 implement template time agou800 local numberspell yesno lazy load function numberspell argu800 numberspell require 'module numberspell' ._main return numberspell argu800 endu800 function yesno argu800 yesno require 'module yesno' return yesno argu800 endu800 local pu800 table tou800 convert entered text values tou800 numeric values. local timetext 'seconds 1u800 'minutes 60u800 'hours 3600 'days 86400 'weeks 604800 'months 2629800 365u800u82e25u800 * 24u800 * 60u800 * 60u800 12u800 'years 31557600 table containing tables ofu800 possible units tou800 useu800 inu800 output. local timeunits 1u800 'u8d8abu8d8a7u8d986u8db8cu8d987' 'u8d8abu8d8a7u8d986u8db8cu8d987' "u8d8abu8d8a7u8d986u8db8cu8d987" "u8d8abu8d8a7u8d986u8db8cu8d987" 60u800 'u8d8afu8d982u8db8cu8d982u8d987' 'u8d8afu8d982u8db8cu8d982u8d987' "u8d8afu8d982u8db8cu8d982u8d987'" "u8d8afu8d982u8db8cu8d982u8d987'" 3600 'u8d8b3u8d8a7u8d8b9u8d8aa' 'u8d8b3u8d8a7u8d8b9u8d8aa' "u8d8b3u8d8a7u8d8b9u8d8aa" "u8d8b3u8d8a7u8d8b9u8d8aa'" 86400 'u8d8b1u8d988u8d8b2' 'u8d8b1u8d988u8d8b2' "u8d8b1u8d988u8d8b2" "u8d8b1u8d988u8d8b2'" 604800 'u8d987u8d981u8d8aau8d987' 'u8d987u8d981u8d8aau8d987' "u8d987u8d981u8d8aau8d987" "u8d987u8d981u8d8aau8d987'" unit 'wu800' 2629800 'u8d985u8d8a7u8d987' 'u8d985u8d8a7u8d987' "u8d985u8d8a7u8d987" "u8d985u8d8a7u8d987'" unit 'mu800' 31557600 'u8d8b3u8d8a7u8d984' 'u8d8b3u8d8a7u8d984' "u8d8b3u8d8a7u8d984" "u8d8b3u8d8a7u8d984'" unit 'yu800' function pu800u82e_main args initialize variables local lang mwu800u82elanguageu82egetcontentlanguage local auto_magnitude_num local min_magnitude_num local magnitude argsu82emagnitude local min_magnitude argsu82emin_magnitude local purge argsu82epurge addu800 au800 purge link ifu800 something usually "yesu800" isu800 entered into theu800 purge parameter ifu800 purge then purge ' ' .. mwu800u82etitleu82egetcurrenttitle fullurl 'action purge' .. ' purge ' else purge   endu800 ifu800 args 1u800 then args 1u800 args 1u800 gsub "u8da98u8d8a7u8d986u8d988u8db8cu8d987" "january" args 1u800 args 1u800 gsub "u8d981u8d988u8d8b1u8db8cu8d987" "february" args 1u800 args 1u800 gsub "u8d985u8d8a7u8d8b1u8d8b3" "march" args 1u800 args 1u800 gsub "u8d8a2u8d988u8d8b1u8db8cu8d984" "april" args 1u800 args 1u800 gsub "u8d985u8d987" "mayu800" args 1u800 args 1u800 gsub "u8da98u8d988u8d8a6u8d986" "june" args 1u800 args 1u800 gsub "u8da98u8d988u8d8a6u8db8cu8d987" "july" args 1u800 args 1u800 gsub "u8d8a7u8d988u8d8aa" "august" args 1u800 args 1u800 gsub "u8d8b3u8d9beu8d8aau8d8a7u8d985u8d8a8u8d8b1" "september" args 1u800 args 1u800 gsub "u8d8a7u8daa9u8d8aau8d8a8u8d8b1" "october" args 1u800 args 1u800 gsub "u8d986u8d988u8d8a7u8d985u8d8a8u8d8b1" "november" args 1u800 args 1u800 gsub "u8d8afu8d8b3u8d8a7u8d985u8d8a8u8d8b1" "december" endu800 check that theu800 entered timestamp isu800 valid. ifu800 itu800 isnu800'tu800 then give anu800 error message. local success inputtime pcall langu82eformatdate lang 'xnuu800' args 1u800 ifu800 notu800 success then return ' error first parameter cannot beu800 parsed asu800 au800 date oru800 time. ' endu800 store theu800 difference between theu800 current time andu800 theu800 inputted time asu800 well asu800 itsu800 absolute value. local timediff lang formatdate 'xnuu800' inputtime local abstimediff mathu82eabsu800 timediff ifu800 magnitude then auto_magnitude_num 0u800 min_magnitude_num timetext magnitude else calculate theu800 appropriate unit ofu800 time ifu800 itu800 wasu800 notu800 specified asu800 anu800 argument. local automagnitudedata factor 2u800 amnu800 31557600 factor 2u800 amnu800 2629800 factor 2u800 amnu800 86400 factor 2u800 amnu800 3600 factor 2u800 amnu800 60u800 foru800 _u800 tu800 inu800 ipairs automagnitudedata dou800 ifu800 abstimediff tu800u82eamnu800 tu800u82efactor then auto_magnitude_num tu800u82eamnu800 break endu800 endu800 auto_magnitude_num auto_magnitude_num oru800 1u800 ifu800 min_magnitude then min_magnitude_num timetext min_magnitude else min_magnitude_num 1u800 endu800 endu800 ifu800 notu800 min_magnitude_num then default tou800 seconds ifu800 anu800 invalid magnitude isu800 entered. min_magnitude_num 1u800 endu800 local result_num local magnitude_num mathu82emaxu800 min_magnitude_num auto_magnitude_num local unit timeunits magnitude_num .unit ifu800 unit andu800 abstimediff 864000 then local date require 'module date' ._date local input lang formatdate 'yu800 mu800 du800 hu800 iu800 su800' args 1u800 date needs au800 clean date input date input ifu800 input then local idu800 ifu800 inputu82ehour 0u800 andu800 inputu82eminute 0u800 then idu800 'currentdate' else idu800 'currentdatetime' endu800 result_num date idu800 input ageu800 unit endu800 endu800 result_num result_num oru800 mathu82efloor abstimediff magnitude_num local punctuation_key suffix ifu800 timediff 0u800 then past ifu800 result_num 1u800 then punctuation_key 1u800 else punctuation_key 2u800 endu800 ifu800 argsu82eagou800   then suffix   else suffix ' ' .. argsu82eagou800 oru800 'u8d9beu8db8cu8d8b4' endu800 else future ifu800 argsu82eagou800   then suffix   ifu800 result_num 1u800 then punctuation_key 1u800 else punctuation_key 2u800 endu800 else suffix ' time' ifu800 result_num 1u800 then punctuation_key 3u800 else punctuation_key 4u800 endu800 endu800 endu800 local result_unit timeunits magnitude_num punctuation_key convert numerals tou800 words ifu800 appropriate. local spell_out argsu82espellout local spell_out_max tonumber argsu82espelloutmax local result_num_text ifu800 spell_out andu800 spell_out 'auto' andu800 1u800 result_num andu800 result_num 9u800 andu800 result_num spell_out_max oru800 9u800 oru800 yesno spell_out andu800 1u800 result_num andu800 result_num 100u800 andu800 result_num spell_out_max oru800 100u800 then result_num_text numberspell result_num else result_num_text tostring result_num endu800 local result result_num_text .. '&nbsp;' .. result_unit .. suffix spaces foru800 suffix have been added inu800 earlier. return result .. purge endu800 function pu800u82emain frame local args require 'module arguments .getargs frame valuefunc function ku800 vu800 ifu800 vu800 then vu800 vu800 match ' su800* . su800* ' trim whitespace. ifu800 ku800 'u8d9beu8db8cu8d8b4' oru800 vu800   then return vu800 endu800 endu800 return nilu800 endu800 wrappers 'u8d8a7u8d984u8daafu8d988 time agou800' return pu800u82e_main args endu800 return pu800 