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
date_time created with decimals #221
Comments
Your observation is right that Boost 1.81 fixed the behavior of Most notably the code before had a bug which is clearly visible on inspection:
I.e. there is a division which should have been a multiplication.
What actual errors? Or did you just refer to the changed behavior?
This is true: I also agree that the "fixed" behavior is odd as it only applies to the ICU backend and all other backends set the nanoseconds directly to zero: locale/src/boost/locale/util/gregorian.cpp Line 477 in 299381b
I don't understand this. As the difference caused by the change is always less than a second it won't be noticeable in
Still to avoid any confusion I'd actually opt for a (breaking!) change modifying But then: Why introduce a breaking change if the only current issue is, that |
Thanks for your explanation that I can understand more on the change.
|
Yes this is a difference. But I don't understand why it has to be an integer seconds. I.e. what error the fractional part actually causes.
If you add 1 second to a timepoint than the difference is exactly 1. If you create time_points at different times than the difference between them in seconds will be the same independent of their fractional part/milliseconds. So I don't understand what you are referring to:
You are right that the subseconds are only settable via
A |
thanks for your patience to understand
hope the above better explain my thought |
Sorry I still am missing something:
But the time as printed and shown for all purposes of Boost.Locale is 4:0:0 as set. The subseconds are not observable outside of
Again: In the context of Boost.Locale I don't see this. I adjusted your code a bit to try it just now:
So when using Boost.Locale to calculate the difference in seconds you get exactly zero as expected and as before. And using the
But what exactly do you do that you run into the problem? As shown using
Yes, that would mean storing the value internally as nanoseconds. However e.g. ICU, i.e. the backend you are using, stores it as a double so there is no way to change that.
Yes that would be possible but as mentioned it may lead to another kind of unexpected behavior as the value won't be as set in all cases while currently an addition of 1 second n times leads to a difference of n seconds. So I'm rather inclined to never set subseconds by default. I.e. the default ctor will return integer seconds and subseconds are only supported through custom calendars or |
since difference internal will just subtract the values (with subseconds), error occurs. workaround is to trim (floor) to seconds before calling difference.
In summary, the recent update only benefits get now() with subseconds if it is not handling it. But in some use cases as mine I need to trim the subseconds. As long as the library remain precision in seconds and users may not have intention or benefit to get current time with subseconds. The library internals like 'difference' may not handle subseconds right. To be safe, all vars to have be trimmed when create and before calling any library function which should be correct with ZERO subseconds. If it is believed good to save the subsecond value, it seems having a way to set the subseconds other than with a random system subseconds should work. Same behavior as before, if set period::nanosecond(something), it is set. Otherwise get the system portion. Then difference is correct. And may also be other internal functions of the library. The fractional part should have no impacts as long as the value can be set. I am not sure if it need huge effort to enhance. Just for your consideration.
The library features will just as it is now and extended to support subseconds with ICU backend.. ICU itself should have tackle operations on subseconds if it supports it. |
I see now, thank you! More specifically it seems that:
Note however that this is at least consistent with how e.g. days vs hours are handled. But at least there you can set both. TBH I don't really see a value in having the subseconds anymore especially given the confusing semantic as above where the subseconds lead to unexpected second-differences when not handled explicitely. Especially as the fact that the subseconds were always zero went unreported for all that time. Not only that: All other backends store the time as This means that |
good. It is rather to give back time_t. Some of the unittests may also have assumptions on integers so similar problems may just pass. More work may need to enable subseconds. anyhow I would like to thank you for maintenance of the library. It is crucial for c++ programs to deal with locale issues. |
ICU was the only backend storing subseconds in its calendar and hence reported fractional times in `date_time::time()` However outside of `date_time::time(floor(time))` there was no way setting those milli/nanoseconds. This leads to unexpected behavior for comparisons of seemingly identical time points, especially as it depends on the backend. Closes #221
ICU was the only backend storing subseconds in its calendar and hence reported fractional times in `date_time::time()` However outside of `date_time::time(floor(time))` there was no way setting those milli/nanoseconds. This leads to unexpected behavior for comparisons of seemingly identical time points, especially as it depends on the backend. Closes #221
ICU was the only backend storing subseconds in its calendar and hence reported fractional times in `date_time::time()` However outside of `date_time::time(floor(time))` there was no way setting those milli/nanoseconds. This leads to unexpected behavior for comparisons of seemingly identical time points, especially as it depends on the backend. Closes #221
I've updated to fedora 39 from 38, so the boost library is now 1.81.0 and errors start happening.
when created a new date_time var0 = period::year(2024) + period::month(0) + period::day(1) + period::hour(0) + period::minute(0) + period::second(0)
you can discover the var0.time() has decimals. and the decimal changes every other run of the program.
This seems the subseconds was set from the current time but there is no way the library can set it. say period::microsec or so.
This also create inaccuracy on difference() and (var1 - var0) / period::second()
I use temporary workaround as:
The text was updated successfully, but these errors were encountered: