Skip to content
DateTimeCompare

DateTimeCompare

Description

Order two instants on the absolute (UTC) timeline, regardless of each one’s utc_offset_seconds.

Success

Returns -1 if a precedes b, +1 if it follows, 0 if they are the same instant.

Failure

Cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    i32 DateTimeCompare(DateTime a, DateTime b) {
        u64 ua = DateTimeToUnixNs(a);
        u64 ub = DateTimeToUnixNs(b);
        // Same instant rendered in two zones compares equal.
        DateTime c = DateTimeFromUnixNs(T_2021 * NS_PER_SEC, IST);
        return DateTimeCompare(a, b) == -1 && DateTimeCompare(b, a) == 1 && DateTimeCompare(a, c) == 0;
    }
        StrReadFmt(p, "{}", b);
    
        bool ok = DateTimeCompare(a, b) == 0 && b.utc_offset_seconds == MST && b.nanosecond == 123456789u &&
                  b.year == a.year && b.month == a.month && b.day == a.day && b.hour == a.hour;
        StrDeinit(&s);
Last updated on