Closed Bug 1295643 Opened 8 years ago Closed 8 years ago

Implement duration time formatting for AS ("now", "1m", "2h", "3d", etc)

Categories

(Firefox for Android Graveyard :: Awesomescreen, defect)

defect
Not set
normal

Tracking

(firefox51 affected)

RESOLVED INVALID
Tracking Status
firefox51 --- affected

People

(Reporter: ahunt, Assigned: ahunt)

Details

Attachments

(1 file)

There doesn't seem to be any good way of formatting dates in the format that we need ("now", "1m", "2h", "3d", etc), we probably need to roll our own.

The closest I've been able to find is DateUtils.getRelativeTimeSpanString, but that only provides more verbose Strings than we want ("5 minutes ago", no support for "now", etc):

https://developer.android.com/reference/android/text/format/DateUtils.html#getRelativeTimeSpanString(long,%20long,%20long,%20int)
Assignee: nobody → ahunt
Whiteboard: [MobileAS s1.2]
I bet we lose the conciseness as soon as we start to translate the strings to the different languages; I don't even know how to write something short like "3d" in German. In addition to that I wouldn't be surprised if some languages use some strange formats that will require multiple strings for some time spans. I'll just flag flod and he can give us some insights.

With flod's input we might want to bounce that back to UX. The big advantage of getRelativeTimeSpanString() is that it will work at least with all the languages Android ships with.
Flags: needinfo?(francesco.lodolo)
Comment on attachment 8781624 [details]
Bug 1295643 - Implement DurationFormat.formatDurationSince() for simple duration strings

https://reviewboard.mozilla.org/r/72008/#review69786

::: mobile/android/base/java/org/mozilla/gecko/home/activitystream/DurationFormat.java:24
(Diff revision 2)
> +     * "now" for recent times, strings such as "1m", "3h", "4d", "2w", for intermediate durations,
> +     * or an absolute date (12 Jan 2015) for dates more than 4 weeks ago.
> +     *
> +     * Will also return "now" for dates in the future.
> +     */
> +    public static String formatDurationSince(final Context context, final long date) {

This is the perfect class to write a unit test for. :)

::: mobile/android/base/moz.build:442
(Diff revision 2)
>      'GuestSession.java',
>      'health/HealthRecorder.java',
>      'health/SessionInformation.java',
>      'health/StubbedHealthRecorder.java',
>      'home/activitystream/ActivityStream.java',
> +    'home/activitystream/DurationFormat.java',

This seems to be a pretty generic helper - independent from activity stream. Could it be moved?
It would be helpful to have an idea of the UX we're talking about (can't see references here, or dependencies).

As they are, strings lack any localization comment and that's not going to work for sure. I wouldn't be surprised to see locales using full words instead of an abbreviation, so layout should take that into account
http://www.unicode.org/cldr/charts/29/by_type/date_&_time.fields.html#Relative_Hour_Short

One final note: Gandalf is working on adding a RelativeTimeFormat to Intl API (bug 1270140).
Flags: needinfo?(francesco.lodolo)
(In reply to Francesco Lodolo [:flod] from comment #5)
> It would be helpful to have an idea of the UX we're talking about (can't see
> references here, or dependencies).

It's still in development but you can see some of the iOS and Android screens with time here:
 * https://mozilla.invisionapp.com/share/E2867FF8U#/screens/178815181
 * https://mozilla.invisionapp.com/share/VW7ZBXV8Q#/screens/174427349
(In reply to Sebastian Kaspari (:sebastian) from comment #6)
> (In reply to Francesco Lodolo [:flod] from comment #5)
> > It would be helpful to have an idea of the UX we're talking about (can't see
> > references here, or dependencies).
> 
> It's still in development but you can see some of the iOS and Android
> screens with time here:
>  * https://mozilla.invisionapp.com/share/E2867FF8U#/screens/178815181
>  * https://mozilla.invisionapp.com/share/VW7ZBXV8Q#/screens/174427349

Thanks. They look great but I think they're going to blow up with localized strings :-\
One thing to notice is that RelativeTime is "in 3 minutes", "2 min. ago" etc. UnitFormat is "1 minute", "3 min.", "5m.".

I believe that in this bug you're looking for UnitFormat, which is bug 1291408.

CLDR/ICU provide all you need so if you can access system ICU from Android, you should use that, if not, you may want to wait for bug 1215247 and use Gecko's one.
From CLDR you're looking for Units/Duration/*/narrow. Here's list for English - http://www.unicode.org/cldr/charts/29/summary/en.html#5150

Notice, that even narrow variants may be subject to plural forms.

For that reason, I'd recommend using ICU or import CLDR data (as JSON?) over asking localizers to provide that data.
(In reply to Zibi Braniecki [:gandalf][:zibi] from comment #8)
> I believe that in this bug you're looking for UnitFormat, which is bug
> 1291408.

That's absolutely right, thanks for pointing it out. CLDR seems indeed to have plural forms (e.g. {0}h)
http://www.unicode.org/cldr/charts/29/by_type/units.duration.html#27a91cd139580375
> like "3d" in German. In addition to that I wouldn't be surprised if some
> languages use some strange formats that will require multiple strings for
> some time spans. I'll just flag flod and he can give us some insights.
> 
> With flod's input we might want to bounce that back to UX. The big advantage
> of getRelativeTimeSpanString() is that it will work at least with all the
> languages Android ships with.

I think for now I'll switch to the getRelativeTimeSpanString() - the current UI can handle long strings if needed, and seeing as we don't have a finalised UI I don't think there's much point in blocking on this (I'll leave this bug open for now to allow us to keep investigating this).

System ICU isn't an option, Android only provides access to ICU via its own (Java) APIs, which don't offer any compact duration formatting (maybe that's precisely because of the issues described here?).

If we still end up needing a more compact version we can look into the Internationalisation API, but having to call into Gecko is expensive, which isn't great when we need this for multiple items in the UI.
Whiteboard: [MobileAS s1.2]
Comment on attachment 8781624 [details]
Bug 1295643 - Implement DurationFormat.formatDurationSince() for simple duration strings

Okay, re-flag me when needed :)
Attachment #8781624 - Flags: review?(s.kaspari)
It looks like we'll be using the longer strings according to the new designs ("5 minutes ago", "4 days ago", etc), which Android is able to provide - therefore we don't need to roll our own anymore / don't need to deal with the associated problems.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: