mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
add support for %c, %x, and %X (closes #43)
based on @alexandrnikitin's commit here: f25c89bb0f
This commit is contained in:
parent
e16f49f4c0
commit
6bc6888fff
3 changed files with 51 additions and 12 deletions
24
Readme.md
24
Readme.md
|
|
@ -44,9 +44,12 @@ If you want to localize it:
|
|||
D: '%m/%d/%y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
X: '%T',
|
||||
c: '%a %b %d %X %Y',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y'
|
||||
v: '%e-%b-%Y',
|
||||
x: '%D'
|
||||
}
|
||||
}
|
||||
var strftimeIT = strftime.localize(it_IT)
|
||||
|
|
@ -85,10 +88,11 @@ e.g. `%q` becomes `q`. Use `%%` to get a literal `%` sign.
|
|||
- B: full month name
|
||||
- b: abbreviated month name
|
||||
- C: AD century (year / 100), padded to 2 digits
|
||||
- D: equivalent to `%m/%d/%y`
|
||||
- c: equivalent to `%a %b %d %X %Y` in en-US (based on locale)
|
||||
- D: equivalent to `%m/%d/%y` in en-US (based on locale)
|
||||
- d: day of the month, padded to 2 digits (01-31)
|
||||
- e: day of the month, padded with a leading space for single digit values (1-31)
|
||||
- F: equivalent to `%Y-%m-%d`
|
||||
- F: equivalent to `%Y-%m-%d` in en-US (based on locale)
|
||||
- H: the hour (24-hour clock), padded to 2 digits (00-23)
|
||||
- h: the same as %b (abbreviated month name)
|
||||
- I: the hour (12-hour clock), padded to 2 digits (01-12)
|
||||
|
|
@ -100,19 +104,21 @@ e.g. `%q` becomes `q`. Use `%%` to get a literal `%` sign.
|
|||
- m: the month, padded to 2 digits (01-12)
|
||||
- n: newline character
|
||||
- o: day of the month as an ordinal (without padding), e.g. 1st, 2nd, 3rd, 4th, ...
|
||||
- P: "am" or "pm" in lowercase [Ruby extension]
|
||||
- p: "AM" or "PM"
|
||||
- R: equivalent to `%H:%M`
|
||||
- r: equivalent to `%I:%M:%S %p`
|
||||
- P: "am" or "pm" in lowercase (Ruby extension, based on locale)
|
||||
- p: "AM" or "PM" (based on locale)
|
||||
- R: equivalent to `%H:%M` in en-US (based on locale)
|
||||
- r: equivalent to `%I:%M:%S %p` in en-US (based on locale)
|
||||
- S: the second, padded to 2 digits (00-60)
|
||||
- s: the number of seconds since the Epoch, UTC
|
||||
- T: equivalent to `%H:%M:%S`
|
||||
- T: equivalent to `%H:%M:%S` in en-US (based on locale)
|
||||
- t: tab character
|
||||
- U: week number of the year, Sunday as the first day of the week, padded to 2 digits (00-53)
|
||||
- u: the weekday, Monday as the first day of the week (1-7)
|
||||
- v: equivalent to `%e-%b-%Y`
|
||||
- v: equivalent to `%e-%b-%Y` in en-US (based on locale)
|
||||
- W: week number of the year, Monday as the first day of the week, padded to 2 digits (00-53)
|
||||
- w: the weekday, Sunday as the first day of the week (0-6)
|
||||
- X: equivalent to `%D` in en-US (based on locale)
|
||||
- x: equivalent to `%T` in en-US (based on locale)
|
||||
- Y: the year with the century
|
||||
- y: the year without the century (00-99)
|
||||
- Z: the time zone name, replaced with an empty string if it is not found
|
||||
|
|
|
|||
23
strftime.js
23
strftime.js
|
|
@ -27,8 +27,11 @@
|
|||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
T: '%H:%M:%S',
|
||||
X: '%T',
|
||||
c: '%a %b %d %X %Y',
|
||||
r: '%I:%M:%S %p',
|
||||
v: '%e-%b-%Y'
|
||||
v: '%e-%b-%Y',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -245,6 +248,12 @@
|
|||
resultString += padTill2(weekNumber(date, 'monday'), padding);
|
||||
break;
|
||||
|
||||
// '16:00:00'
|
||||
// case 'X':
|
||||
case 88:
|
||||
resultString += _processFormat(locale.formats.X, date, locale, timestamp);
|
||||
break;
|
||||
|
||||
// '1970'
|
||||
// case 'Y':
|
||||
case 89:
|
||||
|
|
@ -276,6 +285,12 @@
|
|||
resultString += locale.shortMonths[date.getMonth()];
|
||||
break;
|
||||
|
||||
// ''
|
||||
// case 'c':
|
||||
case 99:
|
||||
resultString += _processFormat(locale.formats.c, date, locale, timestamp);
|
||||
break;
|
||||
|
||||
// '01'
|
||||
// case 'd':
|
||||
case 100:
|
||||
|
|
@ -375,6 +390,12 @@
|
|||
resultString += date.getDay();
|
||||
break; // 0 - 6, Sunday is first day of the week
|
||||
|
||||
// '12/31/69'
|
||||
// case 'x':
|
||||
case 120:
|
||||
resultString += _processFormat(locale.formats.x, date, locale, timestamp);
|
||||
break;
|
||||
|
||||
// '70'
|
||||
// case 'y':
|
||||
case 121:
|
||||
|
|
|
|||
16
test/test.js
16
test/test.js
|
|
@ -46,13 +46,19 @@ ok('Exports');
|
|||
if (process.env.TZ == 'America/Vancouver') {
|
||||
testTimezone('P[DS]T');
|
||||
assert.format('%C', '01', '01', new Date(100, 0, 1));
|
||||
assert.format('%X', '11:51:45', '18:51:45');
|
||||
assert.format('%c', 'Tue Jun 07 11:51:45 2011', 'Tue Jun 07 18:51:45 2011');
|
||||
assert.format('%j', '097', '098', new Date(1365390736236));
|
||||
assert.format('%x', '06/07/11');
|
||||
ok('Time zones (' + process.env.TZ + ')');
|
||||
}
|
||||
else if (process.env.TZ == 'CET') {
|
||||
testTimezone('CES?T');
|
||||
assert.format('%C', '01', '00', new Date(100, 0, 1));
|
||||
assert.format('%X', '20:51:45', '18:51:45');
|
||||
assert.format('%c', 'Tue Jun 07 20:51:45 2011', 'Tue Jun 07 18:51:45 2011');
|
||||
assert.format('%j', '098', '098', new Date(1365390736236));
|
||||
assert.format('%x', '06/07/11');
|
||||
ok('Time zones (' + process.env.TZ + ')');
|
||||
}
|
||||
else {
|
||||
|
|
@ -127,9 +133,12 @@ var it_IT = {
|
|||
D: 'it$%m/%d/%y',
|
||||
F: 'it$%Y-%m-%d',
|
||||
R: 'it$%H:%M',
|
||||
r: 'it$%I:%M:%S %p',
|
||||
T: 'it$%H:%M:%S',
|
||||
v: 'it$%e-%b-%Y'
|
||||
X: '%T',
|
||||
c: '%a %b %d %X %Y',
|
||||
r: 'it$%I:%M:%S %p',
|
||||
v: 'it$%e-%b-%Y',
|
||||
x: '%D'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -144,6 +153,7 @@ assert.format_it('%A', 'martedi');
|
|||
assert.format_it('%a', 'mar');
|
||||
assert.format_it('%B', 'giugno');
|
||||
assert.format_it('%b', 'giu');
|
||||
assert.format_it('%c', null, 'mar giu 07 it$18:51:45 2011');
|
||||
assert.format_it('%D', 'it$06/07/11');
|
||||
assert.format_it('%F', 'it$2011-06-07');
|
||||
assert.format_it('%p', null, 'it$PM');
|
||||
|
|
@ -152,6 +162,8 @@ assert.format_it('%R', null, 'it$18:51');
|
|||
assert.format_it('%r', null, 'it$06:51:45 it$PM');
|
||||
assert.format_it('%T', null, 'it$18:51:45');
|
||||
assert.format_it('%v', 'it$7-giu-2011');
|
||||
assert.format_it('%x', null, 'it$06/07/11');
|
||||
assert.format_it('%X', null, 'it$18:51:45');
|
||||
ok('Localization');
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue