MCPcopy Create free account
hub / github.com/adobe/react-spectrum / fromAbsolute

Function fromAbsolute

packages/@internationalized/date/src/conversion.ts:226–249  ·  view source on GitHub ↗
(ms: number, timeZone: string)

Source from the content-addressed store, hash-verified

224 * Takes a Unix epoch (milliseconds since 1970) and converts it to the provided time zone.
225 */
226export function fromAbsolute(ms: number, timeZone: string): ZonedDateTime {
227 let offset = getTimeZoneOffset(ms, timeZone);
228 let date = new Date(ms + offset);
229 let year = date.getUTCFullYear();
230 let month = date.getUTCMonth() + 1;
231 let day = date.getUTCDate();
232 let hour = date.getUTCHours();
233 let minute = date.getUTCMinutes();
234 let second = date.getUTCSeconds();
235 let millisecond = date.getUTCMilliseconds();
236
237 return new ZonedDateTime(
238 year < 1 ? 'BC' : 'AD',
239 year < 1 ? -year + 1 : year,
240 month,
241 day,
242 timeZone,
243 offset,
244 hour,
245 minute,
246 second,
247 millisecond
248 );
249}
250
251/**
252 * Takes a `Date` object and converts it to the provided time zone.

Callers 10

addZonedFunction · 0.90
cycleZonedFunction · 0.90
setZonedFunction · 0.90
parseZonedDateTimeFunction · 0.90
nowFunction · 0.90
conversion.test.jsFile · 0.90
DateFieldExampleFunction · 0.90
fromDateFunction · 0.85
toZonedFunction · 0.85
toTimeZoneFunction · 0.85

Calls 1

getTimeZoneOffsetFunction · 0.85

Tested by

no test coverage detected