Convert seconds to compound duration: Difference between revisions

Content added Content deleted
m (→‎version 2: elided a blank line from the source.)
m (→‎{{header|Phix}}: (used iff a bit more))
Line 1,180: Line 1,180:
m = floor(s/60)
m = floor(s/60)
s = remainder(s,60)
s = remainder(s,60)
if integer(s) then
secs = sprintf(iff(integer(s)?"%ds":"%3.2fs"),s)
secs = sprintf("%ds",s)
else
secs = sprintf("%3.2fs",s)
end if
if m=0 then
if m=0 then
return sprintf("%s%s",{minus,secs})
return sprintf("%s%s",{minus,secs})
end if
end if
s = round(s)
s = round(s)
secs = iff(s=0?"":sprintf(" and %02ds",s))
if s=0 then
secs = ""
else
secs = sprintf(" and %02ds",s)
end if
h = floor(m/60)
h = floor(m/60)
m = remainder(m,60)
m = remainder(m,60)
Line 1,199: Line 1,191:
return sprintf("%s%s%s",{minus,elapzd(m,"minute"),secs})
return sprintf("%s%s%s",{minus,elapzd(m,"minute"),secs})
end if
end if
mins = iff(m=0?"":", "&elapzd(m,"minute"))
if m=0 then
mins = ""
else
mins = ", "&elapzd(m,"minute")
end if
if h<24 then
if h<24 then
return sprintf("%s%s%s%s",{minus,elapzd(h,"hour"),mins,secs})
return sprintf("%s%s%s%s",{minus,elapzd(h,"hour"),mins,secs})