Skip to content

Proposal: DateTime in std.time #8396

@tau-dev

Description

@tau-dev

It could be very useful to have something like:

// Strictly Gregorian
const DateTime = struct {
    sec: u6, // [0, 60]
    min: u6, // [0, 59]
    hour: u5, // [0, 23] 
    year_day: u9, // [1, 366]
    year: i16, // C.E.

    pub fn monthDay(date: Self) u5; // [1, 31]
    pub fn month(date: Self) u4; // [1, 12]
    pub fn weekDay(date: Self) u8; // [0, 6]
    pub fn week(date: Self) u6; // [1, 54]
    pub fn isLeapYear(date: Self) bool;

    /// utc_offset is in minutes.
    pub fn fromEpoch(epoch: i64, utc_offset: i16) Self;
    pub fn toEpoch(date: Self, utc_offset: i16) i64;
};

// Posix Epoch repeats on leap seconds, International Atomic Time is useful for strictly monotonic time stamps.
// As far as I understood https://techcommunity.microsoft.com/t5/networking-blog/leap-seconds-for-the-appdev-what-you-should-know/ba-p/339813, 
// it seems like Windows' GetSystemTimeAsFileTime follows IAC.
pub fn epochToAtomicTime(epoch: i64, leap_seconds: []const i64) i64;
pub fn atomicTimeToEpoch(atomic: i64, leap_seconds: []const i64) i64;

Maybe also with a more elegant way to format it than passing the fields seperately to fmt.format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions