Skip to content

lightbox: Use a friendlier format for the date, like "Yesterday at 4:47 PM" #45

Open
@chrisbobbe

Description

@chrisbobbe

…or "A few seconds ago", etc.

Currently it shows something like "Mar 31, 2023 15:09:51".

Implementation (full solution)

It's possible that we'll want to merge a partial solution before implementing this, but anyway I wanted to write down some findings.

Dart intl.DateFormat doesn't support some desired features:

  1. Relative times, like "21 minutes ago"
  2. Combining a date and time into one string with a localized separator, such as " at " in English, " um " in German, or " " in Japanese.

We could work around, with our own code or maybe with a library in Dart (such as timeago or relative_time). But (1) is slightly tricky to implement, and requires giving more plural-syntax strings to our volunteer translators. For (2) we could just give the separator to our translators, but that feels unsatisfying because it shouldn't be necessary.

I propose using an ICU library via ffi, which we already plan to do for other localization features: #1165 (comment)

Otherwise, use DateFormat::createInstanceForSkeleton, passing an appropriate "skeleton" (see this helpful explainer):

  • If the timestamp was yesterday, say "Yesterday at {time}". For time, use skeleton jmm, for "12:15 PM".
  • If the timestamp was before yesterday and in the current year, omit the year; use skeleton MMMdjmm, for "Jan 2 at 5:00 PM"
  • If the timestamp was before the current year, include the year, using skeleton yMMMdjmm, for "Jan 2, 2024 at 5:00 PM".
  • If the timestamp is in the future (maybe the server's clock is wrong?), also use skeleton yMMMdjmm. A relative time like "in 21 minutes" would be awkward here.

The strings must be formatted with the same time zone and calendar (Gregorian, Chinese lunar, etc.) as we use to decide which day or year the timestamp is on. We should be able to choose an appropriate Calendar for the which-day/year calculation and pass that Calendar to DateFormat::createInstanceForSkeleton.

We should periodically force-rebuild the widget that shows the time, to avoid freezing with text like "1 minute ago".

We should offer a tooltip that shows the full date and time, with seconds, plus the timezone; skeleton yMMMdjmmsszzzz.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-i18nTranslation, localization, internationalizationa-lightboxThe lightbox / image-viewer screen

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions