Available

amalgame-datetime

Instant ns-UTC, Duration, Stopwatch, ISO 8601.

amc package add datetime GitHub ↗ ← Back to the ecosystem

Overview

Everything is UTC, to the nanosecond. Instant for points in time, Duration for intervals, Stopwatch to time code on the monotonic clock. ISO 8601 and HTTP-date (RFC 1123) format and parse. Local time and time zones are not there yet: they are planned.

Features

  • ✓Instant.Now(), Instant.Parse(s), Format(), Add, Since, IsBefore, IsAfter
  • ✓Duration in nanoseconds: FromMillis, FromSeconds, FromMinutes, FromHours, FromDays
  • ✓Monotonic Stopwatch for NTP-immune timings
  • ✓Sleep: DateTime.SleepMillis(ms), Duration.Sleep(); HTTP dates: FormatHttpDate, ParseHttpDate
  • ✓Written in Amalgame, except the clock reads

Example

Minimal usage example — copy-paste runnable after install.

amc package add datetime

import Amalgame.DateTime

class Program {
    public static void Main() {
        let sw = new Stopwatch()
        DateTime.SleepMillis(120)
        let took: Duration = sw.Elapsed()
        Console.WriteLine("took " + String_FromInt(took.Millis()) + " ms")

        let r: InstantResult = Instant.Parse("2026-05-24T10:30:00Z")
        if (r.Ok) {
            let later: Instant = r.Value.Add(Duration.FromHours(2))
            Console.WriteLine(later.Format())                 // 2026-05-24T12:30:00.000000000Z
            Console.WriteLine(later.Since(r.Value).Format())  // 2h0m0s
        }
    }
}

At a glance

Related packages