I could do Time(12).instant, but that is probably not good practice. Doing Time(12) - Time(0) seems odd. Is there some proper way to convert Time to Period?
One thing that motivates this question is that I want to calculate the Period from a Time to the end of day. However, I cannot do Time(24) - Time(x) because the Time constructor will not allow 24 (out of range).
Thanks! I didn’t know about typemax. That’s interesting.
That solution is interesting, but isn’t much better than Time(x).instant because it relies on (or reveals) the implementation details of Time (that it is stored in nanoseconds).
The more I think about it now, the more I think I just need to write my own Base.convert(Period, Time) and use Time.instant. If that ever changes, there’s only a single place to fix.
I was just asking if that conversion already existed somewhere and I just couldn’t find it.
That’s curious. That only works if you have all zeros after the hour. DateTime(1,1,1,24,0,0,1) gives error. Putting that 24 in hours rolls it over to 0 time the next day. Interesting, but probably not helpful to what I’m trying to do.
I think that’s the same as the first suggestion above. It leaks the details of Time implementation. If I’m ok leaking that, I might as well just do Time(x).instant because that would also be the highest performing (which this may be used in some big loops so may matter).