1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | 'use strict';
|
16 |
|
17 | const dayjs = require('dayjs');
|
18 | const utc = require('dayjs/plugin/utc');
|
19 | dayjs.extend(utc);
|
20 | const quarterOfYear = require('dayjs/plugin/quarterOfYear');
|
21 | dayjs.extend(quarterOfYear);
|
22 | const minMax = require('dayjs/plugin/minMax');
|
23 | dayjs.extend(minMax);
|
24 | const duration = require('dayjs/plugin/duration');
|
25 | dayjs.extend(duration);
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function setCurrentTime(currentTime, utcOffset) {
|
35 |
|
36 | const utcOffsetResolved = typeof utcOffset === 'number' ? utcOffset : dayjs().utcOffset();
|
37 | const currentTimeUTC = currentTime ? dayjs.utc(currentTime) : dayjs().utc();
|
38 | const currentTimeResolved = currentTimeUTC.utcOffset(utcOffsetResolved);
|
39 | if (!currentTimeResolved.isValid()) {
|
40 | throw new Error(`Cannot set current time to '${currentTime}' with UTC offset '${utcOffset}'`);
|
41 | }
|
42 | return {
|
43 | currentTime: currentTimeResolved,
|
44 | utcOffset: utcOffsetResolved
|
45 | };
|
46 | }
|
47 |
|
48 | module.exports = { setCurrentTime };
|