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

Decimal hours #121

Open
raupachz opened this issue Jan 17, 2019 · 6 comments
Open

Decimal hours #121

raupachz opened this issue Jan 17, 2019 · 6 comments

Comments

@raupachz
Copy link
Contributor

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:

  • 10 hours 30 minutes = 10,5
  • 2 hours 48 minutes = 2,8

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

@jodastephen
Copy link
Member

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.

@raupachz
Copy link
Contributor Author

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.

@raupachz
Copy link
Contributor Author

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 ?

@jodastephen
Copy link
Member

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,

@JanecekPetr
Copy link

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.

@Lukiz
Copy link

Lukiz commented Oct 16, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants