From e805091750479ed1cffa5a6b049dbcfcebab0844 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 30 Aug 2013 14:29:41 -0400 Subject: [PATCH] src/timetable: Comparison operators can take raw timestamps --- src/timetable.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 ; } -- 2.39.5