Skip to content

Test 2 oss-20B - #2

Open
ahmetkaansever wants to merge 1 commit into
masterfrom
demo-pr-2
Open

ahmetkaansever wants to merge 1 commit into
masterfrom
demo-pr-2

Conversation

@ahmetkaansever

Copy link
Copy Markdown

General Description

Implemented sub‑second support for chrono formatting. Added helper utilities for non‑negative integer conversion, absolute duration handling, fractional digit counting, and sub‑second formatting. Updated tm_writer to accept an optional sub‑second duration and print it when formatting seconds. Extended chrono_formatter to handle floating‑point and non‑integer durations, and updated the system‑clock formatter to forward subseconds. Added comprehensive tests for various duration types and sub‑second formatting.

File changes

  • include/fmt/chrono.h

    • Added utilities: to_nonnegative_int, abs, pow10, count_fractional_digits, write_sub_sec, format_sec_fractional.
    • Extended tm_writer with constructors that accept a sub‑second duration and logic to print sub‑seconds in on_second.
    • Updated chrono_formatter to use new helpers, support floating‑point seconds, and print sub‑seconds.
    • Modified system‑clock formatter to pass subseconds to tm_writer.
    • Added overload for formatting std::tm with subseconds.
    • Removed duplicated helper definitions.
  • test/chrono-test.cc

    • Updated tests to use time_point_cast<std::chrono::seconds> for consistency.
    • Added new tests covering sub‑second formatting for various duration types (ratio, floating‑point, milliseconds, microseconds, nanoseconds, etc.).
    • Added tests for timestamp formatting with sub‑seconds.
  • test/xchar-test.cc

    • Updated test to cast system clock to seconds before formatting.

@deeployed-peer-dev

deeployed-peer-dev Bot commented Oct 29, 2025 •

Copy link
Copy Markdown
Walkthrough The PR adds sub‑second support to chrono formatting across the library. New helpers convert durations to non‑negative integers, compute absolute values, powers of ten, and count fractional digits. `tm_writer` now accepts optional sub‑seconds and prints them when a second changes. `chrono_formatter` handles any `duration` (including floating‑point), forwards sub‑seconds to the writer, and formats fractional seconds. The system‑clock and UTC formatters forward sub‑seconds, and `formatter` gains an overload that takes a sub‑second duration. All duplicate helper definitions are removed. Tests are updated to cover a wide range of duration types and verify correct sub‑second output. No further downstream changes are required.
Changes | Files | Summary | |-------|---------| | `include/fmt/chrono.h` | Added sub‑second helpers, extended `tm_writer` and `chrono_formatter` to handle sub‑seconds, removed duplicates, updated public overloads. | | `test/chrono-test.cc`, `test/xchar-test.cc` | Updated tests to cast system clock to seconds, added sub‑second formatting tests for various duration types and precisions. |
Sequence Diagram ```mermaid sequenceDiagram participant User participant fmt as fmt::format participant chrono_fmt as chrono_formatter participant tm_writer as tm_writer participant sys_clock as system_clock formatter participant utc_clock as UTC clock formatter
User->>fmt: format(time_point)
fmt->>chrono_fmt: format(time_point)
chrono_fmt->>chrono_fmt: compute sub_seconds if needed
alt period != 1 or floating-point
    chrono_fmt->>sys_clock: forward sub_seconds
else
    chrono_fmt->>tm_writer: write_sub_sec(sub_seconds)
end
sys_clock->>tm_writer: on_second() prints sub_seconds if has_subsecs_
utc_clock->>sys_clock: forward sub_seconds
tm_writer->>User: formatted string with fractional seconds
</details>
<!-- This is an auto-generated comment: raw summary by Deeployed - Reviewed -->
<!--

include/fmt/chrono.h: **Purpose**  
Add sub‑second support to chrono formatting. The PR introduces helpers for converting values to non‑negative integers, absolute durations, power‑of‑ten calculation, counting fractional digits, and formatting sub‑seconds. It extends `tm_writer` to accept an optional sub‑second duration and prints it when formatting seconds. `chrono_formatter` now handles floating‑point and non‑integer durations, forwards subseconds to `tm_writer`, and formats fractional seconds appropriately. System‑clock formatter forwards subseconds, and a new overload formats `std::tm` with subseconds. Duplicate helper definitions were removed.

**Public Interface Changes**  
- `tm_writer` now has constructors that take a `std::chrono::duration<Rep,Period>` subseconds and a flag `has_subsecs_`.  
- `chrono_formatter` now has a templated `format` accepting a `time_point` with any `duration<Rep,Period>` (including floating‑point).  
- `formatter<std::tm>` gained a new `format` overload that takes a `duration<Rep,Period>` subseconds.  
- Helper functions `to_nonnegative_int`, `abs`, `pow10`, `count_fractional_digits`, `write_sub_sec`, `format_sec_fractional` are added to `detail` namespace.

**Implementation Updates**  
- Sub‑second formatting logic moved from `chrono_formatter::write_fractional_seconds` to new helpers.  
- `tm_writer::on_second` now prints subseconds when `has_subsecs_` is true.  
- System‑clock formatter checks if the period is non‑unit or floating‑point to compute and pass subseconds.  
- UTC clock formatter now forwards to the system‑clock formatter with subseconds.  
- `formatter<std::tm>` now supports a `subsecs` overload.

**Tests & Migrations**  
- Tests updated to cast system clock to seconds before formatting.  
- New tests added for sub‑second formatting across various duration types (ratio, floating‑point, milliseconds, microseconds, nanoseconds).  
- Timestamp formatting tests now cover sub‑seconds.

**Dependencies Updated**  
- All call sites using `chrono_formatter` and `formatter<std::tm>` now pass subseconds where needed.  
- No remaining duplicate helper definitions; redundant code removed.  

test/chrono-test.cc, test/xchar-test.cc: **Purpose / Behavioral Change**  
The PR adds sub‑second support to chrono formatting. Time points and durations that include fractional seconds are now printed with the appropriate precision, and the formatting of the `%S` specifier correctly handles floating‑point and non‑integer durations.

**Public Interface / Contract Changes**  
* `fmt::format` for chrono now accepts `std::chrono::time_point` with any duration type, including `ratio<1,3>`, `double`, `milliseconds`, `microseconds`, `nanoseconds`, etc.  
* The `%S` format specifier now prints seconds with fractional part when present, e.g., `"01.333333"` for 1 ⅓ seconds.  
* Existing overloads for `std::tm` and system‑clock formatting forward sub‑seconds to the writer.

**Test Updates / Additions**  
* `test/chrono-test.cc` now casts the system clock to seconds before formatting (`time_point_cast<std::chrono::seconds>`).  
* New tests (`timestamps_sub_seconds`) verify correct sub‑second output for a wide range of duration types and precisions, including:  
  * `ratio<1,3>` and `double` durations.  
  * `std::chrono::seconds`, `milliseconds`, `microseconds`, `nanoseconds`.  
  * Floating‑point seconds (`double{1.5}`).  
  * Mixed precision (e.g., `seconds(1)+milliseconds(120)`).  
  * Current time with nanosecond resolution.  
* Additional checks confirm that the string produced by `{:%Y-%m-%d %H:%M:%S}` matches the concatenation of the formatted seconds and the sub‑second part.

**No Further Dependencies**  
All dependent call sites (e.g., system‑clock formatter and `tm_writer`) were updated in the same PR, so no downstream code requires further changes.
-->
<!-- end of auto-generated comment: raw summary by Deeployed - Reviewed -->
<!-- This is an auto-generated comment: short summary by Deeployed - Reviewed -->
<!--

include/fmt/chrono.h: **Purpose**  
Add sub‑second support to chrono formatting. The PR introduces helpers for converting values to non‑negative integers, absolute durations, power‑of‑ten calculation, counting fractional digits, and formatting sub‑seconds. It extends `tm_writer` to accept an optional sub‑second duration and prints it when formatting seconds. `chrono_formatter` now handles floating‑point and non‑integer durations, forwards subseconds to `tm_writer`, and formats fractional seconds appropriately. System‑clock formatter forwards subseconds, and a new overload formats `std::tm` with subseconds. Duplicate helper definitions were removed.

**Public Interface Changes**  
- `tm_writer` now has constructors that take a `std::chrono::duration<Rep,Period>` subseconds and a flag `has_subsecs_`.  
- `chrono_formatter` now has a templated `format` accepting a `time_point` with any `duration<Rep,Period>` (including floating‑point).  
- `formatter<std::tm>` gained a new `format` overload that takes a `duration<Rep,Period>` subseconds.  
- Helper functions `to_nonnegative_int`, `abs`, `pow10`, `count_fractional_digits`, `write_sub_sec`, `format_sec_fractional` are added to `detail` namespace.

**Implementation Updates**  
- Sub‑second formatting logic moved from `chrono_formatter::write_fractional_seconds` to new helpers.  
- `tm_writer::on_second` now prints subseconds when `has_subsecs_` is true.  
- System‑clock formatter checks if the period is non‑unit or floating‑point to compute and pass subseconds.  
- UTC clock formatter now forwards to the system‑clock formatter with subseconds.  
- `formatter<std::tm>` now supports a `subsecs` overload.

**Tests & Migrations**  
- Tests updated to cast system clock to seconds before formatting.  
- New tests added for sub‑second formatting across various duration types (ratio, floating‑point, milliseconds, microseconds, nanoseconds).  
- Timestamp formatting tests now cover sub‑seconds.

**Dependencies Updated**  
- All call sites using `chrono_formatter` and `formatter<std::tm>` now pass subseconds where needed.  
- No remaining duplicate helper definitions; redundant code removed.  

test/chrono-test.cc, test/xchar-test.cc: **Purpose / Behavioral Change**  
The PR adds sub‑second support to chrono formatting. Time points and durations that include fractional seconds are now printed with the appropriate precision, and the formatting of the `%S` specifier correctly handles floating‑point and non‑integer durations.

**Public Interface / Contract Changes**  
* `fmt::format` for chrono now accepts `std::chrono::time_point` with any duration type, including `ratio<1,3>`, `double`, `milliseconds`, `microseconds`, `nanoseconds`, etc.  
* The `%S` format specifier now prints seconds with fractional part when present, e.g., `"01.333333"` for 1 ⅓ seconds.  
* Existing overloads for `std::tm` and system‑clock formatting forward sub‑seconds to the writer.

**Test Updates / Additions**  
* `test/chrono-test.cc` now casts the system clock to seconds before formatting (`time_point_cast<std::chrono::seconds>`).  
* New tests (`timestamps_sub_seconds`) verify correct sub‑second output for a wide range of duration types and precisions, including:  
  * `ratio<1,3>` and `double` durations.  
  * `std::chrono::seconds`, `milliseconds`, `microseconds`, `nanoseconds`.  
  * Floating‑point seconds (`double{1.5}`).  
  * Mixed precision (e.g., `seconds(1)+milliseconds(120)`).  
  * Current time with nanosecond resolution.  
* Additional checks confirm that the string produced by `{:%Y-%m-%d %H:%M:%S}` matches the concatenation of the formatted seconds and the sub‑second part.

**No Further Dependencies**  
All dependent call sites (e.g., system‑clock formatter and `tm_writer`) were updated in the same PR, so no downstream code requires further changes.
-->
<!-- end of auto-generated comment: short summary by Deeployed - Reviewed -->
<!-- This is an auto-generated comment: impact context by Deeployed - Reviewed -->
<!--

-->
<!-- end of auto-generated comment: impact context by Deeployed - Reviewed -->
---
<summary>Uplevel your code reviews with Deeployed Peer!</summary>


<!-- commit_ids_reviewed_start -->
<!-- e21e942100cca80cf9993995d645acdae93fa7b5 -->
<!-- commit_ids_reviewed_end -->
  <!-- This is an auto-generated comment: learnings by Deeployed - Reviewed -->
<!--
  
  -->
<!-- end of auto-generated comment: learnings by Deeployed - Reviewed -->
 
 <!-- This is an auto-generated comment: summarize by Deeployed - Reviewed -->

@deeployed-peer-dev deeployed-peer-dev 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.

Commits Files that changed from the base of the PR and between Base and e21e942 commits: 3
Files Selected For Review: 3
  • include/fmt/chrono.h with diff length 15943.
  • test/chrono-test.cc with diff length 4017.
  • test/xchar-test.cc with diff length 421.
Review comments generated: (19)
  • Review: 0
  • LGTM: 19
  • Identified issue already discussed: 0

Tips

Chat with Deeployed Bot (@@deeployed-peer-dev)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @@deeployed-peer-dev in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @deeployed-peer-dev: ignore anywhere in the PR description to pause further reviews from the bot.

@Konuralpkilinc Konuralpkilinc changed the title Timestamp formatting shall print also subseconds, fixed a bug for fra… oss-20B Test 2 oss-20B Oct 29, 2025
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