コンテンツにスキップ

Date / Time / DateTime method coverage audit

Generated 2026-05-23 as the Phase 1 artifact of a rigor-type-coverage-uplift session (Phase 4 / Slice 4 of the post-c9a535a coverage-uplift line).

Unlike the String / Integer / Hash / Math audits, the Date / Time conclusion is not a list of dispatch-tier additions. The reader surface is already catalog-ready; the single blocker is a missing type carrier. This document records that finding. The carrier was authorised and implemented (see § 4); the 🟦 rows below are now ✅.


記号意味
Constant[Date] / Constant[Time]キャリア経由でfold済み
🚫非対象(破壊的・非決定的・マシン依存)

Date / DateTime / TimeCATALOG_BY_CLASSconstant_folding.rb)に 登録済みで、DATE_CATALOG / TIME_CATALOGがCソースから抽出済み。リーダ メソッド群(year / month / day / hour / wday / leap? / strftime / iso8601 / next_day / >> …)は:leaf分類でfold適格

それにもかかわらず精密化が起きないのは、Type::ConstantSCALAR_CLASSESlib/rigor/type/constant.rb)にDate / Timeが含まれず、ConstantFoldingfoldable_constant_value?も両クラスを受け付けないため。Date.new(2026,1,1)Nominal[Date]止まりで、その上の.yearもRBSティアのIntegerに 広がる。

spec/integration/fixtures/date_catalog/demo.rbtime_catalog.rbは、この 状況を「a future Constant<Date> carrier would be eligible to fold them」と 明記し、現状のNominal答えがunsound carrierを生まないことを回帰で固定して いる。本監査はその「future carrier」を正式な判断事項として起票するもの。


2. メソッド分類(Date / DateTime)

Section titled “2. メソッド分類(Date / DateTime)”

Date.new(...)の引数が全てConstant[Integer]のとき、以下がConstantに fold可能になる(カタログ分類は確認済み・date_catalog/demo.rbが裏付け):

メソッドfold先状態
Integerリーダyear month/mon day/mday wday yday cwyear cweek cwday jdConstant[Integer]
bool述語leap? julian? gregorian? sunday?saturday?Constant[bool]
Stringリーダto_s iso8601 strftime(fmt) httpdate rfc3339Constant[String]
Dateナビnext_day prev_day next_month prev_year succ >> << nextConstant[Date]
DateTime追加hour min sec offset zone`Constant[IntegerString]`
比較<=> == < > (Date×Date)`Constant[boolInteger]`
破壊的(Dateは不変。該当なし)

Time.utc(...) / Time.gm(...) / Time.at(epoch)の引数が全て定数のとき:

メソッドfold先状態
Integerリーダyear month day hour min sec wday yday usec nsec utc_offsetConstant[Integer]
bool述語utc?/gmt? sunday?saturday? dst?Constant[bool]
Stringリーダstrftime(fmt) to_s ctime/asctime inspectConstant[String]
Timeナビgetutc/getgm + -(Numeric) round floor ceilConstant[Time]
破壊的localtime gmtime utc🚫 ブロックリスト済み
マシン依存getlocal🚫 TIME_CATALOGブロックリストに追加
非決定的Time.now / Time.at / Time.local / Time.new🚫 carrier化対象外(ローカルゾーン依存)

Timeの不変性の注意: Time#localtime / gmtime / utctime_modify でreceiverをin-place変更する。Timeは純粋不変ではない。Constant[Time] キャリアにする場合、String / Setと同じくvalue.dup.freezeで凍結する必要 がある(凍結TimeへのlocaltimeFrozenError → foldはrescueで decline、健全)。TIME_CATALOGは既に3つの擬似ミューテータをブロックリスト済み。


4. 実装(carrier新設、承認のうえ実施)

Section titled “4. 実装(carrier新設、承認のうえ実施)”

Date / Timeの精密化はディスパッチ層の追加では達成できずType::Constant に新しいスカラキャリアを足す型システム変更が前提だった。Setキャリアの前例に 沿って以下を実装した:

  1. lib/rigor/type/constant.rb

    • 先頭でrequire "date"Date / DateTimeはstdlib。Timeはcore)。
    • SCALAR_CLASSESDateDateTimeDateのサブクラスなので包含)と Timeを追加。
    • initializeの凍結分岐をfreezable_carrier?に切り出し、Date / Timevalue.dup.freeze対象に追加(凍結TimeへのlocaltimeFrozenError → foldはrescueでdecline、健全)。
    • describeを特例化 — Date#inspectはastronomical Julian day表記で 不可読なのでiso8601"2026-01-01")を使う。Time#inspect"2026-01-01 00:00:00 UTC"と簡潔なので既定のまま。
  2. constant_folding.rb

    • foldable_constant_value?の許可クラス集合(FOLDABLE_CONSTANT_CLASSES)に Date / Timeを追加。リーダ群はカタログ(catalog_allows?)経由で 自動的にfoldするためUNARY/BINARY Setへの追加は不要。
  3. コンストラクタfoldConstant[Date] / Constant[Time]を産む入口)

    • Date.new(y,m,d) / DateTime.new(...)MethodDispatcher#meta_newdate_new_liftrange_new_lift / regexp_new_liftと同じ場所・同じ形)。
    • Time.utc(...) / Time.gm(...) — Tier D TimeFoldingモジュール (dispatch_stdlib_module_tiersに配線)。UTC固定なのでマシン非依存。
    • Time.now / Time.at / Time.local / Time.new / Date.today / Date.parse対象外 — 非決定的、またはローカルゾーン依存。
  4. FP規律 — マシン依存の排除

    • Time.utc / gmのみをfold(UTC固定)。Time.at / Time.local / Time.new(明示オフセットなし)は解析マシンのゾーンに依存するため非対象。
    • Time#getlocalTIME_CATALOGのブロックリストに追加 — ミューテータでは ないが結果が解析マシンのゾーンに依存するため、Constant[Time](常にUTC) からfoldするとホスト依存の値が型に焼き込まれる。getutc / getgmは UTC結果なのでfold可能なまま。
    • rigor check libクリーン、4345 examples 0 failuresで回帰固定。

© 2026 TypedDuck. Licensed under CC BY-SA 4.0.