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

Class LocalDateTimeValue

packages/graph/src/TemporalTypes.ts:493–692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491 * - hour, minute, second, millisecond, microsecond, nanosecond (from LocalTimeValue)
492 */
493export class LocalDateTimeValue implements TemporalValue {
494 public readonly temporalType = "localdatetime";
495
496 #year: number;
497 #month: number;
498 #day: number;
499 #hour: number;
500 #minute: number;
501 #second: number;
502 #nanosecond: number;
503
504 public constructor(
505 year: number,
506 month: number,
507 day: number,
508 hour: number = 0,
509 minute: number = 0,
510 second: number = 0,
511 nanosecond: number = 0,
512 ) {
513 this.#year = year;
514 this.#month = month;
515 this.#day = day;
516 this.#hour = hour;
517 this.#minute = minute;
518 this.#second = second;
519 this.#nanosecond = nanosecond;
520 }
521
522 /**
523 * Create a LocalDateTimeValue from an ISO datetime string.
524 * Format: YYYY-MM-DDTHH:MM:SS.nnnnnnnnn
525 */
526 public static fromString(iso: string): LocalDateTimeValue | null {
527 const match = iso.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?$/);
528 if (!match || !match[1] || !match[2] || !match[3] || !match[4] || !match[5] || !match[6])
529 return null;
530
531 const year = parseInt(match[1], 10);
532 const month = parseInt(match[2], 10);
533 const day = parseInt(match[3], 10);
534 const hour = parseInt(match[4], 10);
535 const minute = parseInt(match[5], 10);
536 const second = parseInt(match[6], 10);
537
538 let nanosecond = 0;
539 if (match[7]) {
540 const frac = match[7].padEnd(9, "0");
541 nanosecond = parseInt(frac, 10);
542 }
543
544 return new LocalDateTimeValue(year, month, day, hour, minute, second, nanosecond);
545 }
546
547 /**
548 * Create a LocalDateTimeValue from a map of components.
549 */
550 public static fromMap(map: Record<string, unknown>): LocalDateTimeValue | null {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected