mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
Merge branch 'master' into v0.9
Conflicts: strftime.js test/test.js
This commit is contained in:
commit
c029f7a79e
4 changed files with 30 additions and 14 deletions
|
|
@ -129,16 +129,18 @@ e.g. `%q` becomes `q`. Use `%%` to get a literal `%` sign.
|
|||
For more detail see `man 3 strftime` as the format specifiers should behave
|
||||
identically. If behaviour differs please [file a bug](https://github.com/samsonjs/strftime/issues/new).
|
||||
|
||||
Any specifier can be modified with `-`, `_`, or `0` as well, as in Ruby.
|
||||
Any specifier can be modified with `-`, `_`, `0`, or `:` as well, as in Ruby.
|
||||
Using `%-` will omit any leading zeroes or spaces, `%_` will force spaces
|
||||
for padding instead of the default, and `%0` will force zeroes for padding.
|
||||
There's some redundancy here as `%-d` and `%e` have the same result, but it
|
||||
solves some awkwardness with formats like `%l`.
|
||||
solves some awkwardness with formats like `%l`. Using `%:` for time zone offset,
|
||||
as in `%:z` will insert a colon as a delimiter.
|
||||
|
||||
Contributors
|
||||
============
|
||||
|
||||
* [Rob Colburn](https://github.com/robcolburn)
|
||||
* [Cory Heslip](https://github.com/cheslip)
|
||||
* [Alexandr Nikitin](https://github.com/alexandrnikitin)
|
||||
* [Sami Samhuri](https://github.com/samsonjs)
|
||||
* [Andrew Schaaf](https://github.com/andrewschaaf)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"name": "strftime",
|
||||
"version": "0.8.2",
|
||||
"version": "0.8.3",
|
||||
"main": "strftime.js",
|
||||
"ignore": [
|
||||
"Readme.md",
|
||||
"Makefile",
|
||||
"test/*",
|
||||
"test",
|
||||
"*.json"
|
||||
],
|
||||
"dependencies": {},
|
||||
|
|
|
|||
24
strftime.js
24
strftime.js
|
|
@ -131,7 +131,8 @@
|
|||
var resultString = '',
|
||||
padding = null,
|
||||
isInScope = false,
|
||||
length = format.length;
|
||||
length = format.length,
|
||||
extendedTZ = false;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
|
||||
|
|
@ -153,6 +154,11 @@
|
|||
padding = '0';
|
||||
continue;
|
||||
}
|
||||
// ':'
|
||||
else if (currentCharCode === 58) {
|
||||
extendedTZ = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (currentCharCode) {
|
||||
|
||||
|
|
@ -297,10 +303,10 @@
|
|||
resultString += padTill2(date.getDate(), padding);
|
||||
break;
|
||||
|
||||
// '01'
|
||||
// ' 1'
|
||||
// case 'e':
|
||||
case 101:
|
||||
resultString += date.getDate();
|
||||
resultString += padTill2(date.getDate(), padding == null ? ' ' : padding);
|
||||
break;
|
||||
|
||||
// 'Jan'
|
||||
|
|
@ -378,7 +384,7 @@
|
|||
resultString += day === 0 ? 7 : day;
|
||||
break; // 1 - 7, Monday is first day of the week
|
||||
|
||||
// '1-Jan-1970'
|
||||
// ' 1-Jan-1970'
|
||||
// case 'v':
|
||||
case 118:
|
||||
resultString += _processFormat(locale.formats.v, date, locale, timestamp);
|
||||
|
|
@ -406,17 +412,21 @@
|
|||
// case 'z':
|
||||
case 122:
|
||||
if (_useUtcBasedDate && _customTimezoneOffset === 0) {
|
||||
resultString += "+0000";
|
||||
resultString += extendedTZ ? "+00:00" : "+0000";
|
||||
}
|
||||
else {
|
||||
var off;
|
||||
if(_customTimezoneOffset !== 0) {
|
||||
if (_customTimezoneOffset !== 0) {
|
||||
off = _customTimezoneOffset / (60 * 1000);
|
||||
}
|
||||
else {
|
||||
off = -date.getTimezoneOffset();
|
||||
}
|
||||
resultString += (off < 0 ? '-' : '+') + padTill2(Math.floor(Math.abs(off / 60))) + padTill2(Math.abs(off % 60));
|
||||
var sign = off < 0 ? '-' : '+';
|
||||
var sep = extendedTZ ? ':' : '';
|
||||
var hours = Math.floor(Math.abs(off / 60));
|
||||
var mins = Math.abs(off % 60);
|
||||
resultString += sign + padTill2(hours) + sep + padTill2(mins);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
|||
10
test/test.js
10
test/test.js
|
|
@ -74,7 +74,7 @@ assert.format('%d', '07');
|
|||
assert.format('%-d', '7');
|
||||
assert.format('%_d', ' 7');
|
||||
assert.format('%0d', '07');
|
||||
assert.format('%e', '7');
|
||||
assert.format('%e', ' 7');
|
||||
assert.format('%F', '2011-06-07');
|
||||
assert.format('%H', null, '18');
|
||||
assert.format('%h', 'Jun');
|
||||
|
|
@ -104,7 +104,7 @@ assert.format('%t', '\t');
|
|||
assert.format('%U', '23');
|
||||
assert.format('%U', '24', null, new Date(+Time + 5 * 86400000));
|
||||
assert.format('%u', '2');
|
||||
assert.format('%v', '7-Jun-2011');
|
||||
assert.format('%v', ' 7-Jun-2011');
|
||||
assert.format('%W', '23');
|
||||
assert.format('%W', '23', null, new Date(+Time + 5 * 86400000));
|
||||
assert.format('%w', '2');
|
||||
|
|
@ -112,7 +112,9 @@ assert.format('%Y', '2011');
|
|||
assert.format('%y', '11');
|
||||
assert.format('%Z', null, 'GMT');
|
||||
assert.format('%z', null, '+0000');
|
||||
assert.format('%:z', null, '+00:00');
|
||||
assert.format('%%', '%'); // any other char
|
||||
assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0));
|
||||
ok('GMT');
|
||||
|
||||
|
||||
|
|
@ -159,7 +161,7 @@ assert.format_it('%P', null, 'it$pm');
|
|||
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('%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');
|
||||
|
|
@ -178,6 +180,7 @@ assert.formatTZ('%F %r %z', '2011-06-07 08:51:45 PM +0200', '+0200');
|
|||
assert.formatTZ('%F %r %z', '2011-06-07 11:51:45 AM -0700', -420);
|
||||
assert.formatTZ('%F %r %z', '2011-06-07 11:51:45 AM -0700', '-0700');
|
||||
assert.formatTZ('%F %r %z', '2011-06-07 11:21:45 AM -0730', '-0730');
|
||||
assert.formatTZ('%F %r %:z', '2011-06-07 11:21:45 AM -07:30', '-0730');
|
||||
ok('Time zone offset');
|
||||
|
||||
|
||||
|
|
@ -224,5 +227,6 @@ function testTimezone(regex) {
|
|||
assert.format('%T', T, '18:51:45');
|
||||
assert.format('%Z', tz, 'GMT');
|
||||
assert.format('%z', sign + '0' + Math.abs(hourDiff) + '00', '+0000');
|
||||
assert.format('%:z', sign + '0' + Math.abs(hourDiff) + ':00', '+00:00');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue