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

Class TimeValue

packages/graph/src/TemporalTypes.ts:321–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319 * - offsetMinutes: The timezone offset in minutes
320 */
321export class TimeValue implements TemporalValue {
322 public readonly temporalType = "time";
323
324 #hour: number;
325 #minute: number;
326 #second: number;
327 #nanosecond: number;
328 #offsetSeconds: number;
329
330 public constructor(
331 hour: number,
332 minute: number,
333 second: number,
334 nanosecond: number = 0,
335 offsetSeconds: number = 0,
336 ) {
337 this.#hour = hour;
338 this.#minute = minute;
339 this.#second = second;
340 this.#nanosecond = nanosecond;
341 this.#offsetSeconds = offsetSeconds;
342 }
343
344 /**
345 * Create a TimeValue from an ISO time string with timezone offset.
346 * Format: HH:MM:SS.nnnnnnnnn+HH:MM or HH:MM:SS.nnnnnnnnnZ
347 */
348 public static fromString(iso: string): TimeValue | null {
349 // Match time with timezone: HH:MM:SS.frac+HH:MM or Z
350 const match = iso.match(/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))$/);
351 if (!match || !match[1] || !match[2] || !match[3]) return null;
352
353 const hour = parseInt(match[1], 10);
354 const minute = parseInt(match[2], 10);
355 const second = parseInt(match[3], 10);
356
357 // Parse fractional seconds as nanoseconds
358 let nanosecond = 0;
359 if (match[4]) {
360 const frac = match[4].padEnd(9, "0");
361 nanosecond = parseInt(frac, 10);
362 }
363
364 // Parse timezone offset
365 let offsetSeconds = 0;
366 if (match[5] !== "Z" && match[6] && match[7] && match[8]) {
367 const sign = match[6] === "+" ? 1 : -1;
368 const offsetHours = parseInt(match[7], 10);
369 const offsetMins = parseInt(match[8], 10);
370 offsetSeconds = sign * (offsetHours * 3600 + offsetMins * 60);
371 }
372
373 return new TimeValue(hour, minute, second, nanosecond, offsetSeconds);
374 }
375
376 /**
377 * Create a TimeValue from a map of components.
378 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected