Open raupachz opened 5 years ago
I think decimal hours would be in scope for ThreeTen-Extra. They are tricky because they are decimals, and TemporalField
only handles integer numbers. If they can be expressed using integer numbers then things might be easier.
The proprietary class I am using at the moment uses BigDecimal
and with a scale of two, but is not aligned with any interfaces of java.time.
Would it make sense to create TemporalField
for the fractional digits? The integer numbers would be from 0 to 99 if we stick to the scale of 2.
Of course, some operations would not be possible. You could get the Hours field but not the minutes or second field.
Sorry, I am not that familiar with the internals of JSR 310.
What I am trying to do is create a class DecimalHours
that stores an amount of time in decimal representation, for example 3.5 hours
. Instead of base 60 we are using base 100 for the minutes. Therefore DecimalHours
needs to implement TemporalAmount
. Internally we could use BigDecimal
with a scale of 2 or a long
that stores decimal minutes. One hundred decimal minutes accounts for one hour. The hour part is no different from our base 60 hour only the way we treat fractions are different.
But what TemporalUnits
are supported by DecimalHours
? Does it make sense to use MINUTES
and HOURS
? Introduce a whole new TemporalUnit
?
Yes, you'll need a new TemporalUnit
. You can only reuse one if it has the same meaning, ie. if a decimal hour equals a standard hour. You should avoid BigDecimal
and just use a long
I think. You can divide/remainder by 100 as necessary,
I came here to say this is something we also would love to see. Of course we can deal with decimal hours on our own, it's not impossible given the limited amount of features we need, but obviously I looked at java.time and threeten-extra for existing solutions only to find it cumbersome.
In the end we went with something like Temporals.durationToDoubleSeconds()
etc. for decimal hours, but even that is not simple to get right.
I think this problem can take inspiration in java.time.Duration
and org.threeten.extra.Hours
Duration
uses two fields representing seconds and nanoseconds. Derived DecimalHours can store hours and (real)nanoseconds for compatibility with java.time API. Methods outside time API then would use on fly conversion to BigDecimal
representing hours with 13 decimal places (1 nanosecond = 0.0000000000003 hours)
Hi there,
just checking if this is something worth pursuing/contributing to Threeten-Extra. In Germany many accounting systems, payroll systems, time tracking systems have the concept of Industrieminuten (industry minutes) and Industriestunden (industry hours).
Industrieminuten allow the decimal representations of elapsed time. One Industriestunde equals 100 minutes. One Industrieminute is therefore 36 seconds in actual time.
Examples:
The advantages of this system are easier addition and a more compact visual representation of elapsed time. An addition to Threeten-Extra would improve integration with legacy software. With easier addition I am not talking about cpu cycles, but a person using an actual calculator or something like MS Excel.
Are there similar concepts in other countries? Thoughts?
References: https://de.wikipedia.org/wiki/Industrieminute https://en.wikipedia.org/wiki/Decimal_time