duckduckgo-utils icon indicating copy to clipboard operation
duckduckgo-utils copied to clipboard

Add function for formatting dates with locale awareness

Open GuiltyDolphin opened this issue 9 years ago • 2 comments
trafficstars

duckduckgo/zeroclickinfo-goodies#2810 adds locale support for dates to Perl Goodies.

It would be nice to have consistent locale-aware date formatting across JS and Perl; in Goodies (Perl) we have the Dates GoodieRole for this, and in the JavaScript we have moment.js... kindah.

Currently people choose which date format to use for moment.js output, but we should probably standardize this and provide a formatDate function that allows us to control exactly how this formatting is done, preferably grabbing locale information and doing something along the lines of moment.locale(...) and moment.format("LLLL") to ensure consistent, long-locale-date formatting for all IAs.

Here's some tasters (basic formatting):

Locale: en-us; Perl: Jun 17, 2016, 4:34:42 PM JS: Jun 17, 2016 4:34 PM

Locale: en-gb; Perl: 17 Jun 2016, 16:34:42 JS: 17 Jun 2016 16:34

There's likely other adjustments that can be made.

/cc @abeyang @moollaza @duckduckgo/community-leaders

GuiltyDolphin avatar Jun 17 '16 16:06 GuiltyDolphin

I thought Moment.js did this out-of-the-box based on the browser settings?

mintsoft avatar Jun 18 '16 01:06 mintsoft

@mintsoft Uhh, not for me - it gives ISO8601 by default.

There might be a setting you can turn on? But you'd probably still want to specify whether you want the long, short, really short or other locale format.

It does support changing individual format specifiers (e.g., dddd) to locale format, but I'm not sure if it supports just auto-detecting the default preferred date format (I may be wrong).

GuiltyDolphin avatar Jun 18 '16 13:06 GuiltyDolphin