|
1 |
| -import moment, { Moment } from 'moment'; |
2 | 1 | import { TimeOption, TimeRange, TIME_FORMAT } from '../../types/time';
|
3 | 2 | import { describeTimeRange } from '../../utils/rangeutil';
|
4 | 3 | import * as dateMath from '../../utils/datemath';
|
| 4 | +import { dateTime, DateTime, toUtc } from '../../utils/moment_wrapper'; |
5 | 5 |
|
6 | 6 | export const mapTimeOptionToTimeRange = (
|
7 | 7 | timeOption: TimeOption,
|
8 | 8 | isTimezoneUtc: boolean,
|
9 | 9 | timezone?: dateMath.Timezone
|
10 | 10 | ): TimeRange => {
|
11 |
| - const fromMoment = stringToMoment(timeOption.from, isTimezoneUtc, false, timezone); |
12 |
| - const toMoment = stringToMoment(timeOption.to, isTimezoneUtc, true, timezone); |
| 11 | + const fromMoment = stringToDateTimeType(timeOption.from, isTimezoneUtc, false, timezone); |
| 12 | + const toMoment = stringToDateTimeType(timeOption.to, isTimezoneUtc, true, timezone); |
13 | 13 |
|
14 | 14 | return { from: fromMoment, to: toMoment, raw: { from: timeOption.from, to: timeOption.to } };
|
15 | 15 | };
|
16 | 16 |
|
17 |
| -export const stringToMoment = ( |
| 17 | +export const stringToDateTimeType = ( |
18 | 18 | value: string,
|
19 | 19 | isTimezoneUtc: boolean,
|
20 | 20 | roundUp?: boolean,
|
21 | 21 | timezone?: dateMath.Timezone
|
22 |
| -): Moment => { |
| 22 | +): DateTime => { |
23 | 23 | if (value.indexOf('now') !== -1) {
|
24 | 24 | if (!dateMath.isValid(value)) {
|
25 |
| - return moment(); |
| 25 | + return dateTime(); |
26 | 26 | }
|
27 | 27 |
|
28 | 28 | const parsed = dateMath.parse(value, roundUp, timezone);
|
29 |
| - return parsed || moment(); |
| 29 | + return parsed || dateTime(); |
30 | 30 | }
|
31 | 31 |
|
32 | 32 | if (isTimezoneUtc) {
|
33 |
| - return moment.utc(value, TIME_FORMAT); |
| 33 | + return toUtc(value, TIME_FORMAT); |
34 | 34 | }
|
35 | 35 |
|
36 |
| - return moment(value, TIME_FORMAT); |
| 36 | + return dateTime(value, TIME_FORMAT); |
37 | 37 | };
|
38 | 38 |
|
39 | 39 | export const mapTimeRangeToRangeString = (timeRange: TimeRange): string => {
|
|
0 commit comments