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

Easier ways to analyze a DateTimePeriod instance #428

Open
nesk opened this issue Aug 31, 2024 · 3 comments
Open

Easier ways to analyze a DateTimePeriod instance #428

nesk opened this issue Aug 31, 2024 · 3 comments
Labels
waiting for clarification Additional information is needed from the user

Comments

@nesk
Copy link

nesk commented Aug 31, 2024

The Duration class in the standard library provides everything you need to analyze its state:

  • isNegative
  • isPositive
  • a ZERO instance

Those things are missing in the DateTimePeriod class.

Would you consider adding those features?

@dkhalanskyjb
Copy link
Collaborator

ZERO is okay is there are some use cases for it, but isNegative and isPositive don't make sense for DateTimePeriod because of periods like 1 month - 30 days. If you add this period to 2024-01-01 you'll get a later date, and if you add it to 2024-02-01, you'll get an earlier date:

val date1 = LocalDate(2024, 1, 1)
val date2 = LocalDate(2024, 2, 1)
val period = DatePeriod(months = 1, days = -30)
println(date1 < date1 + period) // true
println(date2 < date2 + period) // false

(https://pl.kotl.in/oTONoY3XP)

Do you know of any use cases for ZERO?

@nesk
Copy link
Author

nesk commented Sep 2, 2024

I can see your point for negative/positive, I understand.

ZERO would be mainly used for verifications. I've just done a subtraction two dates, is it equal to zero or no?

@dkhalanskyjb
Copy link
Collaborator

dkhalanskyjb commented Sep 2, 2024

Can't one write date1 == date2 instead of date1 - date2 == ZERO?

@dkhalanskyjb dkhalanskyjb added the waiting for clarification Additional information is needed from the user label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for clarification Additional information is needed from the user
Projects
None yet
Development

No branches or pull requests

3 participants
@nesk @dkhalanskyjb and others