-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
test.js
80 lines (64 loc) · 2.43 KB
/
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
require('mocha');
var assert = require('assert');
var pad = require('pad-left');
var timestamp = require('./');
var timestampUTC = require('./').utc;
describe('timestamp', function() {
it('should return the default timestamp:', function() {
assert(/^\d{4}-\d{2}-\d{2}$/.test(timestamp()));
});
it('should work with delimiters', function() {
assert(/^\[\d{4}\]/.test(timestamp('[YYYY]')));
assert(/^\[\d{4}\d{2}\]/.test(timestamp('[YYYYMM]')));
assert(/^\[\d{4}:\d{2}\]/.test(timestamp('[YYYY:MM]')));
});
it('should work with no separators', function() {
assert(/^\d{4}\d{2}$/.test(timestamp('YYYYMM')));
assert(/^\d{4}\d{2}\d{2}$/.test(timestamp('YYYYMMDD')));
assert(/^\d{4}\d{2}\d{2}\d{2}$/.test(timestamp('YYYYMMDDss')));
assert(/^\d{4}\d{2}\d{2}$/.test(timestamp('YYYYMMss')));
});
it('should return the year:', function() {
assert(/^\d{4}$/.test(timestamp('YYYY')));
assert(/^\d{4}$/.test(timestampUTC('YYYY')));
});
it('should return the month:', function() {
assert(/^\d{2}$/.test(timestamp('MM')));
assert(/^\d{2}$/.test(timestampUTC('MM')));
});
it('should return the day:', function() {
assert(/^\d{2}$/.test(timestamp('DD')));
assert(/^\d{2}$/.test(timestampUTC('DD')));
});
it('should return hours:', function() {
assert(/^\d{2}$/.test(timestamp('HH')));
assert(/^\d{2}$/.test(timestampUTC('HH')));
});
it('should return minutes:', function() {
assert(/^\d{2}$/.test(timestamp('mm')));
assert(/^\d{2}$/.test(timestampUTC('mm')));
});
it('should return seconds:', function() {
assert(/^\d{2}$/.test(timestamp('ss')));
assert(/^\d{2}$/.test(timestampUTC('ss')));
});
it('should return miliseconds:', function() {
assert(/^\d{3}$/.test(timestamp('ms')));
assert(/^\d{3}$/.test(timestampUTC('ms')));
});
it('should increment zero-based month:', function() {
var expected = String(new Date().getUTCMonth() + 1);
assert.equal(timestamp('MM'), pad(expected, 2, '0'));
});
it('should not increment one-based methods:', function() {
var expected = String(new Date().getUTCFullYear());
assert.equal(timestamp('YYYY'), pad(expected, 4, '0'));
});
it('should return the 2 digit year for a given date', function() {
var date = new Date(2019, 0);
var expectedYear = "19";
assert.equal(timestamp('YY', date), expectedYear);
assert.equal(timestampUTC('YY', date), expectedYear);
});
});