mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +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.
|
||||
// Some other syntax extensions from Ruby are supported: %-, %_, and %0
|
||||
// to pad with nothing, space, or zero (respectively).
|
||||
return fmt.replace(/%([-_0]?.)/g, function(_, c) {
|
||||
var mod, padding;
|
||||
return fmt.replace(/%([-_0:]?.)/g, function(_, c) {
|
||||
var mod, padding, ext;
|
||||
|
||||
if (c.length == 2) {
|
||||
mod = c[0];
|
||||
|
|
@ -131,6 +131,9 @@
|
|||
else if (mod == '0') {
|
||||
padding = '0';
|
||||
}
|
||||
else if (mod == ":") {
|
||||
ext = true;
|
||||
}
|
||||
else {
|
||||
// unrecognized, return the format
|
||||
return _;
|
||||
|
|
@ -267,11 +270,12 @@
|
|||
// '+0000'
|
||||
case 'z':
|
||||
if (options.utc) {
|
||||
return "+0000";
|
||||
return ext ? "+00:00" : "+0000";
|
||||
}
|
||||
else {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue