Skip to content
TzifOffsetFromBuf

TzifOffsetFromBuf

Description

Resolve the local UTC offset in effect at unix_seconds from an in-memory TZif image (data, len bytes) – the parse core behind TzifLocalOffsetSeconds, exposed for callers that already hold the bytes (and for tests that feed synthetic images).

Parameters

Name Direction Description
data in TZif v1/v2+ image bytes.
len in Byte length of data.
unix_seconds in Instant to resolve (seconds since Unix epoch).
out_offset_seconds out Receives the offset on success; untouched on failure.

Success

Returns true; *out_offset_seconds holds the resolved offset (seconds east of UTC).

Failure

Returns false (and leaves the output untouched) on a NULL argument or a malformed / truncated TZif image. Logs via LOG_ERROR; never aborts on bad data.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool TzifOffsetFromBuf(const u8 *data, size len, i64 unix_seconds, i32 *out_offset_seconds) {
        if (!data || !out_offset_seconds)
            return false;
            return false;
        }
        bool ok = TzifOffsetFromBuf(BufData(&data), BufLength(&data), unix_seconds, out_offset_seconds);
        BufDeinit(&data);
        return ok;
    
    static bool resolve(Buf *b, i64 t, i32 *off) {
        return TzifOffsetFromBuf(BufData(b), BufLength(b), t, off);
    }
        u8  junk[44] = {'X', 'Z', 'i', 'f'};
        i32 off      = 12345;
        return !TzifOffsetFromBuf(junk, sizeof(junk), 0, &off) && off == 12345;
    }
        u8  tiny[10] = {'T', 'Z', 'i', 'f', 0};
        i32 off      = 999;
        return !TzifOffsetFromBuf(tiny, sizeof(tiny), 0, &off) && off == 999;
    }
Last updated on