samsonjs / strftime

strftime for JavaScript

Home Page:http://samhuri.net/projects/strftime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

missing formats: %c, %x, %X

ray007 opened this issue · comments

I've added 3 lines for this locally:

case 'c': return _strftime(locale.formats.c || '%a %d %b %Y %r %Z', d, locale);
case 'x': return _strftime(locale.formats.x || '%d.%m.%Y', d, locale); // de (DIN-5008) %d.%m.%Y en-US: %D
case 'X': return _strftime(locale.formats.X || '%T', d, locale); // de (ISO?) %T, en-us: %r

As I see here:

  • c specifier should result in Tue Jun 7 22:51:45 2011 While in your case it's Tue 07 Jun 2011 10:51:45 PM Russian Standard Time
  • x results in 06/07/11 but 07.06.11 in your case.

Where can I read more about the specifiers? Did you mention standards?

The reason they are not supported is because we don't have locales in the browser, which is a big caveat. What if there was a way to use these but only after setting the desired formats explicitly? Opt-in. That way people won't just use them and be sad when they aren't actually localized.

@alexandrnikitin These are standard in C99. From that perspective it's fine. The problem is that we don't know the user's locale in the browser, so providing these is somewhat misleading because we can't fulfill the promise of localization. Previously discussed in #17.

I'm not sure I get it.
We support several specifiers i.e. %a, %A, %b, %B etc, which are locale specific. We have default locale for them which is en-US. Why can't we support %x, %X in the same way? If you want localized variant then please specify the locale. If you can't determine the locale then it's not our problem. BTW it will work in Node.js.

You're right. I'm going to add this change based on your commit and get it into v0.9.