Skip to content

datetime: add compact timedelta formatting for zero-day durations#1185

Open
14NGiestas wants to merge 1 commit intofortran-lang:masterfrom
14NGiestas:datetime-compact-format-timedelta
Open

datetime: add compact timedelta formatting for zero-day durations#1185
14NGiestas wants to merge 1 commit intofortran-lang:masterfrom
14NGiestas:datetime-compact-format-timedelta

Conversation

@14NGiestas
Copy link
Copy Markdown
Member

Summary

This PR improves duration formatting in the datetime module by adding compact, human-friendly output for zero-day timedeltas while preserving the existing verbose format for nonzero-day values.

What changed

  • Updated format_timedelta in src/datetime/stdlib_datetime.f90 to use compact zero-day formatting:
    • 5ms for sub-second durations
    • 1.500s or 42s for sub-minute durations
    • MM:SS when hours are zero
    • HH:MM:SS[.mmm] otherwise
  • Preserved verbose formatting for nonzero-day durations: X days, HH:MM:SS[.mmm].
  • Updated datetime spec text and examples in doc/specs/stdlib_datetime.md.
  • Added example output cases in example/datetime/example_datetime_usage.f90.
  • Expanded and registered unit tests in test/datetime/test_datetime.f90.

Why

The prior formatting was always verbose, which made short durations harder to scan. Compact formatting improves readability for common short intervals while preserving the legacy representation where day-level context is meaningful.

Validation

  • test_datetime includes new compact-format coverage and legacy-format checks.
  • Local run passed for datetime tests after preprocessing/build setup.

Compatibility

  • Backward compatible for nonzero-day durations (verbose format unchanged).
  • Intentional output change for zero-day durations to compact formats.

@14NGiestas 14NGiestas added enhancement New feature or request topic: datetime Specific for date and time data labels May 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 85.07463% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.88%. Comparing base (4c8521d) to head (244ffba).

Files with missing lines Patch % Lines
example/datetime/example_datetime_usage.f90 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1185      +/-   ##
==========================================
+ Coverage   68.81%   68.88%   +0.07%     
==========================================
  Files         408      408              
  Lines       13726    13786      +60     
  Branches     1552     1568      +16     
==========================================
+ Hits         9446     9497      +51     
- Misses       4280     4289       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@14NGiestas 14NGiestas force-pushed the datetime-compact-format-timedelta branch from a700b84 to 244ffba Compare May 7, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request topic: datetime Specific for date and time data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant