Skip to content

Commit 250fbf3

Browse files
committed
Merge pull request #16 from coffbr01/master
Support "GMT:" prefix in addition to "UTC:"
2 parents 129fd5b + f3ced71 commit 250fbf3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ As taken from Steven's post, modified to match the Modifications listed above:
5959
dateFormat(now, "longTime", true);
6060
// 10:46:21 PM UTC
6161

62-
// ...Or add the prefix "UTC:" to your mask.
62+
// ...Or add the prefix "UTC:" or "GMT:" to your mask.
6363
dateFormat(now, "UTC:h:MM:ss TT Z");
6464
// 10:46:21 PM UTC
6565

lib/dateformat.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var dateFormat = function () {
6161
};
6262

6363
// Regexes and supporting functions are cached through closure
64-
return function (date, mask, utc) {
64+
return function (date, mask, utc, gmt) {
6565
var dF = dateFormat;
6666

6767
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
@@ -82,10 +82,14 @@ var dateFormat = function () {
8282

8383
mask = String(dF.masks[mask] || mask || dF.masks["default"]);
8484

85-
// Allow setting the utc argument via the mask
86-
if (mask.slice(0, 4) == "UTC:") {
85+
// Allow setting the utc/gmt argument via the mask
86+
var maskSlice = mask.slice(0, 4);
87+
if (maskSlice == "UTC:" || maskSlice == "GMT:") {
8788
mask = mask.slice(4);
8889
utc = true;
90+
if (maskSlice == "GMT:") {
91+
gmt = true;
92+
}
8993
}
9094

9195
var _ = utc ? "getUTC" : "get",
@@ -125,7 +129,7 @@ var dateFormat = function () {
125129
tt: H < 12 ? "am" : "pm",
126130
T: H < 12 ? "A" : "P",
127131
TT: H < 12 ? "AM" : "PM",
128-
Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
132+
Z: gmt ? "GMT" : utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
129133
o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
130134
S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10],
131135
W: W,

0 commit comments

Comments
 (0)