mirror of
https://github.com/samsonjs/strftime.git
synced 2026-04-24 14:27:38 +00:00
fix strftimeUTC("%s") (closes #7)
This commit is contained in:
parent
c5362e748c
commit
314603eefe
2 changed files with 5 additions and 2 deletions
|
|
@ -86,8 +86,10 @@
|
||||||
d = d || new Date();
|
d = d || new Date();
|
||||||
locale = locale || DefaultLocale;
|
locale = locale || DefaultLocale;
|
||||||
locale.formats = locale.formats || {}
|
locale.formats = locale.formats || {}
|
||||||
|
var msDelta = 0;
|
||||||
if (_useUTC) {
|
if (_useUTC) {
|
||||||
d = new Date(d.getTime() + ((d.getTimezoneOffset() || 0) * 60000));
|
msDelta = (d.getTimezoneOffset() || 0) * 60000;
|
||||||
|
d = new Date(d.getTime() + msDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Most of the specifiers supported by C's strftime
|
// Most of the specifiers supported by C's strftime
|
||||||
|
|
@ -113,7 +115,7 @@
|
||||||
case 'R': return strftime(locale.formats.R || '%H:%M', d, locale);
|
case 'R': return strftime(locale.formats.R || '%H:%M', d, locale);
|
||||||
case 'r': return strftime(locale.formats.r || '%I:%M:%S %p', d, locale);
|
case 'r': return strftime(locale.formats.r || '%I:%M:%S %p', d, locale);
|
||||||
case 'S': return pad(d.getSeconds());
|
case 'S': return pad(d.getSeconds());
|
||||||
case 's': return Math.floor(d.getTime() / 1000);
|
case 's': return Math.floor((d.getTime() - msDelta) / 1000);
|
||||||
case 'L': return pad3(Math.floor(d.getTime() % 1000));
|
case 'L': return pad3(Math.floor(d.getTime() % 1000));
|
||||||
case 'T': return strftime(locale.formats.T || '%H:%M:%S', d, locale);
|
case 'T': return strftime(locale.formats.T || '%H:%M:%S', d, locale);
|
||||||
case 't': return '\t';
|
case 't': return '\t';
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,4 @@ for [format, expectedNonUTC, expectedUTC] in TESTS
|
||||||
got = lib[name] format, t
|
got = lib[name] format, t
|
||||||
assert.equal expected, got, "Error for #{name}(#{JSON.stringify(format)}, t): expected #{JSON.stringify(expected)}, got #{JSON.stringify(got)}"
|
assert.equal expected, got, "Error for #{name}(#{JSON.stringify(format)}, t): expected #{JSON.stringify(expected)}, got #{JSON.stringify(got)}"
|
||||||
|
|
||||||
|
console.log "OK"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue