-
Notifications
You must be signed in to change notification settings - Fork 17
/
date_format-test.js
61 lines (46 loc) · 1.99 KB
/
date_format-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
require('should');
var dateFormat = require('../lib');
function createFixedDate() {
return new Date(2010, 0, 11, 14, 31, 30, 5);
}
describe('date_format', function() {
var date = createFixedDate();
it('should default to now when a date is not provided', function() {
dateFormat.asString(dateFormat.DATETIME_FORMAT).should.not.be.empty();
});
it('should be usable directly without calling asString', function() {
dateFormat(dateFormat.DATETIME_FORMAT, date).should.eql('11 01 2010 14:31:30.005');
});
it('should format a date as string using a pattern', function() {
dateFormat.asString(dateFormat.DATETIME_FORMAT, date).should.eql('11 01 2010 14:31:30.005');
});
it('should default to the ISO8601 format', function() {
dateFormat.asString(date).should.eql('2010-01-11T14:31:30.005');
});
it('should provide a ISO8601 with timezone offset format', function() {
var tzDate = createFixedDate();
tzDate.getTimezoneOffset = function () {
return -660;
};
// when tz offset is in the pattern, the date should be in local time
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
.should.eql('2010-01-11T14:31:30.005+11:00');
tzDate = createFixedDate();
tzDate.getTimezoneOffset = function () {
return 120;
};
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
.should.eql('2010-01-11T14:31:30.005-02:00');
});
it('should provide a just-the-time format', function() {
dateFormat.asString(dateFormat.ABSOLUTETIME_FORMAT, date).should.eql('14:31:30.005');
});
it('should provide a custom format', function() {
var customDate = createFixedDate();
customDate.getTimezoneOffset = function () {
return 120;
};
dateFormat.asString('O.SSS.ss.mm.hh.dd.MM.yy', customDate).should.eql('-02:00.005.30.31.14.11.01.10');
});
});