source: trip-planner-front/node_modules/date-format/test/date_format-test.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict';
2
3require('should');
4
5var dateFormat = require('../lib');
6
7function createFixedDate() {
8 return new Date(2010, 0, 11, 14, 31, 30, 5);
9}
10
11describe('date_format', function() {
12 var date = createFixedDate();
13
14 it('should default to now when a date is not provided', function() {
15 dateFormat.asString(dateFormat.DATETIME_FORMAT).should.not.be.empty();
16 });
17
18 it('should be usable directly without calling asString', function() {
19 dateFormat(dateFormat.DATETIME_FORMAT, date).should.eql('11 01 2010 14:31:30.005');
20 });
21
22 it('should format a date as string using a pattern', function() {
23 dateFormat.asString(dateFormat.DATETIME_FORMAT, date).should.eql('11 01 2010 14:31:30.005');
24 });
25
26 it('should default to the ISO8601 format', function() {
27 dateFormat.asString(date).should.eql('2010-01-11T14:31:30.005');
28 });
29
30 it('should provide a ISO8601 with timezone offset format', function() {
31 var tzDate = createFixedDate();
32 tzDate.getTimezoneOffset = function () {
33 return -660;
34 };
35
36 // when tz offset is in the pattern, the date should be in local time
37 dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
38 .should.eql('2010-01-11T14:31:30.005+1100');
39
40 tzDate = createFixedDate();
41 tzDate.getTimezoneOffset = function () {
42 return 120;
43 };
44
45 dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
46 .should.eql('2010-01-11T14:31:30.005-0200');
47 });
48
49 it('should provide a just-the-time format', function() {
50 dateFormat.asString(dateFormat.ABSOLUTETIME_FORMAT, date).should.eql('14:31:30.005');
51 });
52
53 it('should provide a custom format', function() {
54 var customDate = createFixedDate();
55 customDate.getTimezoneOffset = function () {
56 return 120;
57 };
58
59 dateFormat.asString('O.SSS.ss.mm.hh.dd.MM.yy', customDate).should.eql('-0200.005.30.31.14.11.01.10');
60 });
61});
Note: See TracBrowser for help on using the repository browser.