Merge branch 'master' into v0.9

Conflicts:
	strftime.js
	test/test.js
This commit is contained in:
Sami Samhuri 2015-03-05 16:49:32 -08:00
commit c029f7a79e
4 changed files with 30 additions and 14 deletions

View file

@ -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 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). 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 Using `%-` will omit any leading zeroes or spaces, `%_` will force spaces
for padding instead of the default, and `%0` will force zeroes for padding. 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 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 Contributors
============ ============
* [Rob Colburn](https://github.com/robcolburn) * [Rob Colburn](https://github.com/robcolburn)
* [Cory Heslip](https://github.com/cheslip)
* [Alexandr Nikitin](https://github.com/alexandrnikitin) * [Alexandr Nikitin](https://github.com/alexandrnikitin)
* [Sami Samhuri](https://github.com/samsonjs) * [Sami Samhuri](https://github.com/samsonjs)
* [Andrew Schaaf](https://github.com/andrewschaaf) * [Andrew Schaaf](https://github.com/andrewschaaf)

View file

@ -1,11 +1,11 @@
{ {
"name": "strftime", "name": "strftime",
"version": "0.8.2", "version": "0.8.3",
"main": "strftime.js", "main": "strftime.js",
"ignore": [ "ignore": [
"Readme.md", "Readme.md",
"Makefile", "Makefile",
"test/*", "test",
"*.json" "*.json"
], ],
"dependencies": {}, "dependencies": {},

View file

@ -131,7 +131,8 @@
var resultString = '', var resultString = '',
padding = null, padding = null,
isInScope = false, isInScope = false,
length = format.length; length = format.length,
extendedTZ = false;
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
@ -153,6 +154,11 @@
padding = '0'; padding = '0';
continue; continue;
} }
// ':'
else if (currentCharCode === 58) {
extendedTZ = true;
continue;
}
switch (currentCharCode) { switch (currentCharCode) {
@ -297,10 +303,10 @@
resultString += padTill2(date.getDate(), padding); resultString += padTill2(date.getDate(), padding);
break; break;
// '01' // ' 1'
// case 'e': // case 'e':
case 101: case 101:
resultString += date.getDate(); resultString += padTill2(date.getDate(), padding == null ? ' ' : padding);
break; break;
// 'Jan' // 'Jan'
@ -406,7 +412,7 @@
// case 'z': // case 'z':
case 122: case 122:
if (_useUtcBasedDate && _customTimezoneOffset === 0) { if (_useUtcBasedDate && _customTimezoneOffset === 0) {
resultString += "+0000"; resultString += extendedTZ ? "+00:00" : "+0000";
} }
else { else {
var off; var off;
@ -416,7 +422,11 @@
else { else {
off = -date.getTimezoneOffset(); 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; break;

View file

@ -112,7 +112,9 @@ assert.format('%Y', '2011');
assert.format('%y', '11'); assert.format('%y', '11');
assert.format('%Z', null, 'GMT'); assert.format('%Z', null, 'GMT');
assert.format('%z', null, '+0000'); assert.format('%z', null, '+0000');
assert.format('%:z', null, '+00:00');
assert.format('%%', '%'); // any other char assert.format('%%', '%'); // any other char
assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0));
ok('GMT'); ok('GMT');
@ -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', -420);
assert.formatTZ('%F %r %z', '2011-06-07 11:51:45 AM -0700', '-0700'); 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 -0730', '-0730');
assert.formatTZ('%F %r %:z', '2011-06-07 11:21:45 AM -07:30', '-0730');
ok('Time zone offset'); ok('Time zone offset');
@ -224,5 +227,6 @@ function testTimezone(regex) {
assert.format('%T', T, '18:51:45'); assert.format('%T', T, '18:51:45');
assert.format('%Z', tz, 'GMT'); assert.format('%Z', tz, 'GMT');
assert.format('%z', sign + '0' + Math.abs(hourDiff) + '00', '+0000'); assert.format('%z', sign + '0' + Math.abs(hourDiff) + '00', '+0000');
assert.format('%:z', sign + '0' + Math.abs(hourDiff) + ':00', '+00:00');
} }
} }