Skip to content

feat: add %F and %u strftime format codes#111

Merged
atoomic merged 3 commits into
cpan-authors:mainfrom
Koan-Bot:koan.atoomic/add-missing-format-codes
Apr 29, 2026
Merged

feat: add %F and %u strftime format codes#111
atoomic merged 3 commits into
cpan-authors:mainfrom
Koan-Bot:koan.atoomic/add-missing-format-codes

Conversation

@Koan-Bot
Copy link
Copy Markdown

What

Add two missing POSIX strftime format specifiers: %F (ISO 8601 date) and %u (Monday-based weekday number).

Why

%F and %u are defined in POSIX.1-2001 and widely expected by users coming from C's strftime or GNU coreutils date. Currently, time2str("%F", time) silently returns the literal "F" instead of a date — surprising behavior for a standard code.

How

  • format_F: composite format returning %Y-%m-%d (same pattern as existing format_D, format_T)
  • format_u: returns $_[0]->[6] || 7 — maps Sunday from Perl's 0 to POSIX's 7
  • Fixed %e documentation range from 1..32 to 1..31

Testing

15 new test cases in t/format.t (292 → 307):

  • %F and %u tested across all 6 language sections (English, German, French, Italian, Bulgarian, Portuguese)
  • Dedicated Sunday boundary test verifying %u returns 7 and %w returns 0
  • Full test suite passes

@atoomic
Copy link
Copy Markdown
Collaborator

atoomic commented Apr 26, 2026

@Koan-Bot rebase

@atoomic atoomic marked this pull request as ready for review April 26, 2026 13:01
@atoomic atoomic self-assigned this Apr 26, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

This PR adds two POSIX strftime specifiers — %F (ISO 8601 date: YYYY-MM-DD) and %u (Monday-based weekday: 1–7) — that were previously unimplemented and silently fell back to returning the bare letter. Both are implemented in Date::Format::Generic and are inherited by all language subclasses via the existing Date::LanguageDate::Format::Generic chain, so no per-language copies are needed. The %e documentation fix (1..321..31) is also correct.

Confidence Score: 5/5

Safe to merge — implementation is minimal, follows existing patterns exactly, and is thoroughly tested.

Both new format functions are correct: format_u uses the idiomatic $_[0]->[6] || 7 pattern to remap Sunday from 0 to 7, and format_F composes existing helpers the same way format_D and format_T do. Inheritance means all 30+ language subclasses get the new codes for free. 15 new test cases cover every language fixture plus a dedicated Sunday boundary check. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
lib/Date/Format/Generic.pm Adds format_u (Monday-based weekday, Sunday→7) and format_F (ISO 8601 YYYY-MM-DD); both follow existing patterns and are correctly implemented.
lib/Date/Format.pm Documentation additions for %F and %u, plus correction of %e range from 1..32 to 1..31.
t/format.t Adds 15 new test cases covering %F and %u across all 6 language sections plus a dedicated Sunday boundary test (315964800); test count updated from 292 to 307.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["time2str / strftime call"] --> B["_subs() regex substitution\n%(O?[%a-zA-Z])"]
    B --> C{Format code?}
    C -->|"%F"| D["format_F()\nformat_Y . '-' . format_m . '-' . format_d\n→ YYYY-MM-DD"]
    C -->|"%u"| E["format_u()\n$_[0]->[6] || 7\n→ 1..7, Sunday=7"]
    C -->|"%w"| F["format_w()\n$_[0]->[6]\n→ 0..6, Sunday=0"]
    C -->|"%D"| G["format_D()\nformat_m . '/' . format_d . '/' . format_y\n→ MM/DD/YY"]
    C -->|"unknown"| H["return bare letter\n(fallback)"]
Loading

Reviews (1): Last reviewed commit: "feat: add %F (ISO 8601 date) and %u (Mon..." | Re-trigger Greptile

@Koan-Bot
Copy link
Copy Markdown
Author

Rebase with requested adjustments

Branch koan.atoomic/add-missing-format-codes was rebased onto main and review feedback was applied.

Stats

3 files changed, 22 insertions(+), 2 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=None of the recent commits on main mention %F, %u, format_F, or format_u — the ISO 8601 date format )
  • Resolved merge conflicts (1 round(s))
  • Rebased koan.atoomic/add-missing-format-codes onto upstream/main
  • Pre-push CI check: previous run passed
  • Force-pushed koan.atoomic/add-missing-format-codes to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/add-missing-format-codes branch from e798c18 to b451703 Compare April 27, 2026 00:45
Koan-Bot added a commit to Koan-Bot/perl-TimeDate that referenced this pull request Apr 27, 2026
Comment thread .github/workflows/ci.yml Outdated
sudo: false
global: false
cpanfile: ".github/cpanfile"
version: "0.997016"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do not bump/pin the version for cpm let's use install-with-cpm@v2 instead

@atoomic
Copy link
Copy Markdown
Collaborator

atoomic commented Apr 27, 2026

@Koan-Bot rebase

Add two commonly-used POSIX strftime format specifiers that were missing:
- %F: ISO 8601 date format (YYYY-MM-DD), equivalent to %Y-%m-%d
- %u: day of the week as decimal (1=Monday, 7=Sunday)

Also fix %e documentation range from 1..32 to 1..31.

15 new test cases covering all language sections plus a Sunday boundary
test to verify %u correctly returns 7 (not 0) for Sundays.
- Removed pinned `version: "0.997016"` for cpm and upgraded `install-with-cpm@v1` to `install-with-cpm@v2` per reviewer request to not bump/pin the cpm version and use v2 of the action instead.
@Koan-Bot
Copy link
Copy Markdown
Author

Rebase with requested adjustments

Branch koan.atoomic/add-missing-format-codes was rebased onto main and review feedback was applied.

Changes applied

  • Removed pinned version: "0.997016" for cpm and upgraded install-with-cpm@v1 to install-with-cpm@v2 per reviewer request to not bump/pin the cpm version and use v2 of the action instead.

Stats

4 files changed, 23 insertions(+), 3 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=None of the recent commits on main mention %F, %u, or ISO 8601 date format codes — the feature this )
  • Rebased koan.atoomic/add-missing-format-codes onto upstream/main
  • Applied review feedback
  • Pre-push CI check: previous run passed
  • Force-pushed koan.atoomic/add-missing-format-codes to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/add-missing-format-codes branch from 54afe00 to 797365d Compare April 27, 2026 06:00
@atoomic atoomic merged commit 975b1b4 into cpan-authors:main Apr 29, 2026
22 checks passed
atoomic pushed a commit that referenced this pull request Apr 29, 2026
@Koan-Bot Koan-Bot deleted the koan.atoomic/add-missing-format-codes branch April 29, 2026 10:21
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.

2 participants