forked from phstc/jquery-dateFormat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.html
executable file
·233 lines (224 loc) · 15.9 KB
/
Test.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="assets/jsunittest.js" type="text/javascript"></script>
<script src="jquery-1.4.min.js" type="text/javascript"></script>
<script src="jquery.dateFormat-1.0.js" type="text/javascript"></script>
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
</head>
<body>
<div id="content">
<div id="header">
<h1>JavaScript unit test file</h1>
</div>
<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
<div id="testlog"></div>
<!-- Put sample/test html here -->
<div id="sample">
</div>
</div>
<script type="text/javascript"><!--
// <![CDATA[
new Test.Unit.Runner({
setup: function() {
},
teardown: function() {
},
testeJavaUtilDateFormat : function() { with(this) {
/* Java java.util.Date output */
assertEqual('18/12/2009', $.format.date('2009-12-18 10:54:50.546', 'dd/MM/yyyy'));
assertEqual('Dec/2009', $.format.date('2009-12-18 10:54:50.546', 'MMM/yyyy'));
assertEqual('12', $.format.date('2009-12-18 10:54:50.546', 'MM'));
assertEqual('05', $.format.date('2009-12-5 10:54:50.546', 'dd'));
assertEqual('2009', $.format.date('2009-12-18 10:54:50.546', 'yyyy'));
assertEqual('12', $.format.date('2009-12-18 10:54:50.546', 'MM'));
assertEqual('10:54:50', $.format.date('2009-12-18 10:54:50.546', 'hh:mm:ss'));
assertEqual('10', $.format.date('2009-12-18 10:54:50.546', 'hh'));
assertEqual('54', $.format.date('2009-12-18 10:54:50.546', 'mm'));
assertEqual('50', $.format.date('2009-12-18 10:54:50.546', 'ss'));
assertEqual('546', $.format.date('2009-12-18 10:54:50.546', 'SSS'));
assertEqual('18/12/2009 01:54:50', $.format.date('2009-12-18 13:54:50.546', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('18/12/2009 14:54:50', $.format.date('2009-12-18 14:54:50.546', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('18/12/2009 10:54:50 AM', $.format.date('2009-12-18 10:54:50.546', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('18/12/2009 01:54:50 PM', $.format.date('2009-12-18 13:54:50.546', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z18/b12/c2009 x10:e54:f50', $.format.date('2009-12-18 10:54:50.546', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('2010', $.format.date(new Date(1274370756526), 'yyyy'));
assertEqual('Friday', $.format.date('2009-12-18 10:54:50.546', 'ddd'));
}},
testFormatDateType2 : function() { with(this) {
/* ??? Wed Jan 13 10:43:41 CET 2010 */
assertEqual('01/01/2010', $.format.date('Wed Jan 1 10:43:41 CET 2010', 'dd/MM/yyyy'));
assertEqual('Jan/2010', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'MMM/yyyy'));
assertEqual('01', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'MM'));
assertEqual('05', $.format.date('Wed Jan 5 10:43:41 CET 2010', 'dd'));
assertEqual('2010', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'yyyy'));
assertEqual('01', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'MM'));
assertEqual('10:43:41', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'hh:mm:ss'));
assertEqual('10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'hh'));
assertEqual('43', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'mm'));
assertEqual('41', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'ss'));
assertEqual('13/01/2010 01:43:41', $.format.date('Wed Jan 13 13:43:41 CET 2010', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('13/01/2010 14:43:41', $.format.date('Wed Jan 13 14:43:41 CET 2010', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('13/01/2010 10:43:41 AM', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('13/01/2010 05:43:41 PM', $.format.date('Wed Jan 13 17:43:41 CET 2010', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z13/b01/c2010 x10:e43:f41', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Wednesday', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'ddd'));
}},
testJAXBFormat : function() { with(this) {
/* Java JAXB java.util.Date output */
assertEqual('19/10/2010', $.format.date('2010-10-19T11:40:33.527+02:00', 'dd/MM/yyyy'));
assertEqual('Oct/2010', $.format.date('2010-10-19T11:40:33.527+02:00', 'MMM/yyyy'));
assertEqual('10', $.format.date('2010-10-19T11:40:33.527+02:00', 'MM'));
assertEqual('05', $.format.date('2010-10-05T11:40:33.527+02:00', 'dd'));
assertEqual('2010', $.format.date('2010-10-19T11:40:33.527+02:00', 'yyyy'));
assertEqual('19', $.format.date('2010-10-19T11:40:33.527+02:00', 'dd'));
assertEqual('11:40:33', $.format.date('2010-10-19T11:40:33.527+02:00', 'hh:mm:ss'));
assertEqual('11', $.format.date('2010-10-19T11:40:33.527+02:00', 'hh'));
assertEqual('40', $.format.date('2010-10-19T11:40:33.527+02:00', 'mm'));
assertEqual('33', $.format.date('2010-10-19T11:40:33.527+02:00', 'ss'));
assertEqual('19/10/2010 01:43:41', $.format.date('2010-10-19T13:43:41.527+02:00', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('19/10/2010 14:43:41', $.format.date('2010-10-19T14:43:41.527+02:000', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('19/10/2010 10:43:41 AM', $.format.date('2010-10-19T10:43:41.527+02:00', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('19/10/2010 05:43:41 PM', $.format.date('2010-10-19T17:43:41.527+02:00', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z19/b10/c2010 x11:e40:f33', $.format.date('2010-10-19T11:40:33.527+02:00', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Tuesday', $.format.date('2010-10-19T11:40:33.527+02:00', 'ddd'));
}},
testeJavaScriptDateFormat: function() { with(this) {
/* JavaScript Date output */
assertEqual('19/10/2010', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'dd/MM/yyyy'));
assertEqual('Oct/2010', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'MMM/yyyy'));
assertEqual('10', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'MM'));
assertEqual('05', $.format.date(new Date('10/5/2010 11:40:33').toString(), 'dd'));
assertEqual('2010', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'yyyy'));
assertEqual('19', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'dd'));
assertEqual('11:40:33', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'hh:mm:ss'));
assertEqual('11', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'hh'));
assertEqual('40', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'mm'));
assertEqual('33', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'ss'));
assertEqual('19/10/2010 01:43:41', $.format.date(new Date('10/19/2010 13:43:41').toString(), 'dd/MM/yyyy hh:mm:ss'));
assertEqual('19/10/2010 14:43:41', $.format.date(new Date('10/19/2010 14:43:41').toString(), 'dd/MM/yyyy HH:mm:ss'));
assertEqual('19/10/2010 10:43:41 AM', $.format.date(new Date('10/19/2010 10:43:41').toString(), 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('19/10/2010 05:43:41 PM', $.format.date(new Date('10/19/2010 17:43:41').toString(), 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z19/b10/c2010 x11:e40:f33', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Tuesday', $.format.date(new Date('10/19/2010 10:43:41').toString(), 'ddd'));
}},
testFormatDateType5: function() { with(this) {
assertEqual('08/04/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy'));
assertEqual('Apr/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'MMM/yyyy'));
assertEqual('04', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'MM'));
assertEqual('08', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd'));
assertEqual('2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'yyyy'));
assertEqual('19', $.format.date('Fri Apr 19 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd'));
assertEqual('01:02:03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'hh:mm:ss'));
assertEqual('01', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'hh'));
assertEqual('02', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'mm'));
assertEqual('03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'ss'));
assertEqual('08/04/2011 01:02:03', $.format.date('Fri Apr 08 2011 13:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('08/04/2011 14:02:03', $.format.date('Fri Apr 08 2011 14:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('08/04/2011 01:02:03 AM', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('08/04/2011 07:02:03 PM', $.format.date('Fri Apr 08 2011 19:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z08/b04/c2011 x01:e02:f03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Friday', $.format.date('Fri Apr 08 2011 13:02:03 GMT+0800 (China Standard Time)', 'ddd'));
}},
testFormatDateType6: function() { with(this) {
assertEqual('08/04/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy'));
assertEqual('Apr/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'MMM/yyyy'));
assertEqual('04', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'MM'));
assertEqual('08', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd'));
assertEqual('2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'yyyy'));
assertEqual('19', $.format.date('Fri Apr 19 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd'));
assertEqual('01:02:03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'hh:mm:ss'));
assertEqual('01', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'hh'));
assertEqual('02', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'mm'));
assertEqual('03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'ss'));
assertEqual('08/04/2011 01:02:03', $.format.date('Fri Apr 08 2011 13:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('08/04/2011 14:02:03', $.format.date('Fri Apr 08 2011 14:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('08/04/2011 01:02:03 AM', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('08/04/2011 07:02:03 PM', $.format.date('Fri Apr 08 2011 19:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z08/b04/c2011 x01:e02:f03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Friday', $.format.date('Fri Apr 08 2011 14:02:03 GMT+0200 (W. Europe Daylight Time)', 'ddd'));
}},
testFormatDateType7: function() { with(this) {
/* Reference: http://pablocantero.com/blog/2010/09/04/jquery-plugin-javascript-for-java-util-date-tostring-format/#comment-259520318 */
assertEqual('19/04/2009', $.format.date('2009-04-19T16:11:05-02:00', 'dd/MM/yyyy'));
assertEqual('Apr/2009', $.format.date('2009-04-19T16:11:05-02:00', 'MMM/yyyy'));
}},
testFormatDateType8: function() { with(this) {
/* Reference: http://pablocantero.com/blog/2010/09/04/jquery-plugin-javascript-for-java-util-date-tostring-format/#comment-178490699 */
assertEqual('05:45PM', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'hh:mma'));
}},
testDayInWeek: function() { with(this) {
assertEqual('Monday', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'ddd'));
}},
testMonthInYear: function() { with(this) {
assertEqual('Mar', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'MMM'));
assertEqual('March', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'MMMM'));
}},
testLongMonth: function() { with(this) {
assertEqual('February', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'MMMM'));
}},
testShortYear: function() { with(this) {
assertEqual(11, $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'yy'));
assertEqual(12, $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'yy'));
assertEqual('13.01.10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy'));
}},
testShortHour: function() { with(this) {
assertEqual('5', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('5', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy h'));
assertEqual('6', $.format.date('Wed Jan 25 06:23:38 PST 2012', 'h'));
assertEqual('06', $.format.date('Wed Jan 25 06:23:38 PST 2012', 'hh'));
assertEqual('5', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('5', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy h'));
}},
testIssue19: function() { with(this) {
assertEqual('Sep 29, 2011', $.format.date("2011-09-29 14:50:49", "MMM dd, yyyy"));
}},
testIssue17: function() { with(this) {
assertEqual('2011-04-25 09:04', $.format.date("2011-04-25T09:04:14.7270000", "yyyy-MM-dd HH:mm"));
}},
testShortDay: function() { with(this) {
assertEqual('January 9, 2012', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'MMMM d, yyyy'));
assertEqual('January 09, 2012', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'MMMM dd, yyyy'));
}},
testJapanese: function() { with(this) {
assertEqual('2012年01月09日', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'yyyy年MM月dd日'));
}},
testIssue24: function() { with(this) {
assertEqual('-', $.format.date('Wed Jan 09 06:23:38 PST 2012', '-'));
assertEqual('9-', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'd-'));
assertEqual('9/', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'd/'));
}},
testPullRequest: function() { with(this) {
// https://github.com/phstc/jquery-dateFormat/pull/22
assertEqual('07/02/2012', $.format.date('2012-02-07CET00:00:00', 'dd/MM/yyyy'));
assertEqual('Feb/2012', $.format.date('2012-02-07CET00:00:00', 'MMM/yyyy'));
assertEqual('02', $.format.date('2012-02-07CET00:00:00', 'MM'));
assertEqual('07', $.format.date('2012-02-07CET00:00:00', 'dd'));
assertEqual('2012', $.format.date('2012-02-07CET00:00:00', 'yyyy'));
}},
testUnixTimeStamp: function() { with(this) {
// https://github.com/phstc/jquery-dateFormat/pull/22
var testDate = new Date("Jan 2, 2000 01:02:03");
assertEqual("01", $.format.date(testDate.getTime(), 'MM'));
assertEqual("2", $.format.date(testDate.getTime(), 'd'));
assertEqual("2000", $.format.date(testDate.getTime(), 'yyyy'));
assertEqual("01", $.format.date(testDate.getTime(), 'HH'));
assertEqual("02", $.format.date(testDate.getTime(), 'mm'));
assertEqual("03", $.format.date(testDate.getTime(), 'ss'));
}},
testeShortMonthNoPrependedZero: function() { with(this) {
var testDate = new Date("Jan 2, 2000 01:02:03");
assertEqual('2', $.format.date('Wed Feb 09 06:23:38 PST 2012', 'M'));
assertEqual("1", $.format.date(testDate.getTime(), 'M'));
assertEqual('5', $.format.date('2012-05-07CET00:00:00', 'M'));
}},
});
// ]]>
</script>
</body>
</html>