`boost::posix_time::duration` multiplication/division limited to `int`.

Open
#246 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
backend

Research direction

Start in include/boost/date_time/time_duration.hpp at the operator overloads linked in the issue, and reproduce the unsigned multiplication example with BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG enabled. Compare the current int behavior with the requested unsigned or 64-bit support and verify that the resulting duration preserves the expected nanosecond total.

Written by the indexing model from the issue text.

Description

The operator*(), operator*=(), operator/(), and operator/=() currently only support int parameters [see boost::posix_time::duration].

I tried to use it as follows:

std::uint64_t const timedeltaInTensOfNanoseconds = 2793555578;
boost::posix_time::time_duration const duration = boost::posix_time::nanoseconds(10) * timestamp;
// duration.total_nanoseconds() = -15014117180

[I did define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG.]

What did work as expected was:

std::uint64_t const timedeltaInTensOfNanoseconds = 2793555578;
boost::posix_time::time_duration const duration = boost::posix_time::nanoseconds(10 * timestamp);
// duration.total_nanoseconds() = 27935555780

Would it be possible to extend the parameter type for above functions to at least support unsigned as well? Or even extend it to 64-bit types? Or make them template-methods [with a concept limiting them to ints and floats]?

Dominant language
C++
Stars
70
Forks
99
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/date_time

All issues in boostorg/date_time

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.