MCPcopy Create free account
hub / github.com/codemix/graph / DateValue

Class DateValue

packages/graph/src/TemporalTypes.ts:44–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 * - ordinalDay: Day of year (1-366)
43 */
44export class DateValue implements TemporalValue {
45 public readonly temporalType = "date";
46
47 #year: number;
48 #month: number;
49 #day: number;
50
51 public constructor(year: number, month: number, day: number) {
52 this.#year = year;
53 this.#month = month;
54 this.#day = day;
55 }
56
57 /**
58 * Create a DateValue from an ISO date string (YYYY-MM-DD).
59 */
60 public static fromString(iso: string): DateValue | null {
61 const match = iso.match(/^(\d{4})-(\d{2})-(\d{2})$/);
62 if (!match || !match[1] || !match[2] || !match[3]) return null;
63 const year = parseInt(match[1], 10);
64 const month = parseInt(match[2], 10);
65 const day = parseInt(match[3], 10);
66 return new DateValue(year, month, day);
67 }
68
69 /**
70 * Create a DateValue from a map of components.
71 */
72 public static fromMap(map: Record<string, unknown>): DateValue | null {
73 const year = map.year;
74 const month = map.month;
75 const day = map.day;
76 if (typeof year !== "number" || typeof month !== "number" || typeof day !== "number") {
77 return null;
78 }
79 return new DateValue(year, month, day);
80 }
81
82 public get year(): number {
83 return this.#year;
84 }
85
86 public get month(): number {
87 return this.#month;
88 }
89
90 public get day(): number {
91 return this.#day;
92 }
93
94 /**
95 * Get the ISO week number (1-53).
96 * Uses the ISO 8601 definition where week 1 is the week containing January 4th.
97 */
98 public get week(): number {
99 const date = new Date(Date.UTC(this.#year, this.#month - 1, this.#day));
100 // Set to nearest Thursday: current date + 4 - current day number (making Sunday=7)
101 const dayNum = date.getUTCDay() || 7;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected