A Duration is a length of time that may vary with calendar date and time. It can be used to modify a date.
When modify dates using Durations (Day | Month | Week | Year) this module compensates for day light saving hour variations to minimise the scenarios that cause the Hour field in the result to be different to the input date. It can't completely avoid the hour changing as some hours are not a real world date and hence will modify the hour more than the Duration modified.
This behaviour is modelled on momentjs so any observed behaviour that is not the same as momentjs should be raised as an issue.
Note adding or subtracting 24 * Hour units from a date may produce a different answer to adding or subtracting a Day if day light saving transitions occur as part of the date change.
Warning
Be careful if you add Duration Delta to a Date as Duration contains months and Years which are not fixed elapsed times like Period Delta, however if you really need a relative number of months or years then it may meet your needs.
A Duration is time period that may vary with with calendar and time.
Using Duration adding 24 hours can produce different result to adding 1 day.
A multi granularity duration delta.
This does not contain week like Period.DeltaRecord. It does contain month and year.
All zero delta. Useful as a starting point if you want to set a few fields only.
Return a Period representing date difference. date1 - date2.
If you add the result of this function to date2 with addend of 1 will return date1.
Differences to Period.diff
When adding a Duration DeltaRecord to a date. The larger granularity fields are added before lower granularity fields so Years are added before Months before Days etc.
Example 1. days in 2016/05 (May) = 31 days in 2016/04 (Apr) = 30 days in 2016/03 (Mar) = 31
days in 2015/03 (Mar) = 31
diff of "2016/05/15" "2015/03/20" result naive field diff. year 1, month 2, day -5
days "2015/03/20" to "2015/04/01" (31 - 20) = 11 days (12). still in march with 11. days "2015/04/01" to "2016/04/15" (15 - 1) = 14 days months "2016/04/15" to "2016/05/15" 1 months result field diff year 1, month 1, day 26
This logic applies all the way down to milliseconds.
Returns date1 - date2 as number of days to add to date1 to get to day date2 is on.
date1 - date2 in days.
Only calculates days difference and ignores any field smaller than day in calculation.
Copyright (c) 2016-2017 Robin Luiten
Add duration * count to date.