Skip to content

DateTimeAddNs

Description

Advance an instant by delta_ns nanoseconds (negative to rewind), preserving its utc_offset_seconds in the result.

Success

Returns the shifted DateTime.

Failure

Cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    DateTime DateTimeAddNs(DateTime dt, i64 delta_ns) {
        u64 base = DateTimeToUnixNs(dt);
        return DateTimeFromUnixNs((u64)((i64)base + delta_ns), dt.utc_offset_seconds);
    static bool test_add(void) {
        DateTime a = DateTimeFromUnixNs(T_2021 * NS_PER_SEC, IST);
        DateTime b = DateTimeAddNs(a, 86400ll * (i64)NS_PER_SEC); // +1 day
        return b.day == 2 && b.month == 1 && b.year == 2021 && b.utc_offset_seconds == IST &&
               DateTimeDiffNs(b, a) == 86400ll * (i64)NS_PER_SEC;
Last updated on