Skip to content

Conversation

iguessthislldo
Copy link
Member

@iguessthislldo iguessthislldo commented Aug 30, 2025

ACE_Time_Value currently doesn't accept a std::chrono::duration with Rep that's a floating point type because it's using the modulus operator to separate the microseconds (duration % seconds(1)) and trying to use modulus with floating points causes a compile error.

This changes it to use subtraction from the whole number of seconds (duration - sec) and adds a test for it.

Summary by CodeRabbit

  • New Features

    • Support for constructing time values from floating-point std::chrono durations.
  • Bug Fixes

    • More consistent sub-second extraction; conversion semantics adjusted (may affect negative-duration edge cases).
    • Internal arithmetic for adding/subtracting durations simplified to reuse construction logic.
  • Tests

    • Expanded chrono tests (positive/negative and floating-point cases) and added a reusable test helper.
  • Chores

    • Updated test ignore list to reflect current test alignment.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2025

Walkthrough

ACE_Time_Value::set now computes seconds via duration_cast and microseconds from duration - seconds; operator+= and operator-= delegate to ACE_Time_Value(duration). Chrono tests were centralized into a tv_test_case helper and extended to cover floating-point durations. tests/.gitignore entries were reorganized.

Changes

Cohort / File(s) Summary of changes
Time value duration handling
ACE/ace/Time_Value.h
Rewrote ACE_Time_Value::set(const std::chrono::duration<Rep, Period>&) to compute sec with duration_cast<std::chrono::seconds>(duration) and compute usec from duration_cast<std::chrono::microseconds>(duration - sec), using local using aliases and truncate_cast on counts. operator+= and operator-= now delegate to *this += ACE_Time_Value(duration) / *this -= ACE_Time_Value(duration) instead of manual per-field math. No public signatures changed.
Chrono tests
ACE/tests/Chrono_Test.cpp
Added tv_test_case helper overloads to centralize validation; replaced inline checks with helper calls; added tests for floating-point std::chrono::duration<double> (half-day, positive/negative fractional seconds) and adjusted error reporting and accumulation.
Test ignore list
ACE/tests/.gitignore
Reworked ignored test entries: added Compiler_Features_39_Test, Compiler_Features_40_Test, Compiler_Features_41_Test, Compiler_Features_42_Test, Future_Stress_Test, Singleton_Test, TSS_Static_Test; removed Compiler_Features_36_Test, Compiler_Features_37_Test, Compiler_Features_38_Test, SOCK_Acceptor_Test, Multicast_Interfaces_Test; reordered related entries.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Chrono as std::chrono::duration
    participant ACE as ACE_Time_Value

    Note over Caller,Chrono: Input: duration (Rep,Period)

    Caller->>ACE: ACE_Time_Value::set(duration)
    ACE->>Chrono: duration_cast<std::chrono::seconds>(duration)
    Chrono-->>ACE: sec (seconds)
    ACE->>Chrono: remainder = duration - sec
    Chrono-->>ACE: remainder (duration)
    ACE->>Chrono: duration_cast<std::chrono::microseconds>(remainder)
    Chrono-->>ACE: usec (microseconds)
    ACE->>ACE: truncate_cast(sec.count()), truncate_cast(usec.count())
    ACE-->>Caller: constructed ACE_Time_Value(sec,usec)

    Note right of ACE: operator+= / operator-= delegate to\nACE_Time_Value(duration) then reuse existing ops
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I nibble seconds, slice the rest,
I subtract the part that won't digest.
Micros lined in tidy rows,
Tests hop in to check the shows.
A rabbit claps and nibbles a carrot — hooray! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c9d1cbe and addc542.

📒 Files selected for processing (1)
  • ACE/tests/Chrono_Test.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ACE/tests/Chrono_Test.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: ubuntu-24.04 clang++-20
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e compact
  • GitHub Check: ubuntu-24.04 clang++-14
  • GitHub Check: ubuntu-24.04 g++-14
  • GitHub Check: ubuntu-24.04 g++-13
  • GitHub Check: ubuntu-24.04 g++-12
  • GitHub Check: alpine-3.18
  • GitHub Check: VS2022Debug64Cxx17
  • GitHub Check: VS2022Release64
  • GitHub Check: MINGW64-gcc
  • GitHub Check: VS2022Debug64Cxx20
  • GitHub Check: VS2022Debug64
  • GitHub Check: VS2022WChar
  • GitHub Check: VS2022WChar
  • GitHub Check: VS2022Release32
  • GitHub Check: macos-13-C++
  • GitHub Check: VS2022Debug32
  • GitHub Check: macos-14-C++
  • GitHub Check: ubuntu-24.04 g++
  • GitHub Check: windows-2022 vs2022
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
ACE/tests/Chrono_Test.cpp (1)

147-158: Good positive FP-duration coverage; add negative-duration cases to lock semantics.

Please add tests for:

  • negative fractional day (e.g., -0.5 days → sec = -43200, usec = 0);
  • small negative fractional seconds (e.g., -0.1s → sec = -1, usec = 900000) to verify canonicalization.

Example:

   if (tv.sec () != 3600*12 || tv.usec () != 0)
   {
     ...
   }
+
+  // Negative floating-point durations should canonicalize.
+  std::chrono::duration<double, std::ratio<86400>> const neg_half_day {-0.5};
+  tv = ACE_Time_Value { neg_half_day };
+  if (tv.sec () != -3600*12 || tv.usec () != 0)
+  {
+    ACE_ERROR ((LM_ERROR,
+                ACE_TEXT ("(%P|%t) unexpected value after converting ")
+                ACE_TEXT ("-0.5 day to ACE_Time_Value. <sec=-43200,usec=0> - ")
+                ACE_TEXT ("got <sec=%d,usec=%d>\n"), tv.sec (), tv.usec ()));
+    ++errors;
+  }
+
+  std::chrono::duration<double> const neg_tenth {-0.1};
+  tv = ACE_Time_Value { neg_tenth };
+  if (tv.sec () != -1 || tv.usec () != 900000)
+  {
+    ACE_ERROR ((LM_ERROR,
+                ACE_TEXT ("(%P|%t) unexpected value after converting ")
+                ACE_TEXT ("-0.1s to ACE_Time_Value. <sec=-1,usec=900000> - ")
+                ACE_TEXT ("got <sec=%d,usec=%d>\n"), tv.sec (), tv.usec ()));
+    ++errors;
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0245b63 and 222db9e.

📒 Files selected for processing (3)
  • ACE/ace/Time_Value.h (1 hunks)
  • ACE/tests/.gitignore (5 hunks)
  • ACE/tests/Chrono_Test.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: VS2022Debug64
  • GitHub Check: ubuntu-24.04 g++-10 wchar
  • GitHub Check: MINGW64-gcc
  • GitHub Check: alpine-3.18
  • GitHub Check: ubuntu-22.04 clang++-13
  • GitHub Check: ubuntu-24.04 clang++-20 c++23
  • GitHub Check: ubuntu-24.04 g++-10 ACE for TAO
  • GitHub Check: ubuntu-24.04 g++-12
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e micro
  • GitHub Check: ubuntu-24.04 clang++-14
  • GitHub Check: ubuntu-24.04 g++-11
  • GitHub Check: ubuntu-22.04 g++-9
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e compact
  • GitHub Check: ubuntu-24.04 clang++-16
  • GitHub Check: ubuntu-22.04 g++-10
  • GitHub Check: ubuntu-24.04 g++-13
  • GitHub Check: ubuntu-24.04 g++-14
  • GitHub Check: ubuntu-24.04 clang++-20
  • GitHub Check: ubuntu-24.04 clang++-15
  • GitHub Check: ubuntu-22.04 clang++-12
🔇 Additional comments (5)
ACE/tests/.gitignore (5)

97-103: Confirm intent of Compiler_Features ignore set change.

Dropping 36–38 and adding 39–42 will start tracking 36–38 if those dirs exist. If that’s intended (e.g., tests stabilized), fine; otherwise, keep them ignored for consistency.


120-120: LGTM: add Future_Stress_Test to ignore.

No issues.


163-163: Multicast_Interfaces_Test ignore entry changed—verify desired state.

Network-interface dependent tests often produce local flakiness/noise. Ensure we either keep ignoring it or add CI guards before unignoring.


229-231: Singleton_Test/SOCK_Acceptor_Test entries—double-check policy.

If these tests are meant to be tracked, remove from .gitignore; if not, keep them here. Current change suggests policy shift—please confirm.


270-270: LGTM: add TSS_Static_Test to ignore.

Matches typical policy for platform-dependent TSS tests.

`ACE_Time_Value` currently doesn't accept a `std::chrono::duration` with
`Rep` that's a floating point type because it's using the modulus
operator to separate the microseconds (`duration % seconds(1)`) and
trying to use modulus with floating points causes a compile error.

This changes it to use subtraction from the whole number of seconds
(`duration - sec`) and adds a test for it.

Also:
- Simplify the `-=` and `+=` ops of `ACE_Time_Value`
- Rewrite some of the testing in `Chrono_Test.cpp`.
@iguessthislldo iguessthislldo force-pushed the igtd/fp-duration-to-time-value branch from 222db9e to b226740 Compare September 3, 2025 00:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
ACE/ace/Time_Value.h (1)

121-127: Float-duration remainder extraction fix is correct; optional: canonicalize negative remainders.

Subtraction avoids the FP modulo compile error. If you want usec in [0..1s) canonical form (not required by current tests), adjust negative remainders locally before calling set(). This mirrors “seconds-minus-one, remainder-plus-one-second.”

     using std::chrono::seconds;
     using std::chrono::microseconds;
     using std::chrono::duration_cast;

-    auto const sec = duration_cast<seconds> (duration);
-    auto const usec = duration_cast<microseconds> (duration - sec);
-    this->set (ACE_Utils::truncate_cast<time_t> (sec.count ()), ACE_Utils::truncate_cast<suseconds_t> (usec.count ()));
+    seconds sec = duration_cast<seconds>(duration);
+    auto rem = duration - sec;
+    if (rem < seconds{0}) {
+      sec -= seconds{1};
+      rem += seconds{1};
+    }
+    auto const usec = duration_cast<microseconds>(rem);
+    this->set(ACE_Utils::truncate_cast<time_t>(sec.count()),
+              ACE_Utils::truncate_cast<suseconds_t>(usec.count()));
🧹 Nitpick comments (4)
ACE/tests/.gitignore (1)

97-103: Verify intent of Compiler_Features ignore list changes.

You added 39–42 and still list 36–38. If 36–38 are meant to be tracked (unignored), please remove them; if they should remain ignored, keep all consistently. Consider keeping this section sorted to reduce future diffs.

ACE/tests/Chrono_Test.cpp (3)

24-35: Use safe formatter for time_t in logs.

On platforms where time_t is 64-bit, %d is unsafe. Use %: for time_t in ACE logging.

-                ACE_TEXT ("Expected <sec=%d,usec=%d> - got <sec=%d,usec=%d>\n"),
-                what, expect_sec, expect_usec, tv.sec (), tv.usec ()));
+                ACE_TEXT ("Expected <sec=%:,usec=%d> - got <sec=%:,usec=%d>\n"),
+                what, expect_sec, expect_usec, tv.sec (), tv.usec ()));

307-315: Fix expected values in error messages (typos only).

Messages still say 3300 us; the checks expect 303000 and 302600.

-                ACE_TEXT ("of 300 ms. Expected <sec=2,usec=3300> - got <sec=%d,")
+                ACE_TEXT ("of 300 ms. Expected <sec=2,usec=303000> - got <sec=%d,")
-                ACE_TEXT ("of 400 us. Expected <sec=2,usec=3300> - got <sec=%d,")
+                ACE_TEXT ("of 400 us. Expected <sec=2,usec=302600> - got <sec=%d,")

Also applies to: 321-324


352-355: Spelling: “substracting” → “subtracting”.

Update log messages for clarity.

-                ACE_TEXT ("unexpected value after substracting an ACE_Time_Value ")
+                ACE_TEXT ("unexpected value after subtracting an ACE_Time_Value ")

(Apply to all occurrences in these ranges.)

Also applies to: 376-382, 400-405, 424-429, 471-476

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 222db9e and b226740.

📒 Files selected for processing (4)
  • ACE/NEWS (1 hunks)
  • ACE/ace/Time_Value.h (3 hunks)
  • ACE/tests/.gitignore (5 hunks)
  • ACE/tests/Chrono_Test.cpp (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: VS2022Release64
  • GitHub Check: VS2022WChar
  • GitHub Check: VS2022Debug64Cxx17
  • GitHub Check: VS2022Release32
  • GitHub Check: MINGW64-gcc
  • GitHub Check: ubuntu-24.04 g++-10 ACE for TAO
  • GitHub Check: ubuntu-24.04 clang++-20 c++23
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e compact
  • GitHub Check: ubuntu-24.04 clang++-20
  • GitHub Check: ubuntu-24.04 clang++-16
  • GitHub Check: ubuntu-22.04 clang++-13
  • GitHub Check: ubuntu-24.04 clang++-14
  • GitHub Check: ubuntu-22.04 g++-10
  • GitHub Check: ubuntu-24.04 g++-11
  • GitHub Check: ubuntu-22.04 g++-9
  • GitHub Check: ubuntu-24.04 clang++-15
  • GitHub Check: ubuntu-22.04 clang++-12
  • GitHub Check: ubuntu-24.04 g++-14
  • GitHub Check: ubuntu-24.04 g++-12
  • GitHub Check: alpine-3.18
🔇 Additional comments (8)
ACE/tests/.gitignore (4)

120-120: Confirm ignoring Future_Stress_Test.

Stress tests are often excluded from default runs. If CI relies on this being ignored, LGTM; otherwise, consider enabling it for periodic runs.


163-163: Multicast_Interfaces_Test ignore status changed — confirm.

This test can be platform/network dependent. Please confirm the change aligns with CI environments.


229-231: Singleton_Test and SOCK_Acceptor_Test ignore changes.

SOCK_Acceptor_Test has historically had intermittent platform differences. Please confirm this change is intentional and CI-ready.


270-270: TSS_Static_Test ignore status — OK.

No concerns; consistent with other TSS tests’ handling.

ACE/ace/Time_Value.h (2)

271-276: Delegating +=(duration) to +=(ACE_Time_Value) — good simplification.

Reduces duplication and centralizes normalization. LGTM.


286-291: Delegating -=(duration) to -=(ACE_Time_Value) — good simplification.

Consistent with += path; no issues.

ACE/tests/Chrono_Test.cpp (1)

111-112: Nice coverage for mixed-unit rounding.

The 1120ms case validates microsecond carry correctly. LGTM.

ACE/NEWS (1)

4-5: NEWS entry is concise and accurate.

Matches the code changes and tests. LGTM.

@jrw972 jrw972 merged commit 61ca42f into DOCGroup:master Sep 3, 2025
39 checks passed
iguessthislldo added a commit to iguessthislldo/ACE_TAO that referenced this pull request Sep 4, 2025
This is a backport of DOCGroup#2462

`ACE_Time_Value` currently doesn't accept a `std::chrono::duration` with
`Rep` that's a floating point type because it's using the modulus
operator to separate the microseconds (`duration % seconds(1)`) and
trying to use modulus with floating points causes a compile error.

This changes it to use subtraction from the whole number of seconds
(`duration - sec`) and adds a test for it.

Also:
- Simplify the `-=` and `+=` ops of `ACE_Time_Value`
- Rewrite some of the testing in `Chrono_Test.cpp`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants