Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time_point to string conversion for large and negative values #37

Merged
merged 4 commits into from
Oct 30, 2018

Conversation

wanderingbort
Copy link
Contributor

This fixes two issues:

  1. time_points which were more than 32bits of seconds from the epoch would wrap due to the silent integer narrowing that happens in uint32_t time_point::sec_since_epoch() const as a result those time points would translate to the wrong ISO string.

  2. negative time_points are representable due to being composed of the fc::microsecond type which can store negative values. However, these have no representable ISO string so they now degrade to a duration in terms of seconds with 3-digits of precision for millisecond output. Effectively providing the same base unit as the ISO string (seconds) and the extra resolution.

Note: it is probably worthwhile to consider if changing ::sec_since_epoch() const and removing the express-ability of negative points in time is worthwhile for master. This is being made against a patch release of a downstream product so, it should not make breaking changes to the data types.

src/time.cpp Outdated
// negative time_points are non-sensical but expressible with the current constraints
uint64_t secs = (uint64_t)(-count) / 1000000ULL;
uint64_t msec = ((uint64_t)(-count) % 1000000ULL) / 1000ULL;
return string("-") + to_string(secs) + "." + padded_ms(msec) + "s";
Copy link
Contributor

@heifner heifner Oct 30, 2018

Choose a reason for hiding this comment

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

Appends an "s" to the end of negative time point. All the examples I see with boost posix time and iso specs, none include a trailing s.

https://www.boost.org/doc/libs/1_68_0/doc/html/date_time/posix_time.html

@heifner heifner merged commit 9adee18 into v1.4.x Oct 30, 2018
@heifner heifner deleted the feature/fix-large-ISO-timepoints branch October 30, 2018 14:54
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.

3 participants