Skip to content

What exactly is the difference between Interval.length(), Interval.count(), and DateTime.diff()? #1434

Answered by icambron
arcataroger asked this question in Q&A
Discussion options

You must be logged in to vote

Durations

Durations are a pile of units. Think of it as like { days: 1, hours: 48, minutes: 3, seconds: 4 }. The various methods like shiftTo can move data between the units. Anyway, that duration would return 1 for days, since the day component is 1. as("days") converts it to days and would return 3.something. If you don't specify the units in the diff() call, you get the diff in milliseconds (i.e. the duration is like {milliseconds: someHugeNumber}, so the days component is 0. See here for more.

Interval.length(unit) vs Duration.as(unit)

These are not always the same. See here

Interval.count

No, count("days") checks how many calendar days are included in the interval. So if the interval…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@arcataroger
Comment options

Answer selected by arcataroger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants