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

Add parts to Duration #15

Closed
MMauro94 opened this issue Aug 30, 2019 · 4 comments
Closed

Add parts to Duration #15

MMauro94 opened this issue Aug 30, 2019 · 4 comments

Comments

@MMauro94
Copy link

Hi! First of all thanks for the great work!

Would it be possible to add the following functions to the Duration class:

  • toDaysPart()
  • toHoursPart()
  • toMinutesPart()
  • toSecondsPart()
  • toNanosPart()

They should mimic the behavior of java.time.Duration.

As far as I can see the logic is already implemented in the __toString() function, so it should be quite easy to extract into functions.

@BenMorel
Copy link
Member

Sure!

Do you know why Java has duplicate method names here? toDays() vs toDaysPart(), toHours() vs toHoursPart() etc.?

Theirs docs are mostly copy/pastes, so I can just assume these methods are doing the same thing. The only difference being that the methods ending in Part() have been introduced in Java 9, so maybe they plan to deprecated the old ones?

@MMauro94
Copy link
Author

The toX() functions return the total number of units, instead of their "part".

Example:

Duration d = Duration.parse("PT1H30M20S"); //1 hour, 30 minutes, 20 seconds

d.toHours(); // 1
d.toHoursPart(); // 1

d.toMinutes(); // 90
d.toMinutesPart(); // 30

d.toSeconds(); // 5420
d.toSecondsPart(); // 20

@BenMorel
Copy link
Member

Oh right, this makes sense. I'll add both versions then!

@BenMorel
Copy link
Member

Implemented and released in 0.1.14!

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

No branches or pull requests

2 participants