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

Class DateTimeValue

packages/graph/src/TemporalTypes.ts:703–1032  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701 * - timezone: The timezone name (if provided)
702 */
703export class DateTimeValue implements TemporalValue {
704 public readonly temporalType = "datetime";
705
706 #year: number;
707 #month: number;
708 #day: number;
709 #hour: number;
710 #minute: number;
711 #second: number;
712 #nanosecond: number;
713 #offsetSeconds: number;
714 #timezone: string | null;
715
716 public constructor(
717 year: number,
718 month: number,
719 day: number,
720 hour: number = 0,
721 minute: number = 0,
722 second: number = 0,
723 nanosecond: number = 0,
724 offsetSeconds: number = 0,
725 timezone: string | null = null,
726 ) {
727 this.#year = year;
728 this.#month = month;
729 this.#day = day;
730 this.#hour = hour;
731 this.#minute = minute;
732 this.#second = second;
733 this.#nanosecond = nanosecond;
734 this.#offsetSeconds = offsetSeconds;
735 this.#timezone = timezone;
736 }
737
738 /**
739 * Create a DateTimeValue from an ISO datetime string with timezone.
740 * Format: YYYY-MM-DDTHH:MM:SS.nnnnnnnnn+HH:MM or YYYY-MM-DDTHH:MM:SS.nnnnnnnnn[TZ]
741 */
742 public static fromString(iso: string): DateTimeValue | null {
743 // Match datetime with timezone offset or named timezone
744 const match = iso.match(
745 /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))?(?:\[([^\]]+)\])?$/,
746 );
747 if (!match || !match[1] || !match[2] || !match[3] || !match[4] || !match[5] || !match[6])
748 return null;
749
750 const year = parseInt(match[1], 10);
751 const month = parseInt(match[2], 10);
752 const day = parseInt(match[3], 10);
753 const hour = parseInt(match[4], 10);
754 const minute = parseInt(match[5], 10);
755 const second = parseInt(match[6], 10);
756
757 let nanosecond = 0;
758 if (match[7]) {
759 const frac = match[7].padEnd(9, "0");
760 nanosecond = parseInt(frac, 10);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected