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

Class LocalTimeValue

packages/graph/src/TemporalTypes.ts:194–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192 * - nanosecond: Nanoseconds (0-999999999)
193 */
194export class LocalTimeValue implements TemporalValue {
195 public readonly temporalType = "localtime";
196
197 #hour: number;
198 #minute: number;
199 #second: number;
200 #nanosecond: number;
201
202 public constructor(hour: number, minute: number, second: number, nanosecond: number = 0) {
203 this.#hour = hour;
204 this.#minute = minute;
205 this.#second = second;
206 this.#nanosecond = nanosecond;
207 }
208
209 /**
210 * Create a LocalTimeValue from an ISO time string (HH:MM:SS.nnnnnnnnn).
211 */
212 public static fromString(iso: string): LocalTimeValue | null {
213 // Match time format: HH:MM:SS or HH:MM:SS.fractional
214 const match = iso.match(/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?$/);
215 if (!match || !match[1] || !match[2] || !match[3]) return null;
216
217 const hour = parseInt(match[1], 10);
218 const minute = parseInt(match[2], 10);
219 const second = parseInt(match[3], 10);
220
221 // Parse fractional seconds as nanoseconds
222 let nanosecond = 0;
223 if (match[4]) {
224 // Pad to 9 digits
225 const frac = match[4].padEnd(9, "0");
226 nanosecond = parseInt(frac, 10);
227 }
228
229 return new LocalTimeValue(hour, minute, second, nanosecond);
230 }
231
232 /**
233 * Create a LocalTimeValue from a map of components.
234 */
235 public static fromMap(map: Record<string, unknown>): LocalTimeValue | null {
236 const hour = typeof map.hour === "number" ? map.hour : 0;
237 const minute = typeof map.minute === "number" ? map.minute : 0;
238 const second = typeof map.second === "number" ? map.second : 0;
239 const nanosecond = typeof map.nanosecond === "number" ? map.nanosecond : 0;
240
241 return new LocalTimeValue(hour, minute, second, nanosecond);
242 }
243
244 public get hour(): number {
245 return this.#hour;
246 }
247
248 public get minute(): number {
249 return this.#minute;
250 }
251

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected