* Create a TimeValue from an ISO time string with timezone offset. * Format: HH:MM:SS.nnnnnnnnn+HH:MM or HH:MM:SS.nnnnnnnnnZ
(iso: string)
| 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. |
nothing calls this directly
no outgoing calls
no test coverage detected