1
var moment = require("../../moment");
4
/**************************************************
6
*************************************************/
9
"parse" : function(test) {
12
var tests = 'tammikuu tam_helmikuu hel_maaliskuu maa_huhtikuu huh_toukokuu tou_kesäkuu kes_heinäkuu hei_elokuu elo_syyskuu syys_lokakuu lok_marraskuu mar_joulukuu jou'.split("_");
14
function equalTest(input, mmm, i) {
15
test.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
17
for (i = 0; i < 12; i++) {
18
tests[i] = tests[i].split(' ');
19
equalTest(tests[i][0], 'MMM', i);
20
equalTest(tests[i][1], 'MMM', i);
21
equalTest(tests[i][0], 'MMMM', i);
22
equalTest(tests[i][1], 'MMMM', i);
23
equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
24
equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
25
equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
26
equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
31
"format" : function(test) {
35
['dddd, MMMM Do YYYY, h:mm:ss a', 'sunnuntai, helmikuu 14. 2010, 3:25:50 pm'],
36
['ddd, hA', 'su, 3PM'],
37
['M Mo MM MMMM MMM', '2 2. 02 helmikuu hel'],
38
['YYYY YY', '2010 10'],
39
['D Do DD', '14 14. 14'],
40
['d do dddd ddd dd', '0 0. sunnuntai su su'],
41
['DDD DDDo DDDD', '45 45. 045'],
42
['w wo ww', '8 8. 08'],
48
['vuo\\den DDDo päivä', 'vuoden 45. päivä'],
50
['LL', '14. helmikuuta 2010'],
51
['LLL', '14. helmikuuta 2010, klo 15.25'],
52
['LLLL', 'sunnuntai, 14. helmikuuta 2010, klo 15.25']
54
b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
56
for (i = 0; i < a.length; i++) {
57
test.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
62
"format ordinal" : function(test) {
65
test.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1st');
66
test.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2nd');
67
test.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3rd');
68
test.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4th');
69
test.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5th');
70
test.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6th');
71
test.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7th');
72
test.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8th');
73
test.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9th');
74
test.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10th');
76
test.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11th');
77
test.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12th');
78
test.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13th');
79
test.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14th');
80
test.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15th');
81
test.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16th');
82
test.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17th');
83
test.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18th');
84
test.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19th');
85
test.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20th');
87
test.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21st');
88
test.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22nd');
89
test.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23rd');
90
test.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24th');
91
test.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25th');
92
test.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26th');
93
test.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27th');
94
test.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28th');
95
test.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29th');
96
test.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30th');
98
test.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31st');
102
"format month" : function(test) {
105
var expected = 'tammikuu tam_helmikuu hel_maaliskuu maa_huhtikuu huh_toukokuu tou_kesäkuu kes_heinäkuu hei_elokuu elo_syyskuu syy_lokakuu lok_marraskuu mar_joulukuu jou'.split("_");
107
for (i = 0; i < expected.length; i++) {
108
test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
113
"format week" : function(test) {
116
var expected = 'sunnuntai su su_maanantai ma ma_tiistai ti ti_keskiviikko ke ke_torstai to to_perjantai pe pe_lauantai la la'.split("_");
118
for (i = 0; i < expected.length; i++) {
119
test.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
124
"from" : function(test) {
127
var start = moment([2007, 1, 28]);
128
test.equal(start.from(moment([2007, 1, 28]).add({s:44}), true), "muutama sekunti", "44 seconds = few seconds");
129
test.equal(start.from(moment([2007, 1, 28]).add({s:45}), true), "minuutti", "45 seconds = a minute");
130
test.equal(start.from(moment([2007, 1, 28]).add({s:89}), true), "minuutti", "89 seconds = a minute");
131
test.equal(start.from(moment([2007, 1, 28]).add({s:90}), true), "kaksi minuuttia", "90 seconds = 2 minutes");
132
test.equal(start.from(moment([2007, 1, 28]).add({m:44}), true), "44 minuuttia", "44 minutes = 44 minutes");
133
test.equal(start.from(moment([2007, 1, 28]).add({m:45}), true), "tunti", "45 minutes = an hour");
134
test.equal(start.from(moment([2007, 1, 28]).add({m:89}), true), "tunti", "89 minutes = an hour");
135
test.equal(start.from(moment([2007, 1, 28]).add({m:90}), true), "kaksi tuntia", "90 minutes = 2 hours");
136
test.equal(start.from(moment([2007, 1, 28]).add({h:5}), true), "viisi tuntia", "5 hours = 5 hours");
137
test.equal(start.from(moment([2007, 1, 28]).add({h:21}), true), "21 tuntia", "21 hours = 21 hours");
138
test.equal(start.from(moment([2007, 1, 28]).add({h:22}), true), "päivä", "22 hours = a day");
139
test.equal(start.from(moment([2007, 1, 28]).add({h:35}), true), "päivä", "35 hours = a day");
140
test.equal(start.from(moment([2007, 1, 28]).add({h:36}), true), "kaksi päivää", "36 hours = 2 days");
141
test.equal(start.from(moment([2007, 1, 28]).add({d:1}), true), "päivä", "1 day = a day");
142
test.equal(start.from(moment([2007, 1, 28]).add({d:5}), true), "viisi päivää", "5 days = 5 days");
143
test.equal(start.from(moment([2007, 1, 28]).add({d:25}), true), "25 päivää", "25 days = 25 days");
144
test.equal(start.from(moment([2007, 1, 28]).add({d:26}), true), "kuukausi", "26 days = a month");
145
test.equal(start.from(moment([2007, 1, 28]).add({d:30}), true), "kuukausi", "30 days = a month");
146
test.equal(start.from(moment([2007, 1, 28]).add({d:45}), true), "kuukausi", "45 days = a month");
147
test.equal(start.from(moment([2007, 1, 28]).add({d:46}), true), "kaksi kuukautta", "46 days = 2 months");
148
test.equal(start.from(moment([2007, 1, 28]).add({d:74}), true), "kaksi kuukautta", "75 days = 2 months");
149
test.equal(start.from(moment([2007, 1, 28]).add({d:76}), true), "kolme kuukautta", "76 days = 3 months");
150
test.equal(start.from(moment([2007, 1, 28]).add({M:1}), true), "kuukausi", "1 month = a month");
151
test.equal(start.from(moment([2007, 1, 28]).add({M:5}), true), "viisi kuukautta", "5 months = 5 months");
152
test.equal(start.from(moment([2007, 1, 28]).add({d:344}), true), "11 kuukautta", "344 days = 11 months");
153
test.equal(start.from(moment([2007, 1, 28]).add({d:345}), true), "vuosi", "345 days = a year");
154
test.equal(start.from(moment([2007, 1, 28]).add({d:547}), true), "vuosi", "547 days = a year");
155
test.equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "kaksi vuotta", "548 days = 2 years");
156
test.equal(start.from(moment([2007, 1, 28]).add({y:1}), true), "vuosi", "1 year = a year");
157
test.equal(start.from(moment([2007, 1, 28]).add({y:5}), true), "viisi vuotta", "5 years = 5 years");
161
"suffix" : function(test) {
164
test.equal(moment(30000).from(0), "muutaman sekunnin päästä", "prefix");
165
test.equal(moment(0).from(30000), "muutama sekunti sitten", "suffix");
169
"now from now" : function(test) {
172
test.equal(moment().fromNow(), "muutama sekunti sitten", "now from now should display as in the past");
176
"fromNow" : function(test) {
179
test.equal(moment().add({s:30}).fromNow(), "muutaman sekunnin päästä", "in a few seconds");
180
test.equal(moment().add({d:5}).fromNow(), "viiden päivän päästä", "in 5 days");
184
"calendar day" : function(test) {
188
var a = moment().hours(2).minutes(0).seconds(0);
190
test.equal(moment(a).calendar(), "tänään klo 02.00", "today at the same time");
191
test.equal(moment(a).add({ m: 25 }).calendar(), "tänään klo 02.25", "Now plus 25 min");
192
test.equal(moment(a).add({ h: 1 }).calendar(), "tänään klo 03.00", "Now plus 1 hour");
193
test.equal(moment(a).add({ d: 1 }).calendar(), "huomenna klo 02.00", "tomorrow at the same time");
194
test.equal(moment(a).subtract({ h: 1 }).calendar(), "tänään klo 01.00", "Now minus 1 hour");
195
test.equal(moment(a).subtract({ d: 1 }).calendar(), "eilen klo 02.00", "yesterday at the same time");
199
"calendar next week" : function(test) {
206
for (i = 2; i < 7; i++) {
207
m = moment().add({ d: i });
208
test.equal(m.calendar(), m.format('dddd [klo] LT'), "today + " + i + " days current time");
209
m.hours(0).minutes(0).seconds(0).milliseconds(0);
210
test.equal(m.calendar(), m.format('dddd [klo] LT'), "today + " + i + " days beginning of day");
211
m.hours(23).minutes(59).seconds(59).milliseconds(999);
212
test.equal(m.calendar(), m.format('dddd [klo] LT'), "today + " + i + " days end of day");
217
"calendar last week" : function(test) {
221
for (var i = 2; i < 7; i++) {
222
var m = moment().subtract({ d: i });
223
test.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), "today - " + i + " days current time");
224
m.hours(0).minutes(0).seconds(0).milliseconds(0);
225
test.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), "today - " + i + " days beginning of day");
226
m.hours(23).minutes(59).seconds(59).milliseconds(999);
227
test.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), "today - " + i + " days end of day");
232
"calendar all else" : function(test) {
235
var weeksAgo = moment().subtract({ w: 1 });
236
var weeksFromNow = moment().add({ w: 1 });
238
test.equal(weeksAgo.calendar(), weeksAgo.format('L'), "yksi viikko sitten");
239
test.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), "yhden viikon päästä");
241
weeksAgo = moment().subtract({ w: 2 });
242
weeksFromNow = moment().add({ w: 2 });
244
test.equal(weeksAgo.calendar(), weeksAgo.format('L'), "kaksi viikkoa sitten");
245
test.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), "kaden viikon päästä");