Skip to content

Commit dc84d4b

Browse files
committed
Fixed Date.format().
1 parent d9e3f3c commit dc84d4b

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- fixed: `Date.extend()`
3636
- fixed: `String.isJSON()` validator
3737
- fixed: `String.parseDate()` now it parses date to UTC correctly
38+
- fixed: `Date.format()` now it formats a date as UTC correctly
3839

3940
======= 2.9.4 (HOTFIX)
4041

test/test-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function prototypeDate() {
99

1010
var dt = new Date(1404723152167);
1111
assert.ok(dt.toString() === 'Mon Jul 07 2014 10:52:32 GMT+0200 (CEST)', 'date problem');
12-
assert.ok(dt.format() === '2014-07-07T10:52:32.167Z', 'date format(0) problem');
12+
assert.ok(dt.format() === '2014-07-07T08:52:32.167Z', 'date format(0) problem');
1313
assert.ok(dt.add('minute', 5).toString() === 'Mon Jul 07 2014 10:57:32 GMT+0200 (CEST)', 'date add');
1414
assert.ok(dt.format('MMM') === 'Jul', 'month name 1');
1515
assert.ok(dt.format('MMMM') === 'July', 'month name 2');

utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,7 @@ Date.compare = function(d1, d2) {
26482648
Date.prototype.format = function(format, resource) {
26492649

26502650
if (!format)
2651-
return this.getFullYear() + '-' + (this.getMonth() + 1).toString().padLeft(2, '0') + '-' + this.getDate().toString().padLeft(2, '0') + 'T' + this.getHours().toString().padLeft(2, '0') + ':' + this.getMinutes().toString().padLeft(2, '0') + ':' + this.getSeconds().toString().padLeft(2, '0') + '.' + this.getMilliseconds().toString().padLeft(3, '0') + 'Z';
2651+
return this.getUTCFullYear() + '-' + (this.getUTCMonth() + 1).toString().padLeft(2, '0') + '-' + this.getUTCDate().toString().padLeft(2, '0') + 'T' + this.getUTCHours().toString().padLeft(2, '0') + ':' + this.getUTCMinutes().toString().padLeft(2, '0') + ':' + this.getUTCSeconds().toString().padLeft(2, '0') + '.' + this.getUTCMilliseconds().toString().padLeft(3, '0') + 'Z';
26522652

26532653
if (datetimeformat[format])
26542654
return datetimeformat[format](this, resource);

0 commit comments

Comments
 (0)