tonysamperi / ts-luxon

Typescript based Luxon: ⏱ A library for working with dates and times in TS and JS (immutable)
https://tonysamperi.github.io/ts-luxon
MIT License
13 stars 3 forks source link

Feature Request #7

Closed btd1337 closed 1 year ago

btd1337 commented 1 year ago

Would it be possible to add the following functions to the library?

These last 3 should compare the day, month, and year as a whole

Thanks in advance!

tonysamperi commented 1 year ago

isTheSame is a function already... You use dto.isSame(otherDto, "day") and it does the comparison. isFuture and isPast are useless because you can do dto > otherDto or if Typescript complains about comparing not integer values, you can do dto.valueOf() > otherDto.valueOf().

Cheers.

btd1337 commented 1 year ago

@tonysamperi thanks for your answer and the isSame function explanation.

But...

The isFuture and isPast functions It's not in this way as you mentioned:

The feature I would like you to add would be like this:

date1.isFuture("day");
date1.isFuture(date2, "day")

date1.isPast("day");
date1.isPast(date2, "day")

Example:

date1 = "2023-07-25 10:00:00"

date2 = 2023-07-25 10:00:00
date1.isFuture(date2, "day")    // false

date3 = 2023-07-24 10:00:00
date1.isFuture(date3, "day")    // true

It would be very valuable if you reconsidered!

Thanks in advance

tonysamperi commented 1 year ago

@btd1337 easy peasy

dto.startOf("day") > otherDto And you can do the same using dto.diff(otherDto, "days") or something similar, I don't remember right know. Believe me. You can already do what you ask. Then if you often use this stuff, you can make your own Luxon helper to gather specific functions!

Cheers