TimeSpan
TimeSpan represents a time interval compatible with .NET System.TimeSpan string formatting.
Parsing
Section titled “Parsing”Use TimeSpan.parse() to parse C#-compatible values in the format [-][d.]hh:mm:ss[.fffffff].
import { TimeSpan } from '@cratis/fundamentals';
const span = TimeSpan.parse('1.02:30:15.25');
console.log(span.days); // 1console.log(span.hours); // 2console.log(span.minutes); // 30console.log(span.seconds); // 15Formatting
Section titled “Formatting”Use toString() to produce a C#-compatible TimeSpan string.
import { TimeSpan } from '@cratis/fundamentals';
const span = TimeSpan.parse('00:05:30');console.log(span.toString()); // "00:05:30"JSON Serialization
Section titled “JSON Serialization”TimeSpan.toJSON() returns the same C#-compatible representation as toString(), so JSON payloads round-trip cleanly between frontend and backend.
import { TimeSpan } from '@cratis/fundamentals';
const span = TimeSpan.parse('00:00:01.5');const json = JSON.stringify({ duration: span });Available Values
Section titled “Available Values”A parsed TimeSpan provides component and aggregate values, including:
ticksdays,hours,minutes,secondsmilliseconds,microseconds,nanosecondstotalDays,totalHours,totalMinutes,totalSecondstotalMilliseconds,totalMicroseconds,totalNanoseconds