Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81146 views
1
/*!
2
* Copyright (c) 2015, Salesforce.com, Inc.
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of Salesforce.com nor the names of its contributors may
16
* be used to endorse or promote products derived from this software without
17
* specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
'use strict';
33
var vows = require('vows');
34
var assert = require('assert');
35
var tough = require('../lib/cookie');
36
37
function dateVows(table) {
38
var theVows = {};
39
Object.keys(table).forEach(function (date) {
40
var expect = table[date];
41
theVows[date] = function () {
42
var got = tough.parseDate(date) ? 'valid' : 'invalid';
43
assert.equal(got, expect ? 'valid' : 'invalid');
44
};
45
});
46
return {"date parsing": theVows};
47
}
48
49
vows
50
.describe('Date')
51
.addBatch(dateVows({
52
"Wed, 09 Jun 2021 10:18:14 GMT": true,
53
"Wed, 09 Jun 2021 22:18:14 GMT": true,
54
"Tue, 18 Oct 2011 07:42:42.123 GMT": true,
55
"18 Oct 2011 07:42:42 GMT": true,
56
"8 Oct 2011 7:42:42 GMT": true,
57
"8 Oct 2011 7:2:42 GMT": true,
58
"Oct 18 2011 07:42:42 GMT": true,
59
"Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)": true,
60
"09 Jun 2021 10:18:14 GMT": true,
61
"99 Jix 3038 48:86:72 ZMT": false,
62
'01 Jan 1970 00:00:00 GMT': true,
63
'01 Jan 1600 00:00:00 GMT': false, // before 1601
64
'01 Jan 1601 00:00:00 GMT': true,
65
'10 Feb 81 13:00:00 GMT': true, // implicit year
66
'Thu, 17-Apr-2014 02:12:29 GMT': true, // dashes
67
'Thu, 17-Apr-2014 02:12:29 UTC': true // dashes and UTC
68
}))
69
.addBatch({
70
"strict date parse of Thu, 01 Jan 1970 00:00:010 GMT": {
71
topic: function () {
72
return tough.parseDate('Thu, 01 Jan 1970 00:00:010 GMT', true) ? true : false;
73
},
74
"invalid": function (date) {
75
assert.equal(date, false);
76
}
77
}
78
})
79
.export(module);
80
81