Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support strftime #4565

Closed
DartBot opened this issue Aug 17, 2012 · 5 comments
Closed

Support strftime #4565

DartBot opened this issue Aug 17, 2012 · 5 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report

Comments

@DartBot
Copy link

DartBot commented Aug 17, 2012

This issue was originally filed by chri...@gmail.com


It would be really nice if Date supported strftime output. For example:

(new Date.now()).strftime("%a") // "Thu"

The most complete list that I know of is from: http://cheat.errtheblog.com/s/strftime/

Printing dates in JavaScript is hard. It would be so nice if it were easy in Dart.

@kasperl
Copy link

kasperl commented Aug 17, 2012

Added Area-Library, Triaged labels.

@alan-knight
Copy link
Contributor

I'm going to call this a duplicate of 3953, providing internationalization/localization. So right now the equivalent of what you're asking for would be

  new DateFormat("E").format(new Date.now());

though with the additional cost that you'd need to have done an async

  initializeDateFormatting('en_US', null)

somewhere previously. It has the advantage that the set of skeletons come from ICU and are reasonably well-defined, and that they will adapt to other locales, so if your default locale was something else it would print appropriately for it. But it isn't printf-like, so it doesn't fit into strings quite as easily.


Set owner to @alan-knight.
Added Duplicate label.
Marked as being merged into #3953.

@DartBot
Copy link
Author

DartBot commented Sep 6, 2012

This comment was originally written by chris.eee...@gmail.com


Just to play devil's advocate, the underlying strftime C library is also locale aware. Maybe it's the old C/Perl/Ruby hacker in me, but to get the locale specific abbreviated day of the week, I much prefer:

date.strftime('%a');

To:

new DateFormat("E").format(date);

There is less cluttering up the intent of the code--at least to my eye. Even if strftime is just a wrapper around DateFormat, I would like to see strftime make it into Dart.

@DartBot
Copy link
Author

DartBot commented Oct 11, 2014

This comment was originally written by gouttonio@gmail.com


Then, why keep the strftime, and not go directly for format ?

date.format('whatever');

As long as the "whatever" part is heavily documented...
The thing to ask ourselves is : "Is there any ambiguity that the returned type of format is a string ? If not, do we need to keep the str in the function name ?"

Consistency with existing languages is important to flatten the learning curve. But evolution towards elegance is important too !

Just my 2 cents.

@DartBot DartBot added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report labels Oct 11, 2014
@willhaslett
Copy link

I would love to see this opened back up. It's never too late for Dart to start using the same DateTime string formatting syntax that the rest of the world uses. Dart is going against huge ubiquity here. There are good reasons that some things C never die.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

4 participants