Download the PHP package org_heigl/dateintervalcomparator without Composer
On this page you can find all versions of the php package org_heigl/dateintervalcomparator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download org_heigl/dateintervalcomparator
More information about org_heigl/dateintervalcomparator
Files in org_heigl/dateintervalcomparator
Package dateintervalcomparator
Short Description Compare two DateInterval-Objects with one another
License MIT
Informations about the package dateintervalcomparator
DateIntervalComparator
Compare two DateInterval-Objects with one another.
Installation
DateIntervalComparator is best installed using composer
composer require org_heigl/dateintervalcomparator
Usage
The uses the same return values all comparison-functions in PHP use. When the first value is smaller than the second it returns -1, if the first is greater than the second it returns 1 and when both are equals it returns 0. The method can therefore be used as callback to sort arrays.
This library assumes that the compared intervals are sensible and alike. Comparing 3 months and 4 days against 5 months and 7 days is what this library is made for. It's not been made for comparing 3 months and 4 days against 94 days. Due to the different number of days in a month this comparison will be different depending on the start-date and we do want to compare only the Intervals and not the resulting end-dates!
As long as the values do not exceed their moduli (e.g. a value of 13 for month or 25 for the hour) you are on the safe side.
You can even enforce this safe side by setting . That will then throw an exception when one of the values for month, day, hour, minute or second will exceed the values 12, 31, 24, 60 and 60 resp.
Caveat/Limitations
Take care! DateIntervals can be nasty!
Due to their nature DateIntervals do not take Date or Time into account! So might or might not be the same as ! This Library will compare on a "same entity"-level. So first years are compared, then months, then weeks and so on. When you have an interval that is describing only 55 weeks and compare that to one that is only describing one year, the one year will be considered greater even though 55 weeks are more. So you should only compare comparable intervals!
The same can happen with f.e. and You'd think they are the same, but consider DaylightSavingsTime and they suddenly might not be the same! So currently the would be considered the "higher" one.
License
This library is published under the MIT-License. Find a copy in the LICENSE.md-File.