choptastic / qdate

Erlang date, time, and timezone management: formatting, conversion, and date arithmetic
http://sigma-star.com/blog/post/qdate
MIT License
246 stars 82 forks source link

Differences for ranges #30

Open choptastic opened 7 years ago

choptastic commented 7 years ago

Qdate could benefit from more date arithmetic in the sense of finding out the difference between two dates.

difference_days(Date1, Date2) would return the number of days between those two dates.

difference_minutes(Date1, Date2) would do the same (though this is easy because of the easy conversion to unix timestamps - same with seconds (obviously), hours.

calculating differences of days with respect is more complicated if a range crosses a daylight savings time.

My gut is telling me that the answer to both is to strip off any time component and use just dates, then convert to gregorian days with calendar:date_to_gregorian_days(Date). From there, the math is simple. Maybe the time component could then be re-added to the original dates and the time component compared to retrieve the fractional part of a day with compared times.

Something to chew on.