Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding p as timezone offset, e.g. +02:00 #56

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Readme.md
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/dateformat.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions 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();
});
});