7 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
Ben Joffe introduces a new date conversion algorithm that only requires four multiplications, significantly improving speed over previous methods. The algorithm can accurately process time over ±1.89 trillion years and is available as open source in multiple programming languages.
If you do, here's more
Ben Joffe introduces a fast date conversion algorithm that cuts the number of multiplications needed from seven or more to just four. This change significantly speeds up the calculation, matching the performance gains seen in the previous fastest algorithm, Neri-Schneider (2021). The algorithm can accurately process UNIX 64-bit time over a span of ±1.89 trillion years and has been released as free open-source software under the BSL-1.0 license. Implementations are available in multiple programming languages, including Rust, Go, and Zig.
The algorithm features three key innovations. First, it calculates years backwards, which simplifies the process by removing intermediate steps. Second, it eliminates the need for a specific calculation of the day of the year, instead using a year-modulus-bitshift technique to reduce dependencies. Third, it incorporates the "Julian Map" technique from Joffe's earlier work, refining the computation of leap years, particularly the 100 and 400-year rules. The performance of this new algorithm is demonstrated through benchmarks on Intel x64 and Apple M4 Pro processors, showing a substantial reduction in CPU cycles required compared to previous algorithms.
The article also includes a detailed pseudocode representation of the algorithm and an explanation of its components. Joffe emphasizes the efficiency gains achieved by counting years backwards, which allows for merging certain calculations and eliminating unnecessary terms. By starting from a leap year, the algorithm avoids complications that arise in traditional forward-counting methods. This approach not only enhances speed but also maintains accuracy, making it a valuable tool for developers needing efficient date calculations in their applications.
Questions about this article
No questions yet.