Skip to content

Commit dd4b3f4

Browse files
committed
Added compact date parse and format tests
1 parent 6e1990a commit dd4b3f4

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

test.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ function testFormat(name, dateObj, format, expected) {
1717
});
1818
}
1919

20-
function suite(name, suiteBody) {
21-
suiteBody();
22-
}
23-
2420
testParse('basic date parse', '2012/05/03', 'YYYY/MM/DD', new Date(2012, 4, 3));
21+
testParse('compact basic date parse', '20120503', 'YYYYMMDD', new Date(2012, 4, 3));
2522
testParse('basic date parse with time', '2012/05/03 05:01:40', 'YYYY/MM/DD HH:mm:ss', new Date(2012, 4, 3, 5, 1, 40));
2623
testParse('date with different slashes', '2012-05-03 05:01:40', 'YYYY-MM-DD HH:mm:ss', new Date(2012, 4, 3, 5, 1, 40));
2724
testParse('date with different order', '11-7-97', 'D-M-YY', new Date(1997, 6, 11));
@@ -168,6 +165,7 @@ testFormat('D-M-YYYY', new Date(2043, 8, 18, 2, 1, 9, 5), 'D-M-YYYY', '18-9-2043
168165
testFormat('current date', new Date(), 'YYYY', '' + (new Date()).getFullYear());
169166
testFormat('mask', new Date(1999, 0, 2), 'mediumDate', 'Jan 2, 1999');
170167
testFormat('number date', 1325376000000, 'YYY-MM-DD HH:mm:ss', fecha.format(new Date(Date.UTC(2012,0,1)), 'YYY-MM-DD HH:mm:ss'));
168+
testFormat('compact date format', new Date(2012, 4, 3), 'YYYYMMDD', '20120503');
171169
test('i18n am format', function() {
172170
assert.equal(fecha.format(new Date(2018,4,2,10), 'YYYY-MM-DD HHA', {
173171
amPm: ['sd', 'gd'],
@@ -179,18 +177,15 @@ test('no format', function() {
179177
});
180178

181179
// Literals
182-
suite('literals', function() {
183-
var date = new Date(2009, 1, 14, 15, 25, 50, 125);
184-
185-
testFormat('literal in format', date, '[on] MM-DD-YYYY [at] HH:mm',
186-
'on 02-14-2009 at 15:25');
187-
testFormat('one literal', date, '[day]', 'day');
188-
testFormat('two literals', date, '[day] YY [YY]', 'day 09 YY');
189-
testFormat('incomplete literal', date, '[YY', '[09');
190-
testFormat('literal inside literal', date, '[[YY]]', '[YY]');
191-
testFormat('bracket inside literal', date, '[[]', '[');
192-
testFormat('new lines', date, 'YYYY[\n]DD[\n]', '2009\n14\n');
193-
});
180+
var date = new Date(2009, 1, 14, 15, 25, 50, 125);
181+
182+
testFormat('literal in format', date, '[on] MM-DD-YYYY [at] HH:mm', 'on 02-14-2009 at 15:25');
183+
testFormat('one literal', date, '[day]', 'day');
184+
testFormat('two literals', date, '[day] YY [YY]', 'day 09 YY');
185+
testFormat('incomplete literal', date, '[YY', '[09');
186+
testFormat('literal inside literal', date, '[[YY]]', '[YY]');
187+
testFormat('bracket inside literal', date, '[[]', '[');
188+
testFormat('new lines', date, 'YYYY[\n]DD[\n]', '2009\n14\n');
194189

195190
test('Invalid date', function () {
196191
assert.throws(function () {

0 commit comments

Comments
 (0)