MCPcopy
hub / github.com/valor-software/ngx-bootstrap / cloneWithOffset

Function cloneWithOffset

src/chronos/units/offset.ts:66–82  ·  view source on GitHub ↗
(input: Date, date: Date,
                                config: DateParsingConfig = {})

Source from the content-addressed store, hash-verified

64
65// Return a moment from input, that is local/utc/zone equivalent to model.
66export function cloneWithOffset(input: Date, date: Date,
67 config: DateParsingConfig = {}): Date {
68 if (!config._isUTC) {
69 return input;
70 }
71
72 const res = cloneDate(date);
73 // todo: input._d - res._d + ((res._offset || 0) - (input._offset || 0))*60000
74 const offsetDiff = (config._offset || 0) * 60000;
75 const diff = input.valueOf() - res.valueOf() + offsetDiff;
76 // Use low-level api, because this fn is low-level api.
77 res.setTime(res.valueOf() + diff);
78 // todo: add timezone handling
79 // hooks.updateOffset(res, false);
80
81 return res;
82}
83
84export function getDateOffset(date: Date): number {
85 // On Firefox.24 Date#getTimezoneOffset returns a floating point.

Callers 3

momentsDifferenceFunction · 0.90
diffFunction · 0.90
calendarFunction · 0.90

Calls 3

cloneDateFunction · 0.90
setTimeMethod · 0.80
valueOfMethod · 0.45

Tested by

no test coverage detected