X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/cfc4ba97c3596db1105abc17692a54185cfd3a30..523b2e0f1ece77c569f6db4c040886ed3124512e:/luatz/timetable.lua?ds=sidebyside diff --git a/luatz/timetable.lua b/luatz/timetable.lua index 3bb7689..10af170 100644 --- a/luatz/timetable.lua +++ b/luatz/timetable.lua @@ -1,3 +1,4 @@ +local strftime = require "luatz.strftime".strftime local strformat = string.format local floor = math.floor local function idiv ( n , d ) @@ -143,7 +144,20 @@ function timetable_methods:rfc_3339 ( ) return strformat ( "%04u-%02u-%02uT%02u:%02u:%06.3f" , self:unpack ( ) ) end -local timetable_mt = { +function timetable_methods:strftime ( format_string ) + return strftime ( format_string , self ) +end + +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 ) @@ -152,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 )