facaeb1ff581f47549c38a628bb36eac9fe517b1.svn-base
2.48 KB
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
/*
* time-span-test.js: Tests for the TimeSpan module.
*
* (C) Charlie Robbins
* MIT LICENSE
*
*/
var vows = require('vows'),
assert = require('assert'),
timeSpan = require('../lib/time-span');
vows.describe('time-span/date-time').addBatch({
"When using the TimeSpan module": {
"the parseDate() method": {
"when passed a TimeSpan string using ISO8601 with explicit time modifiers": {
"which do not carry over": {
"should return the correct value": function () {
var target = new Date(Date.parse('2010-04-03T10:04:15Z')),
parsed = timeSpan.parseDate('2010-04-03T12:34:15Z-2HOURS30MINUTES');
assert.equal(target.toString(), parsed.toString());
}
},
"which carry under": {
"should return the correct value": function () {
var target = new Date(Date.parse('2010-03-29T12:34:15Z')),
parsed = timeSpan.parseDate('2010-04-01T12:34:15Z-72HOURS');
assert.equal(target.toString(), parsed.toString());
}
},
"which carry under a leap year": {
"should return the correct value": function () {
var target = new Date(Date.parse('2007-03-31T12:00:00Z')),
parsed = timeSpan.parseDate('2010-03-31T12:00:00Z-1096DAYS');
assert.equal(target.toString(), parsed.toString());
}
},
"which carry over": {
"should return the correct value": function () {
var target = new Date(Date.parse('2013-04-03T12:34:15Z')),
parsed = timeSpan.parseDate('2010-04-03T12:34:15Z+2YEARS365DAYS');
assert.equal(target.toString(), parsed.toString());
}
}
},
"when passed a TimeSpan string using NOW with explicit time modifiers": {
"which do not carry over": {
"should return the correct value": function () {
var now = new Date(Date.now()),
parsed = timeSpan.parseDate('NOW-2HOURS');
now.setHours(now.getHours() - 2);
assert.equal(now.getHours(), parsed.getHours());
}
},
"which carry under": {
"should return the correct value": function () {
var now = new Date(Date.now()),
parsed = timeSpan.parseDate('NOW-72HOURS');
now.setHours(now.getHours() - 72);
assert.equal(now.getHours(), parsed.getHours());
}
}
}
}
}
}).export(module);