1 | var moment = require('../module/moment');
|
2 | var DateUtil = require('./DateUtil');
|
3 | var util = require('vis-util');
|
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 | function TimeStep(start, end, minimumStep, hiddenDates, options) {
|
34 | this.moment = moment;
|
35 |
|
36 |
|
37 | this.current = this.moment();
|
38 | this._start = this.moment();
|
39 | this._end = this.moment();
|
40 |
|
41 | this.autoScale = true;
|
42 | this.scale = 'day';
|
43 | this.step = 1;
|
44 |
|
45 |
|
46 | this.setRange(start, end, minimumStep);
|
47 |
|
48 |
|
49 | this.switchedDay = false;
|
50 | this.switchedMonth = false;
|
51 | this.switchedYear = false;
|
52 | if (Array.isArray(hiddenDates)) {
|
53 | this.hiddenDates = hiddenDates;
|
54 | }
|
55 | else if (hiddenDates != undefined) {
|
56 | this.hiddenDates = [hiddenDates];
|
57 | }
|
58 | else {
|
59 | this.hiddenDates = [];
|
60 | }
|
61 |
|
62 | this.format = TimeStep.FORMAT;
|
63 | this.options = options ? options : {};
|
64 |
|
65 | }
|
66 |
|
67 |
|
68 | TimeStep.FORMAT = {
|
69 | minorLabels: {
|
70 | millisecond:'SSS',
|
71 | second: 's',
|
72 | minute: 'HH:mm',
|
73 | hour: 'HH:mm',
|
74 | weekday: 'ddd D',
|
75 | day: 'D',
|
76 | week: 'D',
|
77 | month: 'MMM',
|
78 | quarter: 'MMM',
|
79 | year: 'YYYY'
|
80 | },
|
81 | majorLabels: {
|
82 | millisecond:'HH:mm:ss',
|
83 | second: 'D MMMM HH:mm',
|
84 | minute: 'ddd D MMMM',
|
85 | hour: 'ddd D MMMM',
|
86 | weekday: 'MMMM YYYY',
|
87 | day: 'MMMM YYYY',
|
88 | week: 'MMMM YYYY',
|
89 | month: 'YYYY',
|
90 | quarter: 'YYYY',
|
91 | year: ''
|
92 | }
|
93 | };
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | TimeStep.prototype.setMoment = function (moment) {
|
101 | this.moment = moment;
|
102 |
|
103 |
|
104 | this.current = this.moment(this.current.valueOf());
|
105 | this._start = this.moment(this._start.valueOf());
|
106 | this._end = this.moment(this._end.valueOf());
|
107 | };
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | TimeStep.prototype.setFormat = function (format) {
|
116 | var defaultFormat = util.deepExtend({}, TimeStep.FORMAT);
|
117 | this.format = util.deepExtend(defaultFormat, format);
|
118 | };
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | TimeStep.prototype.setRange = function(start, end, minimumStep) {
|
131 | if (!(start instanceof Date) || !(end instanceof Date)) {
|
132 | throw "No legal start or end date in method setRange";
|
133 | }
|
134 |
|
135 | this._start = (start != undefined) ? this.moment(start.valueOf()) : new Date();
|
136 | this._end = (end != undefined) ? this.moment(end.valueOf()) : new Date();
|
137 |
|
138 | if (this.autoScale) {
|
139 | this.setMinimumStep(minimumStep);
|
140 | }
|
141 | };
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | TimeStep.prototype.start = function() {
|
147 | this.current = this._start.clone();
|
148 | this.roundToMinor();
|
149 | };
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | TimeStep.prototype.roundToMinor = function() {
|
156 |
|
157 |
|
158 | if (this.scale == 'week') {
|
159 | this.current.weekday(0);
|
160 | }
|
161 |
|
162 |
|
163 | switch (this.scale) {
|
164 | case 'year':
|
165 | this.current.year(this.step * Math.floor(this.current.year() / this.step));
|
166 | this.current.month(0);
|
167 | case 'quarter': this.current.month(0);
|
168 | case 'month': this.current.date(1);
|
169 | case 'week':
|
170 | case 'day':
|
171 | case 'weekday': this.current.hours(0);
|
172 | case 'hour': this.current.minutes(0);
|
173 | case 'minute': this.current.seconds(0);
|
174 | case 'second': this.current.milliseconds(0);
|
175 |
|
176 | }
|
177 |
|
178 | if (this.step != 1) {
|
179 |
|
180 | switch (this.scale) {
|
181 | case 'millisecond': this.current.subtract(this.current.milliseconds() % this.step, 'milliseconds'); break;
|
182 | case 'second': this.current.subtract(this.current.seconds() % this.step, 'seconds'); break;
|
183 | case 'minute': this.current.subtract(this.current.minutes() % this.step, 'minutes'); break;
|
184 | case 'hour': this.current.subtract(this.current.hours() % this.step, 'hours'); break;
|
185 | case 'weekday':
|
186 | case 'day': this.current.subtract((this.current.date() - 1) % this.step, 'day'); break;
|
187 | case 'week': this.current.subtract(this.current.week() % this.step, 'week'); break;
|
188 | case 'month': this.current.subtract(this.current.month() % this.step, 'month'); break;
|
189 | case 'quarter': this.current.subtract((this.current.quarter() - 1) % this.step, 'quarter'); break;
|
190 | case 'year': this.current.subtract(this.current.year() % this.step, 'year'); break;
|
191 | default: break;
|
192 | }
|
193 | }
|
194 | };
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | TimeStep.prototype.hasNext = function () {
|
201 | return (this.current.valueOf() <= this._end.valueOf());
|
202 | };
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | TimeStep.prototype.next = function() {
|
208 | var prev = this.current.valueOf();
|
209 |
|
210 |
|
211 |
|
212 | switch (this.scale) {
|
213 | case 'millisecond': this.current.add(this.step, 'millisecond'); break;
|
214 | case 'second': this.current.add(this.step, 'second'); break;
|
215 | case 'minute': this.current.add(this.step, 'minute'); break;
|
216 | case 'hour':
|
217 | this.current.add(this.step, 'hour');
|
218 |
|
219 | if (this.current.month() < 6) {
|
220 | this.current.subtract(this.current.hours() % this.step, 'hour');
|
221 | } else {
|
222 | if (this.current.hours() % this.step !== 0) {
|
223 | this.current.add(this.step - this.current.hours() % this.step, 'hour');
|
224 | }
|
225 | }
|
226 | break;
|
227 | case 'weekday':
|
228 | case 'day': this.current.add(this.step, 'day'); break;
|
229 | case 'week':
|
230 | if (this.current.weekday() !== 0){
|
231 | this.current.weekday(0);
|
232 | this.current.add(this.step, 'week');
|
233 | } else if(this.options.showMajorLabels === false) {
|
234 | this.current.add(this.step, 'week');
|
235 | } else {
|
236 | var nextWeek = this.current.clone();
|
237 | nextWeek.add(1, 'week');
|
238 | if(nextWeek.isSame(this.current, 'month')){
|
239 | this.current.add(this.step, 'week');
|
240 | } else {
|
241 | this.current.add(this.step, 'week');
|
242 | this.current.date(1);
|
243 | }
|
244 | }
|
245 | break;
|
246 | case 'month': this.current.add(this.step, 'month'); break;
|
247 | case 'quarter': this.current.add(this.step, 'quarter'); break;
|
248 | case 'year': this.current.add(this.step, 'year'); break;
|
249 | default: break;
|
250 | }
|
251 |
|
252 | if (this.step != 1) {
|
253 |
|
254 | switch (this.scale) {
|
255 | case 'millisecond': if(this.current.milliseconds() > 0 && this.current.milliseconds() < this.step) this.current.milliseconds(0); break;
|
256 | case 'second': if(this.current.seconds() > 0 && this.current.seconds() < this.step) this.current.seconds(0); break;
|
257 | case 'minute': if(this.current.minutes() > 0 && this.current.minutes() < this.step) this.current.minutes(0); break;
|
258 | case 'hour': if(this.current.hours() > 0 && this.current.hours() < this.step) this.current.hours(0); break;
|
259 | case 'weekday':
|
260 | case 'day': if(this.current.date() < this.step+1) this.current.date(1); break;
|
261 | case 'week': if(this.current.week() < this.step) this.current.week(1); break;
|
262 | case 'month': if(this.current.month() < this.step) this.current.month(0); break;
|
263 | case 'quarter': if(this.current.quarter() < this.step+1) this.current.quarter(1); break;
|
264 | case 'year': break;
|
265 | default: break;
|
266 | }
|
267 | }
|
268 |
|
269 |
|
270 | if (this.current.valueOf() == prev) {
|
271 | this.current = this._end.clone();
|
272 | }
|
273 |
|
274 |
|
275 | this.switchedDay = false;
|
276 | this.switchedMonth = false;
|
277 | this.switchedYear = false;
|
278 |
|
279 | DateUtil.stepOverHiddenDates(this.moment, this, prev);
|
280 | };
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | TimeStep.prototype.getCurrent = function() {
|
288 | return this.current.clone();
|
289 | };
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | TimeStep.prototype.setScale = function(params) {
|
304 | if (params && typeof params.scale == 'string') {
|
305 | this.scale = params.scale;
|
306 | this.step = params.step > 0 ? params.step : 1;
|
307 | this.autoScale = false;
|
308 | }
|
309 | };
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | TimeStep.prototype.setAutoScale = function (enable) {
|
316 | this.autoScale = enable;
|
317 | };
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | TimeStep.prototype.setMinimumStep = function(minimumStep) {
|
325 | if (minimumStep == undefined) {
|
326 | return;
|
327 | }
|
328 |
|
329 |
|
330 |
|
331 | var stepYear = (1000 * 60 * 60 * 24 * 30 * 12);
|
332 | var stepQuarter = (1000 * 60 * 60 * 24 * 30 * 3);
|
333 | var stepMonth = (1000 * 60 * 60 * 24 * 30);
|
334 | var stepDay = (1000 * 60 * 60 * 24);
|
335 | var stepHour = (1000 * 60 * 60);
|
336 | var stepMinute = (1000 * 60);
|
337 | var stepSecond = (1000);
|
338 | var stepMillisecond= (1);
|
339 |
|
340 |
|
341 | if (stepYear*1000 > minimumStep) {this.scale = 'year'; this.step = 1000;}
|
342 | if (stepYear*500 > minimumStep) {this.scale = 'year'; this.step = 500;}
|
343 | if (stepYear*100 > minimumStep) {this.scale = 'year'; this.step = 100;}
|
344 | if (stepYear*50 > minimumStep) {this.scale = 'year'; this.step = 50;}
|
345 | if (stepYear*10 > minimumStep) {this.scale = 'year'; this.step = 10;}
|
346 | if (stepYear*5 > minimumStep) {this.scale = 'year'; this.step = 5;}
|
347 | if (stepYear > minimumStep) {this.scale = 'year'; this.step = 1;}
|
348 | if (stepQuarter > minimumStep) {this.scale = 'quarter'; this.step = 1;}
|
349 | if (stepMonth > minimumStep) {this.scale = 'month'; this.step = 1;}
|
350 | if (stepDay*7 > minimumStep) {this.scale = 'week'; this.step = 1;}
|
351 | if (stepDay*2 > minimumStep) {this.scale = 'day'; this.step = 2;}
|
352 | if (stepDay > minimumStep) {this.scale = 'day'; this.step = 1;}
|
353 | if (stepDay/2 > minimumStep) {this.scale = 'weekday'; this.step = 1;}
|
354 | if (stepHour*4 > minimumStep) {this.scale = 'hour'; this.step = 4;}
|
355 | if (stepHour > minimumStep) {this.scale = 'hour'; this.step = 1;}
|
356 | if (stepMinute*15 > minimumStep) {this.scale = 'minute'; this.step = 15;}
|
357 | if (stepMinute*10 > minimumStep) {this.scale = 'minute'; this.step = 10;}
|
358 | if (stepMinute*5 > minimumStep) {this.scale = 'minute'; this.step = 5;}
|
359 | if (stepMinute > minimumStep) {this.scale = 'minute'; this.step = 1;}
|
360 | if (stepSecond*15 > minimumStep) {this.scale = 'second'; this.step = 15;}
|
361 | if (stepSecond*10 > minimumStep) {this.scale = 'second'; this.step = 10;}
|
362 | if (stepSecond*5 > minimumStep) {this.scale = 'second'; this.step = 5;}
|
363 | if (stepSecond > minimumStep) {this.scale = 'second'; this.step = 1;}
|
364 | if (stepMillisecond*200 > minimumStep) {this.scale = 'millisecond'; this.step = 200;}
|
365 | if (stepMillisecond*100 > minimumStep) {this.scale = 'millisecond'; this.step = 100;}
|
366 | if (stepMillisecond*50 > minimumStep) {this.scale = 'millisecond'; this.step = 50;}
|
367 | if (stepMillisecond*10 > minimumStep) {this.scale = 'millisecond'; this.step = 10;}
|
368 | if (stepMillisecond*5 > minimumStep) {this.scale = 'millisecond'; this.step = 5;}
|
369 | if (stepMillisecond > minimumStep) {this.scale = 'millisecond'; this.step = 1;}
|
370 | };
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 | TimeStep.snap = function(date, scale, step) {
|
383 | var clone = moment(date);
|
384 |
|
385 | if (scale == 'year') {
|
386 | var year = clone.year() + Math.round(clone.month() / 12);
|
387 | clone.year(Math.round(year / step) * step);
|
388 | clone.month(0);
|
389 | clone.date(0);
|
390 | clone.hours(0);
|
391 | clone.minutes(0);
|
392 | clone.seconds(0);
|
393 | clone.milliseconds(0);
|
394 | }
|
395 | else if (scale == 'quarter') {
|
396 | if ((clone.month() % 3 == 1 && clone.date() > 15) || clone.month() % 3 == 2) {
|
397 | clone.date(1);
|
398 | clone.month(Math.floor(clone.month() / 3) * 3);
|
399 | clone.add(1, 'quarter');
|
400 |
|
401 | } else {
|
402 | clone.date(1);
|
403 | clone.month(Math.floor(clone.month() / 3) * 3);
|
404 | }
|
405 |
|
406 | clone.hours(0);
|
407 | clone.minutes(0);
|
408 | clone.seconds(0);
|
409 | clone.milliseconds(0);
|
410 | }
|
411 | else if (scale == 'month') {
|
412 | if (clone.date() > 15) {
|
413 | clone.date(1);
|
414 | clone.add(1, 'month');
|
415 |
|
416 | }
|
417 | else {
|
418 | clone.date(1);
|
419 | }
|
420 |
|
421 | clone.hours(0);
|
422 | clone.minutes(0);
|
423 | clone.seconds(0);
|
424 | clone.milliseconds(0);
|
425 | }
|
426 | else if (scale == 'week') {
|
427 | if (clone.weekday() > 2) {
|
428 | clone.weekday(0);
|
429 | clone.add(1, 'week');
|
430 | }
|
431 | else {
|
432 | clone.weekday(0);
|
433 | }
|
434 |
|
435 | clone.hours(0);
|
436 | clone.minutes(0);
|
437 | clone.seconds(0);
|
438 | clone.milliseconds(0);
|
439 | }
|
440 | else if (scale == 'day') {
|
441 |
|
442 | switch (step) {
|
443 | case 5:
|
444 | case 2:
|
445 | clone.hours(Math.round(clone.hours() / 24) * 24); break;
|
446 | default:
|
447 | clone.hours(Math.round(clone.hours() / 12) * 12); break;
|
448 | }
|
449 | clone.minutes(0);
|
450 | clone.seconds(0);
|
451 | clone.milliseconds(0);
|
452 | }
|
453 | else if (scale == 'weekday') {
|
454 |
|
455 | switch (step) {
|
456 | case 5:
|
457 | case 2:
|
458 | clone.hours(Math.round(clone.hours() / 12) * 12); break;
|
459 | default:
|
460 | clone.hours(Math.round(clone.hours() / 6) * 6); break;
|
461 | }
|
462 | clone.minutes(0);
|
463 | clone.seconds(0);
|
464 | clone.milliseconds(0);
|
465 | }
|
466 | else if (scale == 'hour') {
|
467 | switch (step) {
|
468 | case 4:
|
469 | clone.minutes(Math.round(clone.minutes() / 60) * 60); break;
|
470 | default:
|
471 | clone.minutes(Math.round(clone.minutes() / 30) * 30); break;
|
472 | }
|
473 | clone.seconds(0);
|
474 | clone.milliseconds(0);
|
475 | } else if (scale == 'minute') {
|
476 |
|
477 | switch (step) {
|
478 | case 15:
|
479 | case 10:
|
480 | clone.minutes(Math.round(clone.minutes() / 5) * 5);
|
481 | clone.seconds(0);
|
482 | break;
|
483 | case 5:
|
484 | clone.seconds(Math.round(clone.seconds() / 60) * 60); break;
|
485 | default:
|
486 | clone.seconds(Math.round(clone.seconds() / 30) * 30); break;
|
487 | }
|
488 | clone.milliseconds(0);
|
489 | }
|
490 | else if (scale == 'second') {
|
491 |
|
492 | switch (step) {
|
493 | case 15:
|
494 | case 10:
|
495 | clone.seconds(Math.round(clone.seconds() / 5) * 5);
|
496 | clone.milliseconds(0);
|
497 | break;
|
498 | case 5:
|
499 | clone.milliseconds(Math.round(clone.milliseconds() / 1000) * 1000); break;
|
500 | default:
|
501 | clone.milliseconds(Math.round(clone.milliseconds() / 500) * 500); break;
|
502 | }
|
503 | }
|
504 | else if (scale == 'millisecond') {
|
505 | var _step = step > 5 ? step / 2 : 1;
|
506 | clone.milliseconds(Math.round(clone.milliseconds() / _step) * _step);
|
507 | }
|
508 |
|
509 | return clone;
|
510 | };
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 | TimeStep.prototype.isMajor = function() {
|
518 | if (this.switchedYear == true) {
|
519 | switch (this.scale) {
|
520 | case 'year':
|
521 | case 'quarter':
|
522 | case 'month':
|
523 | case 'week':
|
524 | case 'weekday':
|
525 | case 'day':
|
526 | case 'hour':
|
527 | case 'minute':
|
528 | case 'second':
|
529 | case 'millisecond':
|
530 | return true;
|
531 | default:
|
532 | return false;
|
533 | }
|
534 | }
|
535 | else if (this.switchedMonth == true) {
|
536 | switch (this.scale) {
|
537 | case 'week':
|
538 | case 'weekday':
|
539 | case 'day':
|
540 | case 'hour':
|
541 | case 'minute':
|
542 | case 'second':
|
543 | case 'millisecond':
|
544 | return true;
|
545 | default:
|
546 | return false;
|
547 | }
|
548 | }
|
549 | else if (this.switchedDay == true) {
|
550 | switch (this.scale) {
|
551 | case 'millisecond':
|
552 | case 'second':
|
553 | case 'minute':
|
554 | case 'hour':
|
555 | return true;
|
556 | default:
|
557 | return false;
|
558 | }
|
559 | }
|
560 |
|
561 | var date = this.moment(this.current);
|
562 | switch (this.scale) {
|
563 | case 'millisecond':
|
564 | return (date.milliseconds() == 0);
|
565 | case 'second':
|
566 | return (date.seconds() == 0);
|
567 | case 'minute':
|
568 | return (date.hours() == 0) && (date.minutes() == 0);
|
569 | case 'hour':
|
570 | return (date.hours() == 0);
|
571 | case 'weekday':
|
572 | case 'day':
|
573 | return (date.date() == 1);
|
574 | case 'week':
|
575 | return (date.date() == 1);
|
576 | case 'month':
|
577 | return (date.month() == 0);
|
578 | case 'quarter':
|
579 | return (date.quarter() == 1);
|
580 | case 'year':
|
581 | return false;
|
582 | default:
|
583 | return false;
|
584 | }
|
585 | };
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 | TimeStep.prototype.getLabelMinor = function(date) {
|
596 | if (date == undefined) {
|
597 | date = this.current;
|
598 | }
|
599 | if (date instanceof Date) {
|
600 | date = this.moment(date)
|
601 | }
|
602 |
|
603 | if (typeof(this.format.minorLabels) === "function") {
|
604 | return this.format.minorLabels(date, this.scale, this.step);
|
605 | }
|
606 |
|
607 | var format = this.format.minorLabels[this.scale];
|
608 |
|
609 | switch (this.scale) {
|
610 | case 'week':
|
611 | if(this.isMajor() && date.weekday() !== 0){
|
612 | return "";
|
613 | }
|
614 | default:
|
615 | return (format && format.length > 0) ? this.moment(date).format(format) : '';
|
616 | }
|
617 | };
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 | TimeStep.prototype.getLabelMajor = function(date) {
|
627 | if (date == undefined) {
|
628 | date = this.current;
|
629 | }
|
630 | if (date instanceof Date) {
|
631 | date = this.moment(date)
|
632 | }
|
633 |
|
634 | if (typeof(this.format.majorLabels) === "function") {
|
635 | return this.format.majorLabels(date, this.scale, this.step);
|
636 | }
|
637 |
|
638 | var format = this.format.majorLabels[this.scale];
|
639 | return (format && format.length > 0) ? this.moment(date).format(format) : '';
|
640 | };
|
641 |
|
642 | TimeStep.prototype.getClassName = function() {
|
643 | var _moment = this.moment;
|
644 | var m = this.moment(this.current);
|
645 | var current = m.locale ? m.locale('en') : m.lang('en');
|
646 | var step = this.step;
|
647 | var classNames = [];
|
648 |
|
649 | |
650 |
|
651 |
|
652 |
|
653 |
|
654 | function even(value) {
|
655 | return (value / step % 2 == 0) ? ' vis-even' : ' vis-odd';
|
656 | }
|
657 |
|
658 | |
659 |
|
660 |
|
661 |
|
662 |
|
663 | function today(date) {
|
664 | if (date.isSame(new Date(), 'day')) {
|
665 | return ' vis-today';
|
666 | }
|
667 | if (date.isSame(_moment().add(1, 'day'), 'day')) {
|
668 | return ' vis-tomorrow';
|
669 | }
|
670 | if (date.isSame(_moment().add(-1, 'day'), 'day')) {
|
671 | return ' vis-yesterday';
|
672 | }
|
673 | return '';
|
674 | }
|
675 |
|
676 | |
677 |
|
678 |
|
679 |
|
680 |
|
681 | function currentWeek(date) {
|
682 | return date.isSame(new Date(), 'week') ? ' vis-current-week' : '';
|
683 | }
|
684 |
|
685 | |
686 |
|
687 |
|
688 |
|
689 |
|
690 | function currentMonth(date) {
|
691 | return date.isSame(new Date(), 'month') ? ' vis-current-month' : '';
|
692 | }
|
693 |
|
694 | |
695 |
|
696 |
|
697 |
|
698 |
|
699 | function currentQuarter(date) {
|
700 | return date.isSame(new Date(), 'quarter') ? ' vis-current-quarter' : '';
|
701 | }
|
702 |
|
703 | |
704 |
|
705 |
|
706 |
|
707 |
|
708 | function currentYear(date) {
|
709 | return date.isSame(new Date(), 'year') ? ' vis-current-year' : '';
|
710 | }
|
711 |
|
712 | switch (this.scale) {
|
713 | case 'millisecond':
|
714 | classNames.push(today(current));
|
715 | classNames.push(even(current.milliseconds()));
|
716 | break;
|
717 | case 'second':
|
718 | classNames.push(today(current));
|
719 | classNames.push(even(current.seconds()));
|
720 | break;
|
721 | case 'minute':
|
722 | classNames.push(today(current));
|
723 | classNames.push(even(current.minutes()));
|
724 | break;
|
725 | case 'hour':
|
726 | classNames.push('vis-h' + current.hours() + (this.step == 4 ? '-h' + (current.hours() + 4) : ''));
|
727 | classNames.push(today(current));
|
728 | classNames.push(even(current.hours()));
|
729 | break;
|
730 | case 'weekday':
|
731 | classNames.push('vis-' + current.format('dddd').toLowerCase());
|
732 | classNames.push(today(current));
|
733 | classNames.push(currentWeek(current));
|
734 | classNames.push(even(current.date()));
|
735 | break;
|
736 | case 'day':
|
737 | classNames.push('vis-day' + current.date());
|
738 | classNames.push('vis-' + current.format('MMMM').toLowerCase());
|
739 | classNames.push(today(current));
|
740 | classNames.push(currentMonth(current));
|
741 | classNames.push(this.step <= 2 ? today(current) : '');
|
742 | classNames.push(this.step <= 2 ? 'vis-' + current.format('dddd').toLowerCase() : '');
|
743 | classNames.push(even(current.date() - 1));
|
744 | break;
|
745 | case 'week':
|
746 | classNames.push('vis-week' + current.format('w'));
|
747 | classNames.push(currentWeek(current));
|
748 | classNames.push(even(current.week()));
|
749 | break;
|
750 | case 'month':
|
751 | classNames.push('vis-' + current.format('MMMM').toLowerCase());
|
752 | classNames.push(currentMonth(current));
|
753 | classNames.push(even(current.month()));
|
754 | break;
|
755 | case 'quarter':
|
756 | classNames.push('vis-q' + current.quarter());
|
757 | classNames.push(currentQuarter(current));
|
758 | classNames.push(even(current.quarter()));
|
759 | break;
|
760 | case 'year':
|
761 | classNames.push('vis-year' + current.year());
|
762 | classNames.push(currentYear(current));
|
763 | classNames.push(even(current.year()));
|
764 | break;
|
765 | }
|
766 | return classNames.filter(String).join(" ");
|
767 | };
|
768 |
|
769 | module.exports = TimeStep;
|