moment-misc.js
3.3 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
describe('FCMoment::time', function() {
describe('getter', function() {
// the scenario where an ambiguously-timed moment's 00:00 time is checked
// is taken care of in moment-ambig.js
it('should return 00:00 for a moment with 00:00 time', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T00:00:00');
var time = mom.time();
expect(time).toEqualDuration('00:00');
});
it('should return the time of a moment with a time', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T07:30:00');
var time = mom.time();
expect(time).toEqualDuration('07:30');
});
});
describe('setter', function() {
// the scenario where an ambiguously-timed moment is given a time via the setter
// is taken care of in moment-ambig.js
describe('when setting with a Duration', function() {
it('should give a moment with 00:00 a time', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T00:00:00');
var dur = moment.duration('13:25');
mom.time(dur);
expect(mom).toEqualMoment('2014-06-08T13:25:00+00:00');
});
it('should overwrite the time of a moment with a time', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T05:00:00');
var dur = moment.duration('13:25');
mom.time(dur);
expect(mom).toEqualMoment('2014-06-08T13:25:00+00:00');
});
it('should move to next day if greater than 24 hours', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T00:00:00');
var dur = moment.duration('1.01:00:00'); // 1 day, 1 hour
mom.time(dur);
expect(mom).toEqualMoment('2014-06-09T01:00:00+00:00');
});
});
describe('when setting with another Moment', function() {
it('should give a moment with 00:00 a time', function() {
var mom1 = $.fullCalendar.moment.utc('2014-06-09T00:00:00');
var mom2 = $.fullCalendar.moment.utc('2014-07-22T05:30:00'); // a Tues, so .days() -> 2
mom1.time(mom2);
expect(mom1).toEqualMoment('2014-06-09T05:30:00+00:00');
});
it('should overwrite the time of a moment with a time', function() {
var mom1 = $.fullCalendar.moment.utc('2014-06-09T04:15:00');
var mom2 = $.fullCalendar.moment.utc('2014-07-22T05:30:00'); // a Tues, so .days() -> 2
mom1.time(mom2);
expect(mom1).toEqualMoment('2014-06-09T05:30:00+00:00');
});
});
});
});
describe('FCMoment::week', function() {
beforeEach(function() {
affix('#cal');
});
it('computes based on a weekNumberCalculation function', function() {
$('#cal').fullCalendar({
weekNumberCalculation: function(date) {
expect(moment.isMoment(date)).toBe(true);
return 999;
}
});
var calendar = $('#cal').fullCalendar('getCalendar');
var mom = calendar.moment();
expect(mom.week()).toBe(999);
});
it('computes based on a weekNumberCalculation "ISO" value', function() {
$('#cal').fullCalendar({
weekNumberCalculation: 'ISO'
});
var calendar = $('#cal').fullCalendar('getCalendar');
var mom = calendar.moment('2015-02-22'); // is 9 local week, 8 ISO week
expect(mom.week()).toBe(8);
});
it('computes based on a weekNumberCalculation "local" value', function() {
$('#cal').fullCalendar({
weekNumberCalculation: 'local'
});
var calendar = $('#cal').fullCalendar('getCalendar');
var mom = calendar.moment('2015-02-22'); // is 9 local week, 8 ISO week
expect(mom.week()).toBe(9);
});
});