1 | /*
|
2 | * Licensed under the Apache License, Version 2.0 (the "License");
|
3 | * you may not use this file except in compliance with the License.
|
4 | * You may obtain a copy of the License at
|
5 | *
|
6 | * http://www.apache.org/licenses/LICENSE-2.0
|
7 | *
|
8 | * Unless required by applicable law or agreed to in writing, software
|
9 | * distributed under the License is distributed on an "AS IS" BASIS,
|
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11 | * See the License for the specific language governing permissions and
|
12 | * limitations under the License.
|
13 | */
|
14 |
|
15 | ;
|
16 |
|
17 | var dayjs = require('dayjs');
|
18 | var utc = require('dayjs/plugin/utc');
|
19 | dayjs.extend(utc);
|
20 |
|
21 | /**
|
22 | * Ensures there is a proper current time
|
23 | *
|
24 | * @param {string} currentTime - the definition of 'now'
|
25 | * @returns {object} if valid, the dayjs object for the current time
|
26 | */
|
27 | function setCurrentTime(currentTime) {
|
28 | if (!currentTime) {
|
29 | // Defaults to current local time
|
30 | return dayjs.utc();
|
31 | }
|
32 | try {
|
33 | return dayjs.utc(currentTime);
|
34 | } catch (err) {
|
35 | throw new Error("".concat(currentTime, " is not a valid date and time: ").concat(err.message));
|
36 | }
|
37 | }
|
38 | module.exports = {
|
39 | setCurrentTime
|
40 | }; |
\ | No newline at end of file |