Datetime library #9

Open
opened 2025-12-13 17:36:25 -05:00 by Ghost · 1 comment
Ghost commented 2025-12-13 17:36:25 -05:00 (Migrated from codefloe.com)

A datetime library should be modelled after Jiff or Temporal.

Fast algorithm for date conversion: https://www.benjoffe.com/fast-date-64

A datetime library should be modelled after [Jiff](https://github.com/burntsushi/jiff) or [Temporal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal). Fast algorithm for date conversion: https://www.benjoffe.com/fast-date-64
Ghost commented 2025-12-13 17:36:56 -05:00 (Migrated from codefloe.com)

Optimised leap year check:

https://hueffner.de/falk/blog/a-leap-year-check-in-three-instructions.html

I'm not sure if this is worth doing, simply because of how complicated it is. I want the code in the standard library to be mostly readable. But I'm leaving it here as an idea if I end up implementing it for performance anyway.

bool is_leap_year_fast(uint32_t y) {
    return ((y * 1073750999) & 3221352463) <= 126976;
}
Optimised leap year check: https://hueffner.de/falk/blog/a-leap-year-check-in-three-instructions.html I'm not sure if this is worth doing, simply because of how complicated it is. I want the code in the standard library to be mostly readable. But I'm leaving it here as an idea if I end up implementing it for performance anyway. ```c bool is_leap_year_fast(uint32_t y) { return ((y * 1073750999) & 3221352463) <= 126976; } ```
Sign in to join this conversation.
No labels
stdlib
syntax
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nclang/design#9
No description provided.