mirror of
https://github.com/samsonjs/strftime.git
synced 2026-04-27 14:57:37 +00:00
added support for extended offset format
This commit is contained in:
parent
9146f45142
commit
4de2693e51
1 changed files with 8 additions and 4 deletions
12
strftime.js
12
strftime.js
|
|
@ -114,8 +114,8 @@
|
||||||
// Most of the specifiers supported by C's strftime, and some from Ruby.
|
// Most of the specifiers supported by C's strftime, and some from Ruby.
|
||||||
// Some other syntax extensions from Ruby are supported: %-, %_, and %0
|
// Some other syntax extensions from Ruby are supported: %-, %_, and %0
|
||||||
// to pad with nothing, space, or zero (respectively).
|
// to pad with nothing, space, or zero (respectively).
|
||||||
return fmt.replace(/%([-_0]?.)/g, function(_, c) {
|
return fmt.replace(/%([-_0:]?.)/g, function(_, c) {
|
||||||
var mod, padding;
|
var mod, padding, ext;
|
||||||
|
|
||||||
if (c.length == 2) {
|
if (c.length == 2) {
|
||||||
mod = c[0];
|
mod = c[0];
|
||||||
|
|
@ -131,6 +131,9 @@
|
||||||
else if (mod == '0') {
|
else if (mod == '0') {
|
||||||
padding = '0';
|
padding = '0';
|
||||||
}
|
}
|
||||||
|
else if (mod == ":") {
|
||||||
|
ext = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// unrecognized, return the format
|
// unrecognized, return the format
|
||||||
return _;
|
return _;
|
||||||
|
|
@ -267,11 +270,12 @@
|
||||||
// '+0000'
|
// '+0000'
|
||||||
case 'z':
|
case 'z':
|
||||||
if (options.utc) {
|
if (options.utc) {
|
||||||
return "+0000";
|
return ext ? "+00:00" : "+0000";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var off = typeof tz == 'number' ? tz : -d.getTimezoneOffset();
|
var off = typeof tz == 'number' ? tz : -d.getTimezoneOffset();
|
||||||
return (off < 0 ? '-' : '+') + pad(Math.floor(Math.abs(off) / 60)) + pad(Math.abs(off) % 60);
|
var sep = ext ? ":" : ""; // separator for extended offset
|
||||||
|
return (off < 0 ? '-' : '+') + pad(Math.floor(Math.abs(off) / 60)) + sep + pad(Math.abs(off) % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
default: return c;
|
default: return c;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue