Keep civil-date math in one utils::time module: days_from_civil is written twice and vex::time claims to be the only copy

未關閉
#1,867 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
66/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
backend

研究方向

Read crates/socket-patch-core/src/api/date.rs, formats/cargo/floor.rs, and vex/time.rs, then check how api::date is imported by tests/e2e_hosted_production.rs. Move the listed time functions and tests into src/utils/time.rs, update callers and remove the duplicate implementation and outdated claim. Run the named date and dated-channel tests; done means behavior is unchanged and only one days_from_civil definition remains.

由索引模型根據 Issue 內容生成。

描述

agent:triaged arch-audit priority:p3 refactor

[agent] Filed by the scheduled architecture audit (audit-core). Register: register.

Kind: refactor. Register ID: A26.

Problem

Calendar arithmetic (Howard Hinnant's civil-date algorithms) lives in three modules at 5ca5623:

  • api/date.rs L48-L56: days_from_civil(year: i64, month: u32, day: u32), the parser half (parse_timestamp_secs, used by api::ranking and api::retry).
  • formats/cargo/floor.rs L25-L33: a second days_from_civil(year: i64, month: i64, day: i64), spelled with div_euclid instead of the if y >= 0 { y } else { y - 399 } / 400 form. It is used to date nightly-YYYY-MM-DD toolchains.
  • vex/time.rs L30-L36: the inverse civil_from_days, inside unix_to_ymdhms. Its doc claims "this is the single civil-date implementation in the crate". telemetry also formats timestamps through it.

Today the two days_from_civil copies compute the same values; api/date.rs's round-trip test pins only its own copy. A time module under vex/ that telemetry and api import, plus a date parser under api/, puts a general utility in two feature modules.

Proposed change
  • Add crates/socket-patch-core/src/utils/time.rs holding days_from_civil, unix_to_ymdhms, now_rfc3339 and parse_timestamp_secs, with the tests of api/date.rs and vex/time.rs.
  • Delete formats/cargo/floor.rs's copy and call utils::time::days_from_civil (convert its i64 month and day at the call).
  • Delete api/date.rs and vex/time.rs, or reduce them to pub use lines if the CLI or tests import them by path (tests/e2e_hosted_production.rs imports api::date::parse_timestamp_secs).
  • Drop the "single civil-date implementation" claim.
Size

4–5 files. The diff is mostly moves; about −25 net lines.

Acceptance criteria
  • Behavior is unchanged. days_from_civil_inverts_unix_to_ymdhms, parsed_order_is_chronological_in_both_formats, unix_to_ymdhms_matches_brute_force and floor.rs's dated-channel tests pass unchanged.
  • One days_from_civil remains in the crate (grep -rn "fn days_from_civil" crates returns one hit).
  • While moving the tests, drop the fake assert assert!(secs > prev_2822 || secs == 0) in parsed_order_is_chronological_in_both_formats (date.rs L523). It checks the test's own loop counter, not the parser.
主要語言
Rust
星號
9
分支
2
平均合併
20 小時 47 分鐘
30 天內合併 PR
681

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SocketDev/socket-patch 的其他 Issue

查看 SocketDev/socket-patch 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。