How to use makeFormat method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

parent-child.js

Source: parent-child.js Github

copy
1var ProLog = require('../lib/prolog').ProLog;
2var $ = require('chalk');
3
4function makeFormat(level, messageColor) {
5  return '<% if (date) { %>' + $.gray('${date}') + '<% } %>' +
6    level + ' ' +
7    '<% if (padding) { %>' + $.gray('${padding}') + '<% } %>' +
8    $[messageColor]('${message}') +
9    '<% if (debug) { %>' + $.gray('${debug}') + '<% } %>';
10}
11
12// Instantiate logger with custom levels.
13var parentLog = new ProLog({
14  levels: {
15    header:     {priority: 0, format: makeFormat('>>>', 'underline')},
16    log:        {priority: 1, format: makeFormat('log', 'reset')},
17    parentonly: {priority: 2, format: makeFormat($.green('par'), 'green')},
18    error:      {priority: 3, format: makeFormat($.red('err'), 'red')},
19  },
20});
21
22// This child logger will send all logging messages to its parent. Note that
23// the "output" option is set to false by default for child loggers.
24var childLogs = [];
25var childLog = new ProLog(parentLog, {
26  levels: {
27    // Don't inherit the parent-only level.
28    parentonly: null,
29    // Create a child-only level.
30    childonly: {priority: 2, format: makeFormat($.cyan('chi'), 'cyan')},
31  },
32  // Totally custom output just for the child logger.
33  // Push un-colored formatted message onto an array.
34  output: function(data) {
35    childLogs.push($.stripColor(this.format(data)));
36  },
37  // Don't split output across multiple lines.
38  format: function(data) {
39    return data.format(this.dataPlus(data));
40  },
41  // Show date and debugging info.
42  formatDate: true,
43  formatDebug: true,
44  // Simplify padding.
45  formatPadding: function(data) {
46    return new Array(data.indent + 1).join('  ');
47  },
48});
49
50console.log('===== Parent and Child Logs =====\n');
51
52var examples = {};
53examples.parent = function() {
54  parentLog.group('Logging levels that don\'t exist on a logger can\'t be called.');
55  parentLog.log('This log message comes from the parent.');
56  parentLog.parentonly('This "parentonly" message comes from the parent.');
57  try {
58    parentLog.childonly('This will throw an exception.');
59  } catch (err) {
60    parentLog.error('Exception: %s', err.message);
61  }
62  parentLog.groupEnd();
63}
64
65examples.child = function() {
66  childLog.group('But will be passed-through.');
67  childLog.log('This log message comes from the child.');
68  childLog.childonly('This "childonly" message comes from the child.');
69  try {
70    childLog.parentonly('This will throw an exception.');
71  } catch (err) {
72    childLog.error('Exception: %s', err.message);
73  }
74  childLog.groupEnd();
75}
76
77examples.grouping = function() {
78  parentLog.header('Note that indentation is cumulative.');
79  parentLog.log('This parent log message should not be indented.');
80  childLog.log('This child log message should not be indented.');
81  parentLog.group('[1] Increase parentLog indent');
82  parentLog.log('This parent log message should be indented once.');
83  childLog.log('This child log message should be indented once.');
84  childLog.group('[2] Increase childLog indent');
85  parentLog.log('This parent log message should still be indented once.');
86  childLog.log('This child log message should be indented twice.');
87  childLog.log([['This array will be indented twice'], ['and logged over'], ['multiple lines.']]);
88  childLog.log('Testing twice-indented child log message %s: %d, %j.', 'A', 1, {a: 1});
89  childLog.groupEnd();
90  childLog.header('[2] Decrease childLog indent');
91  parentLog.log('This parent log message should still be indented once.');
92  childLog.log('This child log message should be indented once.');
93  parentLog.groupEnd();
94  parentLog.header('[1] Decrease parentLog indent');
95  parentLog.log('This parent log message should not be indented.');
96  childLog.log('This child log message should not be indented.');
97  childLog.group('[3] Increase childLog indent');
98  parentLog.log('This parent log message should not be indented.');
99  childLog.log('This child log message should be indented once.');
100  childLog.groupEnd();
101  childLog.header('[3] Decrease childLog indent');
102}
103
104examples.parent();
105examples.child();
106
107// Differentiate childLog messages visually when logged through parentLog.
108parentLog.filter = function(data) {
109  if (data.logger !== this) {
110    data.message = this.eachLine(data.message, $.yellow);
111  }
112};
113childLog.log('All childlog messages logged via parentLog should now be yellow.');
114
115examples.grouping();
116
117console.log('\n===== Just Child Logs =====\n');
118console.log(childLogs.join('\n'));
119
Full Screen

hr.js

Source: hr.js Github

copy
1var moment = require("../../moment");
2
3
4    /**************************************************
5      Croatian
6     *************************************************/
7
8exports["lang:hr"] = {
9    setUp : function (cb) {
10        moment.lang('hr');
11        cb();
12    },
13
14    tearDown : function (cb) {
15        moment.lang('en');
16        cb();
17    },
18
19    "parse" : function (test) {
20        test.expect(96);
21
22        var tests = 'sječanj sje._veljača vel._ožujak ožu._travanj tra._svibanj svi._lipanj lip._srpanj srp._kolovoz kol._rujan ruj._listopad lis._studeni stu._prosinac pro.'.split("_"), i;
23        function equalTest(input, mmm, i) {
24            test.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
25        }
26        for (i = 0; i < 12; i++) {
27            tests[i] = tests[i].split(' ');
28            equalTest(tests[i][0], 'MMM', i);
29            equalTest(tests[i][1], 'MMM', i);
30            equalTest(tests[i][0], 'MMMM', i);
31            equalTest(tests[i][1], 'MMMM', i);
32            equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
33            equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
34            equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
35            equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
36        }
37        test.done();
38    },
39
40    "format" : function (test) {
41        test.expect(22);
42        var a = [
43                ['dddd, Do MMMM YYYY, h:mm:ss a',      'nedjelja, 14. veljača 2010, 3:25:50 pm'],
44                ['ddd, hA',                            'ned., 3PM'],
45                ['M Mo MM MMMM MMM',                   '2 2. 02 veljača vel.'],
46                ['YYYY YY',                            '2010 10'],
47                ['D Do DD',                            '14 14. 14'],
48                ['d do dddd ddd dd',                   '0 0. nedjelja ned. ne'],
49                ['DDD DDDo DDDD',                      '45 45. 045'],
50                ['w wo ww',                            '7 7. 07'],
51                ['h hh',                               '3 03'],
52                ['H HH',                               '15 15'],
53                ['m mm',                               '25 25'],
54                ['s ss',                               '50 50'],
55                ['a A',                                'pm PM'],
56                ['[the] DDDo [day of the year]',       'the 45. day of the year'],
57                ['L',                                  '14. 02. 2010'],
58                ['LL',                                 '14. veljača 2010'],
59                ['LLL',                                '14. veljača 2010 15:25'],
60                ['LLLL',                               'nedjelja, 14. veljača 2010 15:25'],
61                ['l',                                  '14. 2. 2010'],
62                ['ll',                                 '14. vel. 2010'],
63                ['lll',                                '14. vel. 2010 15:25'],
64                ['llll',                               'ned., 14. vel. 2010 15:25']
65            ],
66            b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
67            i;
68        for (i = 0; i < a.length; i++) {
69            test.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
70        }
71        test.done();
72    },
73
74    "format ordinal" : function (test) {
75        test.expect(31);
76        test.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
77        test.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
78        test.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
79        test.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
80        test.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
81        test.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
82        test.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
83        test.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
84        test.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
85        test.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
86
87        test.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
88        test.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
89        test.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
90        test.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
91        test.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
92        test.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
93        test.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
94        test.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
95        test.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
96        test.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
97
98        test.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
99        test.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
100        test.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
101        test.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
102        test.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
103        test.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
104        test.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
105        test.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
106        test.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
107        test.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
108
109        test.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
110        test.done();
111    },
112
113    "format month" : function (test) {
114        test.expect(12);
115        var expected = 'sječanj sje._veljača vel._ožujak ožu._travanj tra._svibanj svi._lipanj lip._srpanj srp._kolovoz kol._rujan ruj._listopad lis._studeni stu._prosinac pro.'.split("_"), i;
116        for (i = 0; i < expected.length; i++) {
117            test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
118        }
119        test.done();
120    },
121
122    "format week" : function (test) {
123        test.expect(7);
124        var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split("_"), i;
125        for (i = 0; i < expected.length; i++) {
126            test.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
127        }
128        test.done();
129    },
130
131    "from" : function (test) {
132        test.expect(30);
133        var start = moment([2007, 1, 28]);
134        test.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true),  "par sekundi", "44 seconds = a few seconds");
135        test.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true),  "jedna minuta",   "45 seconds = a minute");
136        test.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true),  "jedna minuta",   "89 seconds = a minute");
137        test.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true),  "2 minute",     "90 seconds = 2 minutes");
138        test.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true),  "44 minuta",     "44 minutes = 44 minutes");
139        test.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true),  "jedan sat",      "45 minutes = an hour");
140        test.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true),  "jedan sat",      "89 minutes = an hour");
141        test.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true),  "2 sata",        "90 minutes = 2 hours");
142        test.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true),   "5 sati",         "5 hours = 5 hours");
143        test.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true),  "21 sati",        "21 hours = 21 hours");
144        test.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true),  "dan",       "22 hours = a day");
145        test.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true),  "dan",       "35 hours = a day");
146        test.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true),  "2 dana",        "36 hours = 2 days");
147        test.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true),   "dan",       "1 day = a day");
148        test.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true),   "5 dana",        "5 days = 5 days");
149        test.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true),  "25 dana",       "25 days = 25 days");
150        test.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true),  "mjesec",     "26 days = a month");
151        test.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true),  "mjesec",     "30 days = a month");
152        test.equal(start.from(moment([2007, 1, 28]).add({d: 45}), true),  "mjesec",     "45 days = a month");
153        test.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true),  "2 mjeseca",     "46 days = 2 months");
154        test.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true),  "2 mjeseca",     "75 days = 2 months");
155        test.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true),  "3 mjeseca",     "76 days = 3 months");
156        test.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true),   "mjesec",     "1 month = a month");
157        test.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true),   "5 mjeseci",    "5 months = 5 months");
158        test.equal(start.from(moment([2007, 1, 28]).add({d: 344}), true), "11 mjeseci",   "344 days = 11 months");
159        test.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), "godinu",     "345 days = a year");
160        test.equal(start.from(moment([2007, 1, 28]).add({d: 547}), true), "godinu",     "547 days = a year");
161        test.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), "2 godine",       "548 days = 2 years");
162        test.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true),   "godinu",     "1 year = a year");
163        test.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true),   "5 godina",        "5 years = 5 years");
164        test.done();
165    },
166
167    "suffix" : function (test) {
168        test.expect(2);
169        test.equal(moment(30000).from(0), "za par sekundi",  "prefix");
170        test.equal(moment(0).from(30000), "prije par sekundi", "prefix");
171        test.done();
172    },
173
174    "now from now" : function (test) {
175        test.expect(1);
176        test.equal(moment().fromNow(), "prije par sekundi",  "now from now should display as in the past");
177        test.done();
178    },
179
180    "fromNow" : function (test) {
181        test.expect(2);
182        test.equal(moment().add({s: 30}).fromNow(), "za par sekundi", "in a few seconds");
183        test.equal(moment().add({d: 5}).fromNow(), "za 5 dana", "in 5 days");
184        test.done();
185    },
186
187    "calendar day" : function (test) {
188        test.expect(6);
189
190        var a = moment().hours(2).minutes(0).seconds(0);
191
192        test.equal(moment(a).calendar(),                     "danas u 2:00",  "today at the same time");
193        test.equal(moment(a).add({ m: 25 }).calendar(),      "danas u 2:25",  "Now plus 25 min");
194        test.equal(moment(a).add({ h: 1 }).calendar(),       "danas u 3:00",  "Now plus 1 hour");
195        test.equal(moment(a).add({ d: 1 }).calendar(),       "sutra u 2:00",  "tomorrow at the same time");
196        test.equal(moment(a).subtract({ h: 1 }).calendar(),  "danas u 1:00",  "Now minus 1 hour");
197        test.equal(moment(a).subtract({ d: 1 }).calendar(),  "jučer u 2:00", "yesterday at the same time");
198        test.done();
199    },
200
201    "calendar next week" : function (test) {
202        test.expect(15);
203
204        var i, m;
205
206        function makeFormat(d) {
207            switch (d.day()) {
208            case 0:
209                return '[u] [nedjelju] [u] LT';
210            case 3:
211                return '[u] [srijedu] [u] LT';
212            case 6:
213                return '[u] [subotu] [u] LT';
214            case 1:
215            case 2:
216            case 4:
217            case 5:
218                return '[u] dddd [u] LT';
219            }
220        }
221
222        for (i = 2; i < 7; i++) {
223            m = moment().add({ d: i });
224            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today + " + i + " days current time");
225            m.hours(0).minutes(0).seconds(0).milliseconds(0);
226            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today + " + i + " days beginning of day");
227            m.hours(23).minutes(59).seconds(59).milliseconds(999);
228            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today + " + i + " days end of day");
229        }
230        test.done();
231    },
232
233    "calendar last week" : function (test) {
234        test.expect(15);
235
236        var i, m;
237
238        function makeFormat(d) {
239            switch (d.day()) {
240            case 0:
241            case 3:
242                return '[prošlu] dddd [u] LT';
243            case 6:
244                return '[prošle] [subote] [u] LT';
245            case 1:
246            case 2:
247            case 4:
248            case 5:
249                return '[prošli] dddd [u] LT';
250            }
251        }
252
253        for (i = 2; i < 7; i++) {
254            m = moment().subtract({ d: i });
255            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today - " + i + " days current time");
256            m.hours(0).minutes(0).seconds(0).milliseconds(0);
257            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today - " + i + " days beginning of day");
258            m.hours(23).minutes(59).seconds(59).milliseconds(999);
259            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today - " + i + " days end of day");
260        }
261        test.done();
262    },
263
264    "calendar all else" : function (test) {
265        test.expect(4);
266
267        var weeksAgo = moment().subtract({ w: 1 }),
268            weeksFromNow = moment().add({ w: 1 });
269
270        test.equal(weeksAgo.calendar(),       weeksAgo.format('L'),  "1 week ago");
271        test.equal(weeksFromNow.calendar(),   weeksFromNow.format('L'),  "in 1 week");
272
273        weeksAgo = moment().subtract({ w: 2 });
274        weeksFromNow = moment().add({ w: 2 });
275
276        test.equal(weeksAgo.calendar(),       weeksAgo.format('L'),  "2 weeks ago");
277        test.equal(weeksFromNow.calendar(),   weeksFromNow.format('L'),  "in 2 weeks");
278
279        test.done();
280    },
281
282    // Monday is the first day of the week.
283    // The week that contains Jan 1st is the first week of the year.
284
285    "weeks year starting sunday" : function (test) {
286        test.expect(5);
287
288        test.equal(moment([2011, 11, 26]).week(), 1, "Dec 26 2011 should be week 1");
289        test.equal(moment([2012,  0,  1]).week(), 1, "Jan  1 2012 should be week 1");
290        test.equal(moment([2012,  0,  2]).week(), 2, "Jan  2 2012 should be week 2");
291        test.equal(moment([2012,  0,  8]).week(), 2, "Jan  8 2012 should be week 2");
292        test.equal(moment([2012,  0,  9]).week(), 3, "Jan  9 2012 should be week 3");
293
294        test.done();
295    },
296
297    "weeks year starting monday" : function (test) {
298        test.expect(5);
299
300        test.equal(moment([2007, 0, 1]).week(),  1, "Jan  1 2007 should be week 1");
301        test.equal(moment([2007, 0, 7]).week(),  1, "Jan  7 2007 should be week 1");
302        test.equal(moment([2007, 0, 8]).week(),  2, "Jan  8 2007 should be week 2");
303        test.equal(moment([2007, 0, 14]).week(), 2, "Jan 14 2007 should be week 2");
304        test.equal(moment([2007, 0, 15]).week(), 3, "Jan 15 2007 should be week 3");
305
306        test.done();
307    },
308
309    "weeks year starting tuesday" : function (test) {
310        test.expect(6);
311
312        test.equal(moment([2007, 11, 31]).week(), 1, "Dec 31 2007 should be week 1");
313        test.equal(moment([2008,  0,  1]).week(), 1, "Jan  1 2008 should be week 1");
314        test.equal(moment([2008,  0,  6]).week(), 1, "Jan  6 2008 should be week 1");
315        test.equal(moment([2008,  0,  7]).week(), 2, "Jan  7 2008 should be week 2");
316        test.equal(moment([2008,  0, 13]).week(), 2, "Jan 13 2008 should be week 2");
317        test.equal(moment([2008,  0, 14]).week(), 3, "Jan 14 2008 should be week 3");
318
319        test.done();
320    },
321
322    "weeks year starting wednesday" : function (test) {
323        test.expect(6);
324
325        test.equal(moment([2002, 11, 30]).week(), 1, "Dec 30 2002 should be week 1");
326        test.equal(moment([2003,  0,  1]).week(), 1, "Jan  1 2003 should be week 1");
327        test.equal(moment([2003,  0,  5]).week(), 1, "Jan  5 2003 should be week 1");
328        test.equal(moment([2003,  0,  6]).week(), 2, "Jan  6 2003 should be week 2");
329        test.equal(moment([2003,  0, 12]).week(), 2, "Jan 12 2003 should be week 2");
330        test.equal(moment([2003,  0, 13]).week(), 3, "Jan 13 2003 should be week 3");
331
332        test.done();
333    },
334
335    "weeks year starting thursday" : function (test) {
336        test.expect(6);
337
338        test.equal(moment([2008, 11, 29]).week(), 1, "Dec 29 2008 should be week 1");
339        test.equal(moment([2009,  0,  1]).week(), 1, "Jan  1 2009 should be week 1");
340        test.equal(moment([2009,  0,  4]).week(), 1, "Jan  4 2009 should be week 1");
341        test.equal(moment([2009,  0,  5]).week(), 2, "Jan  5 2009 should be week 2");
342        test.equal(moment([2009,  0, 11]).week(), 2, "Jan 11 2009 should be week 2");
343        test.equal(moment([2009,  0, 12]).week(), 3, "Jan 12 2009 should be week 3");
344
345        test.done();
346    },
347
348    "weeks year starting friday" : function (test) {
349        test.expect(6);
350
351        test.equal(moment([2009, 11, 28]).week(), 1, "Dec 28 2009 should be week 1");
352        test.equal(moment([2010,  0,  1]).week(), 1, "Jan  1 2010 should be week 1");
353        test.equal(moment([2010,  0,  3]).week(), 1, "Jan  3 2010 should be week 1");
354        test.equal(moment([2010,  0,  4]).week(), 2, "Jan  4 2010 should be week 2");
355        test.equal(moment([2010,  0, 10]).week(), 2, "Jan 10 2010 should be week 2");
356        test.equal(moment([2010,  0, 11]).week(), 3, "Jan 11 2010 should be week 3");
357
358        test.done();
359    },
360
361    "weeks year starting saturday" : function (test) {
362        test.expect(6);
363
364        test.equal(moment([2010, 11, 27]).week(), 1, "Dec 27 2010 should be week 1");
365        test.equal(moment([2011,  0,  1]).week(), 1, "Jan  1 2011 should be week 1");
366        test.equal(moment([2011,  0,  2]).week(), 1, "Jan  2 2011 should be week 1");
367        test.equal(moment([2011,  0,  3]).week(), 2, "Jan  3 2011 should be week 2");
368        test.equal(moment([2011,  0,  9]).week(), 2, "Jan  9 2011 should be week 2");
369        test.equal(moment([2011,  0, 10]).week(), 3, "Jan 10 2011 should be week 3");
370
371        test.done();
372    },
373
374    "weeks year starting sunday formatted" : function (test) {
375        test.expect(5);
376
377        test.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', "Dec 26 2011 should be week 1");
378        test.equal(moment([2012,  0,  1]).format('w ww wo'), '1 01 1.', "Jan  1 2012 should be week 1");
379        test.equal(moment([2012,  0,  2]).format('w ww wo'), '2 02 2.', "Jan  2 2012 should be week 2");
380        test.equal(moment([2012,  0,  8]).format('w ww wo'), '2 02 2.', "Jan  8 2012 should be week 2");
381        test.equal(moment([2012,  0,  9]).format('w ww wo'), '3 03 3.', "Jan  9 2012 should be week 3");
382
383        test.done();
384    }
385};
386
Full Screen

sl.js

Source: sl.js Github

copy
1var moment = require("../../moment");
2
3
4    /**************************************************
5      Slovenian
6     *************************************************/
7
8exports["lang:sl"] = {
9    setUp : function (cb) {
10        moment.lang('sl');
11        cb();
12    },
13
14    tearDown : function (cb) {
15        moment.lang('en');
16        cb();
17    },
18
19    "parse" : function (test) {
20        test.expect(96);
21
22        var tests = 'januar jan._februar feb._marec mar._april apr._maj maj_junij jun._julij jul._avgust avg._september sep._oktober okt._november nov._december dec.'.split("_"), i;
23        function equalTest(input, mmm, i) {
24            test.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
25        }
26        for (i = 0; i < 12; i++) {
27            tests[i] = tests[i].split(' ');
28            equalTest(tests[i][0], 'MMM', i);
29            equalTest(tests[i][1], 'MMM', i);
30            equalTest(tests[i][0], 'MMMM', i);
31            equalTest(tests[i][1], 'MMMM', i);
32            equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
33            equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
34            equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
35            equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
36        }
37        test.done();
38    },
39
40    "format" : function (test) {
41        test.expect(22);
42        var a = [
43                ['dddd, Do MMMM YYYY, h:mm:ss a',      'nedelja, 14. februar 2010, 3:25:50 pm'],
44                ['ddd, hA',                            'ned., 3PM'],
45                ['M Mo MM MMMM MMM',                   '2 2. 02 februar feb.'],
46                ['YYYY YY',                            '2010 10'],
47                ['D Do DD',                            '14 14. 14'],
48                ['d do dddd ddd dd',                   '0 0. nedelja ned. ne'],
49                ['DDD DDDo DDDD',                      '45 45. 045'],
50                ['w wo ww',                            '7 7. 07'],
51                ['h hh',                               '3 03'],
52                ['H HH',                               '15 15'],
53                ['m mm',                               '25 25'],
54                ['s ss',                               '50 50'],
55                ['a A',                                'pm PM'],
56                ['[the] DDDo [day of the year]',       'the 45. day of the year'],
57                ['L',                                  '14. 02. 2010'],
58                ['LL',                                 '14. februar 2010'],
59                ['LLL',                                '14. februar 2010 15:25'],
60                ['LLLL',                               'nedelja, 14. februar 2010 15:25'],
61                ['l',                                  '14. 2. 2010'],
62                ['ll',                                 '14. feb. 2010'],
63                ['lll',                                '14. feb. 2010 15:25'],
64                ['llll',                               'ned., 14. feb. 2010 15:25']
65            ],
66            b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
67            i;
68        for (i = 0; i < a.length; i++) {
69            test.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
70        }
71        test.done();
72    },
73
74    "format ordinal" : function (test) {
75        test.expect(31);
76        test.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
77        test.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
78        test.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
79        test.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
80        test.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
81        test.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
82        test.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
83        test.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
84        test.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
85        test.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
86
87        test.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
88        test.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
89        test.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
90        test.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
91        test.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
92        test.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
93        test.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
94        test.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
95        test.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
96        test.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
97
98        test.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
99        test.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
100        test.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
101        test.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
102        test.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
103        test.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
104        test.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
105        test.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
106        test.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
107        test.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
108
109        test.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
110        test.done();
111    },
112
113    "format month" : function (test) {
114        test.expect(12);
115        var expected = 'januar jan._februar feb._marec mar._april apr._maj maj._junij jun._julij jul._avgust avg._september sep._oktober okt._november nov._december dec.'.split("_"), i;
116        for (i = 0; i < expected.length; i++) {
117            test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
118        }
119        test.done();
120    },
121
122    "format week" : function (test) {
123        test.expect(7);
124        var expected = 'nedelja ned. ne_ponedeljek pon. po_torek tor. to_sreda sre. sr_četrtek čet. če_petek pet. pe_sobota sob. so'.split("_"), i;
125        for (i = 0; i < expected.length; i++) {
126            test.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
127        }
128        test.done();
129    },
130
131    "from" : function (test) {
132        test.expect(30);
133        var start = moment([2007, 1, 28]);
134        test.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true),  "nekaj sekund", "44 seconds = a few seconds");
135        test.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true),  "ena minuta",   "45 seconds = a minute");
136        test.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true),  "ena minuta",   "89 seconds = a minute");
137        test.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true),  "2 minuti",     "90 seconds = 2 minutes");
138        test.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true),  "44 minut",     "44 minutes = 44 minutes");
139        test.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true),  "ena ura",      "45 minutes = an hour");
140        test.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true),  "ena ura",      "89 minutes = an hour");
141        test.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true),  "2 uri",        "90 minutes = 2 hours");
142        test.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true),   "5 ur",         "5 hours = 5 hours");
143        test.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true),  "21 ur",        "21 hours = 21 hours");
144        test.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true),  "en dan",       "22 hours = a day");
145        test.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true),  "en dan",       "35 hours = a day");
146        test.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true),  "2 dni",        "36 hours = 2 days");
147        test.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true),   "en dan",       "1 day = a day");
148        test.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true),   "5 dni",        "5 days = 5 days");
149        test.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true),  "25 dni",       "25 days = 25 days");
150        test.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true),  "en mesec",     "26 days = a month");
151        test.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true),  "en mesec",     "30 days = a month");
152        test.equal(start.from(moment([2007, 1, 28]).add({d: 45}), true),  "en mesec",     "45 days = a month");
153        test.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true),  "2 meseca",     "46 days = 2 months");
154        test.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true),  "2 meseca",     "75 days = 2 months");
155        test.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true),  "3 mesece",     "76 days = 3 months");
156        test.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true),   "en mesec",     "1 month = a month");
157        test.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true),   "5 mesecev",    "5 months = 5 months");
158        test.equal(start.from(moment([2007, 1, 28]).add({d: 344}), true), "11 mesecev",   "344 days = 11 months");
159        test.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), "eno leto",     "345 days = a year");
160        test.equal(start.from(moment([2007, 1, 28]).add({d: 547}), true), "eno leto",     "547 days = a year");
161        test.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), "2 leti",       "548 days = 2 years");
162        test.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true),   "eno leto",     "1 year = a year");
163        test.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true),   "5 let",        "5 years = 5 years");
164        test.done();
165    },
166
167    "suffix" : function (test) {
168        test.expect(2);
169        test.equal(moment(30000).from(0), "čez nekaj sekund",  "prefix");
170        test.equal(moment(0).from(30000), "nekaj sekund nazaj", "suffix");
171        test.done();
172    },
173
174    "now from now" : function (test) {
175        test.expect(1);
176        test.equal(moment().fromNow(), "nekaj sekund nazaj",  "now from now should display as in the past");
177        test.done();
178    },
179
180    "fromNow" : function (test) {
181        test.expect(2);
182        test.equal(moment().add({s: 30}).fromNow(), "čez nekaj sekund", "in a few seconds");
183        test.equal(moment().add({d: 5}).fromNow(), "čez 5 dni", "in 5 days");
184        test.done();
185    },
186
187    "calendar day" : function (test) {
188        test.expect(6);
189
190        var a = moment().hours(2).minutes(0).seconds(0);
191
192        test.equal(moment(a).calendar(),                     "danes ob 2:00",  "today at the same time");
193        test.equal(moment(a).add({ m: 25 }).calendar(),      "danes ob 2:25",  "Now plus 25 min");
194        test.equal(moment(a).add({ h: 1 }).calendar(),       "danes ob 3:00",  "Now plus 1 hour");
195        test.equal(moment(a).add({ d: 1 }).calendar(),       "jutri ob 2:00",  "tomorrow at the same time");
196        test.equal(moment(a).subtract({ h: 1 }).calendar(),  "danes ob 1:00",  "Now minus 1 hour");
197        test.equal(moment(a).subtract({ d: 1 }).calendar(),  "včeraj ob 2:00", "yesterday at the same time");
198        test.done();
199    },
200
201    "calendar next week" : function (test) {
202        test.expect(15);
203
204        var i, m;
205
206        function makeFormat(d) {
207            switch (d.day()) {
208            case 0:
209                return '[v] [nedeljo] [ob] LT';
210            case 3:
211                return '[v] [sredo] [ob] LT';
212            case 6:
213                return '[v] [soboto] [ob] LT';
214            case 1:
215            case 2:
216            case 4:
217            case 5:
218                return '[v] dddd [ob] LT';
219            }
220        }
221
222        for (i = 2; i < 7; i++) {
223            m = moment().add({ d: i });
224            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today + " + i + " days current time");
225            m.hours(0).minutes(0).seconds(0).milliseconds(0);
226            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today + " + i + " days beginning of day");
227            m.hours(23).minutes(59).seconds(59).milliseconds(999);
228            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today + " + i + " days end of day");
229        }
230        test.done();
231    },
232
233    "calendar last week" : function (test) {
234        test.expect(15);
235
236        var i, m;
237
238        function makeFormat(d) {
239            switch (d.day()) {
240            case 0:
241            case 3:
242            case 6:
243                return '[prejšnja] dddd [ob] LT';
244            case 1:
245            case 2:
246            case 4:
247            case 5:
248                return '[prejšnji] dddd [ob] LT';
249            }
250        }
251
252        for (i = 2; i < 7; i++) {
253            m = moment().subtract({ d: i });
254            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today - " + i + " days current time");
255            m.hours(0).minutes(0).seconds(0).milliseconds(0);
256            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today - " + i + " days beginning of day");
257            m.hours(23).minutes(59).seconds(59).milliseconds(999);
258            test.equal(m.calendar(),       m.format(makeFormat(m)),  "Today - " + i + " days end of day");
259        }
260        test.done();
261    },
262
263    "calendar all else" : function (test) {
264        test.expect(4);
265
266        var weeksAgo = moment().subtract({ w: 1 }),
267            weeksFromNow = moment().add({ w: 1 });
268
269        test.equal(weeksAgo.calendar(),       weeksAgo.format('L'),  "1 week ago");
270        test.equal(weeksFromNow.calendar(),   weeksFromNow.format('L'),  "in 1 week");
271
272        weeksAgo = moment().subtract({ w: 2 });
273        weeksFromNow = moment().add({ w: 2 });
274
275        test.equal(weeksAgo.calendar(),       weeksAgo.format('L'),  "2 weeks ago");
276        test.equal(weeksFromNow.calendar(),   weeksFromNow.format('L'),  "in 2 weeks");
277
278        test.done();
279    },
280
281    // Monday is the first day of the week.
282    // The week that contains Jan 1st is the first week of the year.
283
284    "weeks year starting sunday" : function (test) {
285        test.expect(5);
286
287        test.equal(moment([2011, 11, 26]).week(), 1, "Dec 26 2011 should be week 1");
288        test.equal(moment([2012,  0,  1]).week(), 1, "Jan  1 2012 should be week 1");
289        test.equal(moment([2012,  0,  2]).week(), 2, "Jan  2 2012 should be week 2");
290        test.equal(moment([2012,  0,  8]).week(), 2, "Jan  8 2012 should be week 2");
291        test.equal(moment([2012,  0,  9]).week(), 3, "Jan  9 2012 should be week 3");
292
293        test.done();
294    },
295
296    "weeks year starting monday" : function (test) {
297        test.expect(5);
298
299        test.equal(moment([2007, 0, 1]).week(),  1, "Jan  1 2007 should be week 1");
300        test.equal(moment([2007, 0, 7]).week(),  1, "Jan  7 2007 should be week 1");
301        test.equal(moment([2007, 0, 8]).week(),  2, "Jan  8 2007 should be week 2");
302        test.equal(moment([2007, 0, 14]).week(), 2, "Jan 14 2007 should be week 2");
303        test.equal(moment([2007, 0, 15]).week(), 3, "Jan 15 2007 should be week 3");
304
305        test.done();
306    },
307
308    "weeks year starting tuesday" : function (test) {
309        test.expect(6);
310
311        test.equal(moment([2007, 11, 31]).week(), 1, "Dec 31 2007 should be week 1");
312        test.equal(moment([2008,  0,  1]).week(), 1, "Jan  1 2008 should be week 1");
313        test.equal(moment([2008,  0,  6]).week(), 1, "Jan  6 2008 should be week 1");
314        test.equal(moment([2008,  0,  7]).week(), 2, "Jan  7 2008 should be week 2");
315        test.equal(moment([2008,  0, 13]).week(), 2, "Jan 13 2008 should be week 2");
316        test.equal(moment([2008,  0, 14]).week(), 3, "Jan 14 2008 should be week 3");
317
318        test.done();
319    },
320
321    "weeks year starting wednesday" : function (test) {
322        test.expect(6);
323
324        test.equal(moment([2002, 11, 30]).week(), 1, "Dec 30 2002 should be week 1");
325        test.equal(moment([2003,  0,  1]).week(), 1, "Jan  1 2003 should be week 1");
326        test.equal(moment([2003,  0,  5]).week(), 1, "Jan  5 2003 should be week 1");
327        test.equal(moment([2003,  0,  6]).week(), 2, "Jan  6 2003 should be week 2");
328        test.equal(moment([2003,  0, 12]).week(), 2, "Jan 12 2003 should be week 2");
329        test.equal(moment([2003,  0, 13]).week(), 3, "Jan 13 2003 should be week 3");
330
331        test.done();
332    },
333
334    "weeks year starting thursday" : function (test) {
335        test.expect(6);
336
337        test.equal(moment([2008, 11, 29]).week(), 1, "Dec 29 2008 should be week 1");
338        test.equal(moment([2009,  0,  1]).week(), 1, "Jan  1 2009 should be week 1");
339        test.equal(moment([2009,  0,  4]).week(), 1, "Jan  4 2009 should be week 1");
340        test.equal(moment([2009,  0,  5]).week(), 2, "Jan  5 2009 should be week 2");
341        test.equal(moment([2009,  0, 11]).week(), 2, "Jan 11 2009 should be week 2");
342        test.equal(moment([2009,  0, 12]).week(), 3, "Jan 12 2009 should be week 3");
343
344        test.done();
345    },
346
347    "weeks year starting friday" : function (test) {
348        test.expect(6);
349
350        test.equal(moment([2009, 11, 28]).week(), 1, "Dec 28 2009 should be week 1");
351        test.equal(moment([2010,  0,  1]).week(), 1, "Jan  1 2010 should be week 1");
352        test.equal(moment([2010,  0,  3]).week(), 1, "Jan  3 2010 should be week 1");
353        test.equal(moment([2010,  0,  4]).week(), 2, "Jan  4 2010 should be week 2");
354        test.equal(moment([2010,  0, 10]).week(), 2, "Jan 10 2010 should be week 2");
355        test.equal(moment([2010,  0, 11]).week(), 3, "Jan 11 2010 should be week 3");
356
357        test.done();
358    },
359
360    "weeks year starting saturday" : function (test) {
361        test.expect(6);
362
363        test.equal(moment([2010, 11, 27]).week(), 1, "Dec 27 2010 should be week 1");
364        test.equal(moment([2011,  0,  1]).week(), 1, "Jan  1 2011 should be week 1");
365        test.equal(moment([2011,  0,  2]).week(), 1, "Jan  2 2011 should be week 1");
366        test.equal(moment([2011,  0,  3]).week(), 2, "Jan  3 2011 should be week 2");
367        test.equal(moment([2011,  0,  9]).week(), 2, "Jan  9 2011 should be week 2");
368        test.equal(moment([2011,  0, 10]).week(), 3, "Jan 10 2011 should be week 3");
369
370        test.done();
371    },
372
373    "weeks year starting sunday formatted" : function (test) {
374        test.expect(5);
375
376        test.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', "Dec 26 2011 should be week 1");
377        test.equal(moment([2012,  0,  1]).format('w ww wo'), '1 01 1.', "Jan  1 2012 should be week 1");
378        test.equal(moment([2012,  0,  2]).format('w ww wo'), '2 02 2.', "Jan  2 2012 should be week 2");
379        test.equal(moment([2012,  0,  8]).format('w ww wo'), '2 02 2.', "Jan  8 2012 should be week 2");
380        test.equal(moment([2012,  0,  9]).format('w ww wo'), '3 03 3.', "Jan  9 2012 should be week 3");
381
382        test.done();
383    }
384};
385
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)