MCPcopy
hub / github.com/date-fns/date-fns / generateOffset

Function generateOffset

pkgs/core/src/_lib/test/index.ts:21–39  ·  view source on GitHub ↗
(originalDate: Date)

Source from the content-addressed store, hash-verified

19
20// This makes sure we create the consistent offsets across timezones, no matter where these tests are ran.
21export function generateOffset(originalDate: Date) {
22 // Add the timezone.
23 let offset = "";
24 const tzOffset = originalDate.getTimezoneOffset();
25
26 if (tzOffset !== 0) {
27 const absoluteOffset = Math.abs(tzOffset);
28 const hourOffset = addLeadingZeros(Math.trunc(absoluteOffset / 60), 2);
29 const minuteOffset = addLeadingZeros(absoluteOffset % 60, 2);
30 // If less than 0, the sign is +, because it is ahead of time.
31 const sign = tzOffset < 0 ? "+" : "-";
32
33 offset = `${sign}${hourOffset}:${minuteOffset}`;
34 } else {
35 offset = "Z";
36 }
37
38 return offset;
39}
40
41export function fakeDate(date: number | Date) {
42 function fakeNow(date: number | Date) {

Callers 2

test.tsFile · 0.90
test.tsFile · 0.90

Calls 2

addLeadingZerosFunction · 0.90
getTimezoneOffsetMethod · 0.45

Tested by

no test coverage detected