missing format specifiers
ray007 opened this issue · 4 comments
%b - same as %h
%g - like %G, but without the century
%G - 4-digit year corresponding to the ISO week number (see %V).
%V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week
%x - from locale or '%D' (preferred date representation without the time)
%X - from locale or '%r' (preferred time representation without the date)
info (mostly) taken from http://www.w3schools.com/php/func_date_strftime.asp
good summary also at http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html
I needed %x and %X, listed the rest for completeness.
%b is present. I just pushed some changes I had that document everything in the readme.
The others are all missing and it's not really obvious how to implement the locale formats. Is there a way to find the current locale in a browser? This could be added for node more easily. I will have to research this in order to add %x and %X. Perhaps I can pilfer something from http://phpjs.org/functions/strftime.
On 2013-01-23, at 8:16 AM, ray007 notifications@github.com wrote:
%b - same as %h
%g - like %G, but without the century
%G - 4-digit year corresponding to the ISO week number (see %V).
%V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week
%x - from locale or '%D' (preferred date representation without the time)
%X - from locale or '%r' (preferred time representation without the date)info (mostly) taken from http://www.w3schools.com/php/func_date_strftime.asp
I needed %x and %X, listed the rest for completeness.
—
Reply to this email directly or view it on GitHub.
It looks like there is no way to determine the locale with JS inside a browser. Realistically your best bet for now is to provide your own locales and use %D and %r, which will respect any locale you pass in for localization. Bundling a bunch of locales is possible, but it would be up to you to determine your user's locale and then set it accordingly.
%x and %X may be possible in node but I think implementing those for a browser are currently out of the scope of this project.
You're probably right on getting a locale, but otherwise the x-codes are easy:
case 'x': return _strftime(locale.formats.x || '%D', d, locale);
case 'X': return _strftime(locale.formats.X || '%r', d, locale);
Even though we don't have locale-data, checking navigator.language should help to choose the right one if we do have data ...
Checking to results of a Date's toLocale*() function should also enable us to go generate some locale formats.
From Date's toString() we could get day-shortnames, no idea on how to get full day names or month names without supplying them.
I'm going to close this issue. I feel that this is out of scope.