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

Method fromString

packages/graph/src/TemporalTypes.ts:742–792  ·  view source on GitHub ↗

* Create a DateTimeValue from an ISO datetime string with timezone. * Format: YYYY-MM-DDTHH:MM:SS.nnnnnnnnn+HH:MM or YYYY-MM-DDTHH:MM:SS.nnnnnnnnn[TZ]

(iso: string)

Source from the content-addressed store, hash-verified

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);
761 }
762
763 // Parse timezone offset
764 let offsetSeconds = 0;
765 if (match[8] === "Z") {
766 offsetSeconds = 0;
767 } else if (match[9] && match[10] && match[11]) {
768 const sign = match[9] === "+" ? 1 : -1;
769 const offsetHours = parseInt(match[10], 10);
770 const offsetMins = parseInt(match[11], 10);
771 offsetSeconds = sign * (offsetHours * 3600 + offsetMins * 60);
772 }
773
774 // Named timezone
775 const timezone = match[12] || null;
776
777 // If we have a named timezone but no offset, try to compute offset
778 // For now, just store the timezone name without computing offset
779 // A full implementation would use a timezone database
780
781 return new DateTimeValue(
782 year,
783 month,
784 day,
785 hour,
786 minute,
787 second,
788 nanosecond,
789 offsetSeconds,
790 timezone,
791 );
792 }
793
794 /**
795 * Create a DateTimeValue from a map of components.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected