roscpp_core icon indicating copy to clipboard operation
roscpp_core copied to clipboard

rostime: Added useful time and duration constants.

Open peci1 opened this issue 5 years ago • 4 comments

For Time, WallTime and SteadyTime, I added static constants MIN, MAX, ZERO and UNINITIALIZED.

For Duration and WallDuration, I added static constants MIN, MAX, ZERO, NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK and YEAR.

In the header files, I added explicit specialization declarations for each of the constants. The build and tests succeeded even without these definitions, but clang suggested to add them and I did so.

I'm not sure if YEAR should represent 365 days or 365.2425. I vouch for the latter as it yields smaller errors if you count with large durations (e.g. in 10 years, the 365-day year gives you 2 day error, whereas 365.2425 day has error somewhere around half a day).

These constants are mainly syntactic sugar, but I imagine they could become used over time when people know about them.

peci1 avatar Jul 09 '20 01:07 peci1

The tests are kind of just repeating the definitions, but I couldn't think of anything better...

peci1 avatar Jul 09 '20 01:07 peci1

I'm not sure if YEAR should represent 365 days or 365.2425. I vouch for the latter as it yields smaller errors if you count with large durations (e.g. in 10 years, the 365-day year gives you 2 day error, whereas 365.2425 day has error somewhere around half a day).

Because of this uncertainty - the duration class is simply not designed to handle things like leap years - I would rather not provide a constant for it. Either value will surprise a non-significant amount of users.

dirk-thomas avatar Jul 13 '20 20:07 dirk-thomas

Because of this uncertainty - the duration class is simply not designed to handle things like leap years - I would rather not provide a constant for it.

Good point, I'll remove the constant for year

peci1 avatar Jul 13 '20 21:07 peci1

Wow, this PR has somehow slipped through my fingers... But I found it again! I removed the constant for YEAR due to the mentioned ambiguity. I also removed WEEK as it doesn't seem very useful to me.

@dirk-thomas Could you please re-review?

peci1 avatar Aug 18 '22 23:08 peci1

@dirk-thomas friendly ping

peci1 avatar Apr 09 '23 21:04 peci1

@peci1 Sorry, I am not involved in the project anymore for more than 2.5 years.

dirk-thomas avatar May 01 '23 03:05 dirk-thomas

In that case, this needs to be updated:

https://github.com/ros/roscpp_core/blob/72ce04f8b2849e0e4587ea4d598be6ec5d24d8ca/rostime/package.xml#L7

(and probably others)

Do you know who the maintainer is?

peci1 avatar May 01 '23 05:05 peci1

Unfortunately I don't know. Since the git history doesn't show any new commits, maybe ask on discourse?

dirk-thomas avatar May 02 '23 00:05 dirk-thomas

@ros-pull-request-builder retest this please

peci1 avatar Jun 06 '23 16:06 peci1

Merging without other approvals since I'm the only maintainer.

peci1 avatar Jun 06 '23 16:06 peci1

@Mergifyio backport melodic-devel

peci1 avatar Jun 14 '23 09:06 peci1

backport melodic-devel

✅ Backports have been created

mergify[bot] avatar Jun 14 '23 09:06 mergify[bot]