Skip to content

Support Japanese time notations in Time.parse and add %JT strftime directives - #26

Merged
sugi merged 11 commits into
masterfrom
feature/time-kansuji-support
Jul 13, 2026
Merged

Support Japanese time notations in Time.parse and add %JT strftime directives#26
sugi merged 11 commits into
masterfrom
feature/time-kansuji-support

Conversation

@sugi

@sugi sugi commented Jul 13, 2026

Copy link
Copy Markdown
Owner

概要

時刻の日本語表記(漢数字・全角数字の時分秒)のパースとフォーマットをサポートします。日付と違い時刻には元号のようなマッピングが存在しないため、単純な数字変換に徹しています。

設計書: docs/superpowers/specs/2026-07-13-time-kansuji-support-design.md / 実装計画: docs/superpowers/plans/2026-07-13-time-kansuji-support.md

機能

パース (Time.parse / Date._parse)

日本語時刻表記を等価な ASCII 表記へ「翻字」してから Ruby 標準パーサへ委ねます。Time.parse は内部で Date._parse を呼ぶため、既存フックの拡張だけで対応され、Time クラスのパースパッチは不要です。

require 'time'
Time.parse("平成元年五月四日 午後三時三十四分五十六秒") # => 1989-05-04 15:34:56
Time.parse("令和三年一月一日 零時五分")                 # => 2021-01-01 00:05:00
  • 漢数字・全角・半角の時分秒、午前/午後、「半」(三時半)、「正午」に対応
  • 範囲チェックはせず stdlib に委任: 「二十五時」→ "25:00" → ArgumentError(ASCII と同一挙動)

フォーマット (%JT 指示子)

Time#strftime(新規、%J 日付系も併せて対応)と DateTime#strftime に時刻用の %JT 名前空間を追加。Time#to_wareki_date も追加しています。

t.strftime("%JF %JTF")  # => "平成元年五月四日 十五時三十四分五十六秒"
t.strftime("%JTf")      # => "15時34分56秒"

%JTf(半角複合・0埋めフラグ対応) / %JTF(漢数字複合) / %JTH%JTHk(時) / %JTM%JTMk(分) / %JTS%JTSk(秒)

挙動変更(2.0.0 向け・不具合修正扱い)

  1. Date._parse("12時34分56秒"){mday: 12} ではなく {hour: 12, min: 34, sec: 56} を返すように
  2. Date.parse("12時34分") が当月12日ではなく ArgumentError に(ASCII "12:34" と同一)
  3. 「〜二十五時」など範囲外時刻付き文字列の Time.parse が ArgumentError に
  4. 「10時間耐久」「13時代」など「数字+時」複合語も時刻として翻字されるため、従来 Date.parse が数字を日として拾って成功していた文字列がエラーになる場合があります(レビューで検出し、翻字方式の帰結として維持を選択済み。README の制限事項に記載)

テスト

  • rspec: 82 examples, 0 failures(新規 ~20 例: 正規化・%JT 展開・std_ext 統合・回帰ガード)
  • rubocop: 既存ベースライン5件 + class Time 追加による Style/OneClassPerFile 1件のみ(Metrics/ModuleLength Max を 120→170 に引き上げ)
  • サブエージェント駆動でタスク毎に spec 準拠+品質レビュー、最終に全ブランチレビューを実施済み(ready to merge 判定)

🤖 Generated with Claude Code

https://claude.ai/code/session_01JhoiyVcAVMwTk8AgxNFgeB

sugi and others added 10 commits July 13, 2026 08:25
DateTime %J support and expand_wareki_format already landed upstream;
integrate time normalization with PARSE_QUICK_FILTER and verify stdlib
out-of-range time behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JhoiyVcAVMwTk8AgxNFgeB
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JhoiyVcAVMwTk8AgxNFgeB
Time.parse picks this up automatically since it calls Date._parse.
Reviewer found strings like '10時間耐久' flip Date.parse from a bogus
day-pick to ArgumentError; maintainer approved keeping pure
transliteration over a negative-lookahead exclusion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JhoiyVcAVMwTk8AgxNFgeB
Move number format resolution to Utils.number_format so time and date
formatting share the padding-flag logic.
Add Time#to_wareki_date and StdExt.expand_all_wareki_formats shared by
the Time and DateTime strftime patches.
Follow-ups from final review: pin U+3000 spacing and pre-era Time
strftime behavior; document that DateTime.parse bypasses the patched
parser.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JhoiyVcAVMwTk8AgxNFgeB

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for parsing and formatting Japanese kansuji and zenkaku time notations (such as '十二時三十四分五十六秒', '午後三時半', and '正午') in Time.parse, Time#strftime, and DateTime#strftime. It introduces %JT* time format directives, adds Time#to_wareki_date, and centralizes number formatting logic in Wareki::Utils. Comprehensive tests, documentation, and design specs have been added to support these changes. As there are no review comments, I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@sugi
sugi merged commit 7671c11 into master Jul 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant