X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/abb29b0b113102a7dea3e4691a853ee20e30f614..6237e6cb540b93ff099dcbacdf26d155ea330df8:/src/timetable.lua?ds=sidebyside diff --git a/src/timetable.lua b/src/timetable.lua index b58ad0f..e7f2816 100644 --- a/src/timetable.lua +++ b/src/timetable.lua @@ -102,12 +102,16 @@ local function normalise ( year , month , day , hour , min , sec ) return year , month , day , hour , min , sec end +local leap_years_since_1970 = leap_years_since ( 1970 ) local function timestamp ( year , month , day , hour , min , sec ) - return 60*60*24*( - year * year_length ( year ) - + month * month_length ( month , year ) - + day - ) + year , month , day , hour , min , sec = normalise ( year , month , day , hour , min , sec ) + + local days_since_epoch = day_of_year ( day , month , year ) + + 365 * ( year - 1970 ) + -- Each leap year adds one day + + ( leap_years_since ( year - 1 ) - leap_years_since_1970 ) - 1 + + return days_since_epoch * 60*60*24 + hour * (60*60) + min * 60 + sec