|
|
@ -1,4 +1,4 @@ |
|
|
|
import { TIMEZONE_UTC_OFFSET } from '../config'; |
|
|
|
import { HASTIC_TIMEZONE_OFFSET } from '../config'; |
|
|
|
|
|
|
|
|
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as moment from 'moment'; |
|
|
|
import * as moment from 'moment'; |
|
|
@ -11,7 +11,7 @@ export function parseTimeZone(timeZone: string): number { |
|
|
|
const re = /^-?\d{1,2}?:\d{2}$/; |
|
|
|
const re = /^-?\d{1,2}?:\d{2}$/; |
|
|
|
const correctFormat = re.test(timeZone); |
|
|
|
const correctFormat = re.test(timeZone); |
|
|
|
if(!correctFormat) { |
|
|
|
if(!correctFormat) { |
|
|
|
throw new Error(`Wrong timeZone format in config - "TIMEZONE_UTC_OFFSET": ${timeZone}`); |
|
|
|
throw new Error(`Wrong timeZone format in config - "HASTIC_TIMEZONE_OFFSET": ${timeZone}`); |
|
|
|
} |
|
|
|
} |
|
|
|
const time = _.split(timeZone, ':'); |
|
|
|
const time = _.split(timeZone, ':'); |
|
|
|
let minutesOffset = Math.abs(Number(time[0])) * MINUTES_IN_HOUR + Number(time[1]); |
|
|
|
let minutesOffset = Math.abs(Number(time[0])) * MINUTES_IN_HOUR + Number(time[1]); |
|
|
@ -23,7 +23,7 @@ export function parseTimeZone(timeZone: string): number { |
|
|
|
|
|
|
|
|
|
|
|
export function toTimeZone(time: moment.MomentInput): string { |
|
|
|
export function toTimeZone(time: moment.MomentInput): string { |
|
|
|
const utcTime = moment(time).utc(); |
|
|
|
const utcTime = moment(time).utc(); |
|
|
|
const timeWithOffset = utcTime.utcOffset(TIMEZONE_UTC_OFFSET); |
|
|
|
const timeWithOffset = utcTime.utcOffset(HASTIC_TIMEZONE_OFFSET); |
|
|
|
return timeWithOffset.format(TIME_FORMAT); |
|
|
|
return timeWithOffset.format(TIME_FORMAT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|