From: daurnimator Date: Fri, 30 Aug 2013 18:29:41 +0000 (-0400) Subject: src/timetable: Comparison operators can take raw timestamps X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/e805091750479ed1cffa5a6b049dbcfcebab0844?ds=sidebyside src/timetable: Comparison operators can take raw timestamps --- diff --git a/src/timetable.lua b/src/timetable.lua index 8801623..d1cd534 100644 --- a/src/timetable.lua +++ b/src/timetable.lua @@ -151,14 +151,23 @@ function timetable_methods:rfc_3339 ( ) return strformat ( "%04u-%02u-%02uT%02u:%02u:%06.4g" , unpack_tm ( 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 ) - return a:timestamp() == b:timestamp() + return coerce_arg ( a ) == coerce_arg ( b ) end ; __lt = function ( a , b ) - return a:timestamp() < b:timestamp() + return coerce_arg ( a ) < coerce_arg ( b ) end ; }