fix(ls): render actual UTC calendar dates in long format#2144
Open
a0preetham wants to merge 1 commit into
Open
fix(ls): render actual UTC calendar dates in long format#2144a0preetham wants to merge 1 commit into
a0preetham wants to merge 1 commit into
Conversation
ls -l computed the date column with hand-rolled "approximate" math: no leap years (1970 + days/365) and 30-day months (remaining/30 + 1). The error compounds ~1 day per 4 years plus up to ±5 days within a year — by 2026 a July 5 mtime rendered as 2026-07-20, and late-December dates overshot into the next year entirely (2026-12-31 -> 2027-01-14). Replace the arithmetic with chrono via time_compat::to_chrono_utc, the same conversion the date builtin already uses, keeping the long-iso output style (YYYY-MM-DD HH:MM). Tests pin exact rendering for a mid-year date, a leap day (2024-02-29, unrepresentable under the old math), and a year boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ls -lcomputes its date column with hand-rolled "approximate" calendar math:The error compounds ~1 day per 4 years (14 leap days since 1972) plus up to ±5 days within a year from the 30-day-month approximation. Today the drift is 15 days: a file touched on 2026-07-05 lists as
2026-07-20. Late-December dates overshoot into the next year entirely (2026-12-31renders as2027-01-14), and leap days are unrepresentable.Found while verifying the wasm browser build from #2141 —
ls -ladisagreed withdatein the same session. Reproduces identically on native; it's not wasm-related.Fix
Replace the arithmetic with chrono via
time_compat::to_chrono_utc— the same conversion thedatebuiltin already uses for file mtimes — keeping the existing long-iso output style (YYYY-MM-DD HH:MM, UTC). The????-??-?? ??:??pre-epoch fallback branch is gone too:to_chrono_utchandles pre-epoch times correctly since #2140.Tests
Written first and confirmed failing against the old code. They pin exact rendering using
InMemoryFs::set_modified_timewith fixed epoch seconds (timezone-independent):2026-07-05 20:05(old code:2026-07-20)2024-02-29 12:00(old code:2024-03-13)2026-12-31 23:59(old code:2027-01-14)Verification
--lib --binssuite passes (3,351 tests)time_compatsource-scan test passes-D warningscleantouch /tmp/f && ls -la /tmp && date -u— ls and date now agree