localp={}functionp._error(error_str)return'[[Category:Duration with input error]]<strong class="error">Error in Module:Hms: '..error_str..'</strong>'endfunctionp.main(frame)localargs=require('Module:Arguments').getArgs(frame,{wrappers={'Template:Duration','Template:Duration/sandbox'}})localtmp=args.durationorargs[1]or''localduration={}iftonumber(args[1])orargs[2]orargs[3]thenifargs[4]thenreturnp._error('Parameter number 4 should not be specified')endifnotargs[1]orargs[1]==''thenduration={args[2]or0,args[3]or0}elseduration={args[1],args[2]or0,args[3]or0}endtmp=nilfork,vinipairs(duration)doduration[k]=tonumber(v)ifnotduration[k]thenreturnp._error('Invalid values')endendelseifargs.horargs.morargs.sthenifnotargs.horargs.h==''thenduration={args.mor0,args.sor0}elseduration={args.h,args.mor0,args.sor0}endtmp=nilfork,vinipairs(duration)doduration[k]=tonumber(v)ifnotduration[k]thenreturnp._error('Invalid values')endendelseifmw.ustring.find(tmp,'class="duration"',1,yes)thenreturntmpend-- if there is already a microformat, don't do anythingduration=mw.text.split(mw.ustring.match(tmp,'%d*:?%d+:%d+%.?%d*')or'',':')-- split into tableifduration[4]thenreturnp._error('Maximum of two colons allowed')endfork,vinipairs(duration)doduration[k]=tonumber(v)or0end-- convert values to numbersendifduration[3]thenif(duration[1]+duration[2]+duration[3])==0thenreturnnilendif(duration[1]~=math.ceil(duration[1]))or(duration[2]~=math.ceil(duration[2]))thenreturnp._error('Hours and minutes values must be integers')endifduration[3]>=60thenreturnp._error('Seconds value must be less than 60')endifduration[2]>=60thenreturnp._error('Minutes value must be less than 60 if hours value is specified')endifduration[2]<10thenduration[2]='0'..duration[2]end-- zero paddingifduration[3]<10thenduration[3]='0'..duration[3]endduration='<span class="duration"><span class="h">'..duration[1]..'</span>:<span class="min">'..duration[2]..'</span>:<span class="s">'..duration[3]..'</span></span>'elseifduration[2]thenif(duration[1]+duration[2])==0thenreturnnilendifduration[1]~=math.ceil(duration[1])thenreturnp._error('Hours and minutes values must be integers')endifduration[2]>=60thenreturnp._error('Seconds value must be less than 60')endifduration[2]<10thenduration[2]='0'..duration[2]end-- zero paddingduration='<span class="duration"><span class="min">'..duration[1]..'</span>:<span class="s">'..duration[2]..'</span></span>'elseduration=''endiftmpandtmp~=''thenifduration~=''thentmp=mw.ustring.gsub(tmp,'%d*:?%d+:%d+%.?%d*',duration,1)elsetmp=tmp..' [[Category:Duration without hAudio microformat]]'endelseifduration~=''thentmp=durationendendreturntmpendreturnp