X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/f2fc0b840b9b1ce58e8c9ca0a858f613bb3bd8be..8ce2a7db5c4ea48a342b665385a54514c79d30bb:/luatz/timetable.lua diff --git a/luatz/timetable.lua b/luatz/timetable.lua index 6a39a13..10af170 100644 --- a/luatz/timetable.lua +++ b/luatz/timetable.lua @@ -148,7 +148,16 @@ function timetable_methods:strftime ( format_string ) return strftime ( format_string , self ) end -local timetable_mt = { +local timetable_mt + +local function coerce_arg ( t ) + if getmetatable ( t ) == timetable_mt then + return t:timestamp ( ) + end + return t +end + +timetable_mt = { __index = timetable_methods ; __tostring = timetable_methods.rfc_3339 ; __eq = function ( a , b ) @@ -157,6 +166,9 @@ local timetable_mt = { __lt = function ( a , b ) return a:timestamp ( ) < b:timestamp ( ) end ; + __sub = function ( a , b ) + return coerce_arg ( a ) - coerce_arg ( b ) + end ; } local function cast_timetable ( tm )