diff --git a/Readme.md b/Readme.md index 7dcdbed..025abb0 100644 --- a/Readme.md +++ b/Readme.md @@ -96,6 +96,7 @@ Mask | Description `MM` | Minutes; leading zero for single-digit minutes. `N` | ISO 8601 numeric representation of the day of the week. `o` | GMT/UTC timezone offset, e.g. -0500 or +0230. +`p` | GMT/UTC timezone offset, e.g. -05:00 or +02:30. `s` | Seconds; no leading zero for single-digit seconds. `ss` | Seconds; leading zero for single-digit seconds. `S` | The date's ordinal suffix (st, nd, rd, or th). Works well with `d`. @@ -124,7 +125,7 @@ Name | Mask | Example `longTime` | `h:MM:ss TT Z` | 5:46:21 PM EST `isoDate` | `yyyy-mm-dd` | 2007-06-09 `isoTime` | `HH:MM:ss` | 17:46:21 -`isoDateTime` | `yyyy-mm-dd'T'HH:MM:ss` | 2007-06-09T17:46:21 +`isoDateTime` | `yyyy-mm-dd'T'HH:MM:sso` | 2007-06-09T17:46:21+0700 `isoUtcDateTime` | `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` | 2007-06-09T22:46:21Z ### Localization diff --git a/lib/dateformat.js b/lib/dateformat.js index 95ed91b..7ae6cc1 100644 --- a/lib/dateformat.js +++ b/lib/dateformat.js @@ -16,7 +16,7 @@ 'use strict'; var dateFormat = (function() { - var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZWN]|"[^"]*"|'[^']*'/g; + var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LlopSZWN]|"[^"]*"|'[^']*'/g; var timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g; var timezoneClip = /[^-+\dA-Z]/g; @@ -90,6 +90,7 @@ TT: H < 12 ? dateFormat.i18n.timeNames[6] : dateFormat.i18n.timeNames[7], Z: gmt ? 'GMT' : utc ? 'UTC' : (String(date).match(timezone) || ['']).pop().replace(timezoneClip, ''), o: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), + p: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60),2) + ':' + pad(Math.floor(Math.abs(o) % 60), 2), S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10], W: W, N: N diff --git a/test/test_tzdatetime.js b/test/test_tzdatetime.js new file mode 100644 index 0000000..d0c290c --- /dev/null +++ b/test/test_tzdatetime.js @@ -0,0 +1,12 @@ +var assert = require('assert'); + +var dateFormat = require('./../lib/dateformat'); + +describe('isoUtcDateTime', function() { + it('should correctly format the timezone part', function(done) { + var actual = dateFormat('2014-06-02T13:23:21-08:00', 'yyyy-mm-dd\'T\'HH:MM:ssp'); + var actual2 = dateFormat('2014-06-02T13:23:21-08:00', 'yyyy-mm-dd\'T\'HH:MM:sso'); + assert.strictEqual(actual, actual2.replace(/(\d\d)$/, ':$1')); + done(); + }); +});