Skip to content
TzifLocalOffsetSeconds

TzifLocalOffsetSeconds

Description

Resolve the host’s local UTC offset (seconds east of UTC, so IST is +19800) in effect at unix_seconds, by reading and parsing /etc/localtime.

Parameters

Name Direction Description
unix_seconds in Instant to resolve, in seconds since the Unix epoch (UTC).
out_offset_seconds out Receives the offset on success; untouched on failure.
alloc in Allocator backing the file read + transient parse tables. Fully released before return.

Success

Returns true; *out_offset_seconds holds the offset for the time type in effect at unix_seconds.

Failure

Returns false and leaves *out_offset_seconds unchanged when /etc/localtime is absent, unreadable, or not a valid TZif v1/v2+ stream. Logs via LOG_ERROR; never aborts on malformed file data.

Usage example (Cross-references)

Usage examples (Cross-references)
        DefaultAllocator alloc  = DefaultAllocatorInit();
        i32              offset = 0;
        bool             ok     = TzifLocalOffsetSeconds((i64)(ns / 1000000000ull), &offset, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        if (ok)
    }
    
    bool TzifLocalOffsetSeconds(i64 unix_seconds, i32 *out_offset_seconds, Allocator *alloc) {
        Buf data = BufInit(alloc);
        if (FileReadAndClose("/etc/localtime", &data) < 0) {
Last updated on