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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html>
<head>
</head>
<body class="yui3-skin-sam">
<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
<script type="text/javascript">
(function() {
YUI({
base: "/build/",
//filter: "debug",
logInclude:{"TestRunner":true},
useConsole: true
}).use("console", "test", "dump", "datatype-date", function(Y) {
// Set up the page
var LANG = Y.Lang,
ASSERT = Y.Assert,
ARRAYASSERT = Y.ArrayAssert,
btnRun = Y.get("#btnRun"),
myConsole = new Y.Console().render();
btnRun.set("disabled", false);
Y.on("click", function(){
}, btnRun);
var testParse = new Y.Test.Case({
name: "Date Parse Tests",
testUndefined: function() {
var date = Y.DataType.Date.parse();
ASSERT.isNull(date, "Expected null.");
},
testNull: function() {
var date = Y.DataType.Date.parse(null);
ASSERT.isTrue(LANG.isDate(date), "Expected date.");
},
testParse: function() {
var date = Y.DataType.Date.parse("December 17, 1995 03:24:00");
ASSERT.isTrue(LANG.isDate(date), "Expected date.");
date = Y.DataType.Date.parse(1995,11,17);
ASSERT.isTrue(LANG.isDate(date), "Expected date.");
date = Y.DataType.Date.parse(1995,11,17,3,24,0);
ASSERT.isTrue(LANG.isDate(date), "Expected date.");
date = Y.DataType.Date.parse(948548583);
ASSERT.isTrue(LANG.isDate(date), "Expected date.");
}
});
var testFormat = new Y.Test.Case({
name: "Date Format Tests",
testUndefined: function() {
var output = Y.DataType.Date.format();
ASSERT.areSame("", output, "Expected empty string.");
},
testNull: function() {
var output = Y.DataType.Date.format(null);
ASSERT.areSame("", output, "Expected empty string.");
},
testFormats: function() {
var date = new Date(819199440000),
output;
output = Y.DataType.Date.format(date);
ASSERT.areSame("1995-12-17", output, "Expected default format (%F)");
output = Y.DataType.Date.format(date, {format:"%D"});
output = Y.DataType.Date.format(date, {format:"%a %A"});
ASSERT.areSame("Sun Sunday", output, "Expected %a %A format.");
output = Y.DataType.Date.format(date, {format:"%b %B"});
ASSERT.areSame("Dec December", output, "Expected %b %B format.");
output = Y.DataType.Date.format(date, {format:"%r"});
ASSERT.areSame("03:24:00 AM", output, "Expected %r format.");
output = Y.DataType.Date.format(date, {format:"%R"});
ASSERT.areSame("03:24", output, "Expected %r format.");
}
});
var testFormatLocales = new Y.Test.Case({
name: "Date Format Locale Tests",
testUndefined: function() {
a: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
A: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
b: ['Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Jui', 'Aoû', 'Sep', 'Cct', 'Nov', 'Déc'],
B: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
c: '%a %d %b %Y %T %Z',
p: ['', ''],
P: ['', ''],
x: '%d.%m.%Y',
X: '%T'
});
var date = new Date(819199440000),
output;
output = Y.DataType.Date.format(date);
ASSERT.areSame("1995-12-17", output, "Expected default format (%F).");
output = Y.DataType.Date.format(date, {format:"%a %A", locale:"fr"});
ASSERT.areSame("Dim Dimanche", output, "Expected %a %A format.");
output = Y.DataType.Date.format(date, {format:"%b %B", locale:"fr"});
ASSERT.areSame("Déc Décembre", output, "Expected %b %B format.");
output = Y.DataType.Date.format(date, {format:"%x", locale:"fr"});
ASSERT.areSame("17.12.1995", output, "Expected %x format.");
output = Y.DataType.Date.format(date, {format:"%x", locale:"fr-CH"});
ASSERT.areSame("17. 12. 95", output, "Expected %x format for fr-CH.");
output = Y.DataType.Date.format(date, {format:"%r", locale:"en-GB"});
ASSERT.areSame(" 3:24:00 am PST", output, "Expected %r format for en-GB.");
}
});
Y.Test.Runner.add(testParse);
Y.Test.Runner.add(testFormat);
Y.Test.Runner.add(testFormatLocales);
});
})();
</script>
</body>
</html>