formatRange.js
5.62 KB
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
describe('formatRange', function() {
it('doesn\'t do any splitting when dates have different years', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2015-01-01', 'MMMM Do YYYY');
expect(s).toEqual('January 1st 2014 - January 1st 2015');
});
it('splits correctly on day when dates have same month', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'MMMM Do YYYY');
expect(s).toEqual('January 1st - 5th 2014');
});
it('splits correctly on day when dates have same month and smaller unit in front', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'dddd MMMM Do YYYY');
expect(s).toEqual('Wednesday January 1st - Sunday January 5th 2014');
});
it('splits correctly on the time when dates have the same day', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T08:00:00', 'MMMM Do YYYY h:mma');
expect(s).toEqual('January 1st 2014 6:00am - 8:00am');
});
it('splits correctly on the time when dates have the same day and hour but different am/pm', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T18:00:00', 'MMMM Do YYYY h:mma');
expect(s).toEqual('January 1st 2014 6:00am - 6:00pm');
});
it('splits correctly on the time when the dates have the same hour', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:30:00', 'MMMM Do YYYY h:mma');
expect(s).toEqual('January 1st 2014 6:00am - 6:30am');
});
it('outputs the single date when the dates have the same day and time', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:00:00', 'MMMM Do YYYY h:mma');
expect(s).toEqual('January 1st 2014 6:00am');
});
it('outputs the single date when the dates have the same day and the format string is vague', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-01', 'MMMM Do YYYY');
expect(s).toEqual('January 1st 2014');
});
it('uses a custom separator', function() {
var s = $.fullCalendar.formatRange(
'2014-01-01T06:00:00',
'2014-01-01T06:30:00',
'MMMM Do YYYY h:mma',
'<...>'
);
expect(s).toEqual('January 1st 2014 6:00am<...>6:30am');
});
describe('when called with isRTL', function() {
it('doesn\'t do any splitting when dates have different years', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2015-01-01', 'MMMM Do YYYY', null, true);
expect(s).toEqual('January 1st 2015 - January 1st 2014');
});
it('splits correctly on day when dates have same month', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'MMMM Do YYYY', null, true);
expect(s).toEqual('January 5th - 1st 2014');
});
it('splits correctly on day when dates have same month and smaller unit in front', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'dddd MMMM Do YYYY', null, true);
expect(s).toEqual('Sunday January 5th - Wednesday January 1st 2014');
});
it('splits correctly on the time when dates have the same day', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T08:00:00', 'MMMM Do YYYY h:mma', null, true);
expect(s).toEqual('January 1st 2014 8:00am - 6:00am');
});
it('splits correctly on the time when dates have the same day and hour but different am/pm', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T18:00:00', 'MMMM Do YYYY h:mma', null, true);
expect(s).toEqual('January 1st 2014 6:00pm - 6:00am');
});
it('splits correctly on the time when the dates have the same hour', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:30:00', 'MMMM Do YYYY h:mma', null, true);
expect(s).toEqual('January 1st 2014 6:30am - 6:00am');
});
it('outputs the single date when the dates have the same day and time', function() {
var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:00:00', 'MMMM Do YYYY h:mma', null, true);
expect(s).toEqual('January 1st 2014 6:00am');
});
it('outputs the single date when the dates have the same day and the format string is vague', function() {
var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-01', 'MMMM Do YYYY', null, true);
expect(s).toEqual('January 1st 2014');
});
it('uses a custom separator', function() {
var s = $.fullCalendar.formatRange(
'2014-01-01T06:00:00',
'2014-01-01T06:30:00',
'MMMM Do YYYY h:mma',
'<...>',
true
);
expect(s).toEqual('January 1st 2014 6:30am<...>6:00am');
});
});
describe('when calendar has isRTL', function() {
it('splits correctly on day when dates have same month', function() {
affix('#cal');
$('#cal').fullCalendar({
defaultView: 'basicWeek',
defaultDate: '2014-05-20',
isRTL: true,
titleFormat: 'MMMM Do YYYY',
titleRangeSeparator: ' - '
});
expect($('.fc-toolbar h2')).toHaveText('May 24th - 18th 2014');
});
});
describe('when calendar has a customized lang', function() {
it('uses language and splits correctly on day when dates have same month', function() {
affix('#cal');
$('#cal').fullCalendar({
defaultView: 'basicWeek',
defaultDate: '2014-05-20',
lang: 'fr',
titleFormat: 'dddd MMMM D YYYY',
titleRangeSeparator: ' - '
});
expect($('.fc-toolbar h2')).toHaveText('lundi mai 19 - dimanche mai 25 2014');
});
});
it('splits correctly on day when dates have same month, when given real moments', function() {
var s = $.fullCalendar.formatRange(
moment.utc('2014-01-01'),
moment.utc('2015-01-01'),
'MMMM Do YYYY'
);
expect(s).toEqual('January 1st 2014 - January 1st 2015');
});
});