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

Method constructor

pkgs/tz/src/date/mini.js:31–73  ·  view source on GitHub ↗
(...args)

Source from the content-addressed store, hash-verified

29 //#region static
30
31 constructor(...args) {
32 super();
33
34 // Time zone string is always the last string argument unless date string
35 // is passed (as a single argument).
36 if (args.length > 1 && typeof args[args.length - 1] === "string") {
37 this.timeZone = args.pop();
38 }
39
40 this.internal = new Date();
41
42 // Validate the time zone by checking its offset.
43 if (isNaN(tzOffset(this.timeZone, this))) {
44 this.setTime(NaN);
45 } else {
46 if (!args.length) {
47 // No arguments passed: use current time
48 this.setTime(Date.now());
49 } else if (
50 typeof args[0] === "number" &&
51 (args.length === 1 ||
52 (args.length === 2 && typeof args[1] !== "number"))
53 ) {
54 // Timestamp passed: use it as is
55 this.setTime(args[0]);
56 } else if (typeof args[0] === "string") {
57 // `Date` string passed: parse it as external date
58 this.setTime(+new Date(args[0]));
59 } else if (args[0] instanceof Date) {
60 // `Date` passed: use its timestamp
61 this.setTime(+args[0]);
62 } else {
63 // `Date` values passed:
64
65 // Set it as external date.
66 this.setTime(+new Date(...args));
67
68 // Adjust internal and external dates considering that we might have
69 // landed on the DST hour.
70 adjustToSystemTZ(this, args);
71 }
72 }
73 }
74
75 static tz(tz, ...args) {
76 return args.length

Callers

nothing calls this directly

Calls 3

setTimeMethod · 0.95
tzOffsetFunction · 0.90
adjustToSystemTZFunction · 0.85

Tested by

no test coverage detected