UNPKG

4.44 kBJavaScriptView Raw
1var vows = require('vows');
2var assert = require('assert');
3
4require('../lib/date-utils.js');
5
6vows.describe('Date Parse').addBatch({
7 'can instantiate milliseconds': {
8 topic: function () { return new Date(123456789); },
9 'returns a valid date object': function (date) {
10 assert.ok(date);
11 },
12 'returns a correct value': function (date) {
13 assert.equal(date.valueOf(), 123456789);
14 }
15 },
16
17 'can instantiate string': {
18 topic: function () { return new Date('Jan 1, 2011 01:01:01 GMT'); },
19 'returns a valid date object': function (date) {
20 assert.ok(date);
21 },
22 'returns a correct value': function (date) {
23 assert.equal(date.valueOf(), 1293843661000);
24 }
25 },
26
27 'can instantiate arguments': {
28 topic: function () { return new Date(2011, 1, 1, 1, 1, 1, 0); },
29 'returns a valid date object': function (date) {
30 assert.ok(date);
31 }
32 },
33
34 'can parse normal date': {
35 topic: function () { return Date.parse('Jan 1, 2011 01:01:01 GMT'); },
36 'returns a correct value': function (milli) {
37 assert.equal(milli, 1293843661000);
38 }
39 },
40 'can parse ISO-8601': {
41 topic: function () { return Date.parse('2011-01-01T01:01:01Z'); },
42 'returns a correct value': function (milli) {
43 assert.equal(milli, 1293843661000);
44 }
45 },
46 'can parse custom format': {
47 topic: function () {
48 return Date.parse('20/6/2011 8:30', 'd/M/y H:m');
49 },
50 'returns a correct value': function (milli) {
51 var against = new Date(2011, 5, 20, 8, 30, 0);
52 assert.equal(milli, against.valueOf());
53 }
54 },
55 'parse custom format with full month name': {
56 topic: function () {
57 return Date.parse('June 20, 2011 08:30:00', 'MMM d, y H:m:s');
58 },
59 'returns a correct value': function (milli) {
60 var against = new Date(2011, 5, 20, 8, 30, 0);
61 assert.equal(milli, against.valueOf());
62 }
63 },
64 'parse custom format with abbr month name': {
65 topic: function () {
66 return Date.parse('Jun 20, 2011 08:30:00', 'MMM d, y H:m:s');
67 },
68 'returns a correct value': function (milli) {
69 var against = new Date(2011, 5, 20, 8, 30, 0);
70 assert.equal(milli, against.valueOf());
71 }
72 },
73 'parse custom format with 12 hr clock': {
74 topic: function () {
75 return Date.parse('June 20, 2011 08:30:00AM', 'MMM d, y h:m:sa');
76 },
77 'returns a correct value': function (milli) {
78 var against = new Date(2011, 5, 20, 8, 30, 0);
79 assert.equal(milli, against.valueOf());
80 }
81 },
82 'parse mysql date format': {
83 topic: function () {
84 return Date.parse('2011-06-20 08:30:00', 'y-M-d H:m:s');
85 },
86 'returns a correct value': function (milli) {
87 var against = new Date(2011, 5, 20, 8, 30, 0);
88 assert.equal(milli, against.valueOf());
89 }
90 },
91 'parse us date format w/o time': {
92 topic: function () {
93 return Date.parse('6/20/2011', 'M/d/y');
94 },
95 'returns a correct value': function (milli) {
96 var against = new Date(2011, 5, 20);
97 assert.equal(milli, against.valueOf());
98 }
99 },
100 'parse us date format with time': {
101 topic: function () {
102 return Date.parse('6/20/2011 00:00:01', 'M/d/y H:m:s');
103 },
104 'returns a correct value': function (milli) {
105 var against = new Date(2011, 5, 20, 0, 0, 1);
106 assert.equal(milli, against.valueOf());
107 }
108 },
109 'parse uk date format w/o time': {
110 topic: function () {
111 return Date.parse('20/6/2011', 'd/M/y');
112 },
113 'returns a correct value': function (milli) {
114 var against = new Date(2011, 5, 20);
115 assert.equal(milli, against.valueOf());
116 }
117 },
118 'parse uk date format with time': {
119 topic: function () {
120
121 return Date.parse('20/6/2011 00:00:01', 'd/M/y H:m:s');
122 },
123 'returns a correct value': function (milli) {
124 var against = new Date(2011, 5, 20, 0, 0, 1);
125 assert.equal(milli, against.valueOf());
126 }
127 }
128}).export(module);