MCPcopy Index your code
hub / github.com/adobe/react-spectrum / offsetToString

Function offsetToString

packages/@internationalized/date/src/string.ts:237–249  ·  view source on GitHub ↗
(offset: number)

Source from the content-addressed store, hash-verified

235}
236
237function offsetToString(offset: number) {
238 let sign = Math.sign(offset) < 0 ? '-' : '+';
239 offset = Math.abs(offset);
240 let offsetHours = Math.floor(offset / (60 * 60 * 1000));
241 let offsetMinutes = Math.floor((offset % (60 * 60 * 1000)) / (60 * 1000));
242 let offsetSeconds = Math.floor(((offset % (60 * 60 * 1000)) % (60 * 1000)) / 1000);
243 let stringOffset = `${sign}${String(offsetHours).padStart(2, '0')}:${String(offsetMinutes).padStart(2, '0')}`;
244 if (offsetSeconds !== 0) {
245 stringOffset += `:${String(offsetSeconds).padStart(2, '0')}`;
246 }
247
248 return stringOffset;
249}
250
251export function zonedDateTimeToString(date: ZonedDateTime): string {
252 return `${dateTimeToString(date)}${offsetToString(date.offset)}[${date.timeZone}]`;

Callers 2

parseZonedDateTimeFunction · 0.85
zonedDateTimeToStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected