Convert seconds to compound duration: Difference between revisions
Content deleted Content added
Line 1,361: | Line 1,361: | ||
seconds=int(abs(seconds)) |
seconds=int(abs(seconds)) |
||
if seconds=0 then print "Program complete.": end |
if seconds=0 then print "Program complete.": end |
||
UnitsFound=0: LastFound$="" |
|||
years=int(seconds/31449600): seconds=seconds mod 31449600 |
years=int(seconds/31449600): seconds=seconds mod 31449600 |
||
if years then UnitsFound+=1: LastFound$="years" |
|||
weeks=int(seconds/604800): seconds=seconds mod 604800 |
weeks=int(seconds/604800): seconds=seconds mod 604800 |
||
if weeks then UnitsFound+=1: LastFound$="weeks" |
|||
days=int(seconds/86400): seconds=seconds mod 86400 |
days=int(seconds/86400): seconds=seconds mod 86400 |
||
if days then UnitsFound+=1: LastFound$="days" |
|||
hours=int(seconds/3600): seconds=seconds mod 3600 |
hours=int(seconds/3600): seconds=seconds mod 3600 |
||
if hours then UnitsFound+=1: LastFound$="hours" |
|||
minutes=int(seconds/60): seconds=seconds mod 60 |
minutes=int(seconds/60): seconds=seconds mod 60 |
||
if minutes then UnitsFound+=1: LastFound$="minutes" |
|||
if seconds then UnitsFound+=1: LastFound$="seconds" |
|||
select case years |
select case years |
||
case 0 |
case 0 |
||
Line 1,373: | Line 1,380: | ||
select case weeks |
select case weeks |
||
case 0 |
case 0 |
||
case 1 |
case 1 |
||
if years then |
|||
if LastFound$="weeks" then print " and "; else print ", "; |
|||
end if |
|||
print weeks; " week"; |
print weeks; " week"; |
||
case else |
case else |
||
if years then |
|||
if LastFound$="weeks" then print " and "; else print ", "; |
|||
end if |
|||
print weeks; " weeks"; |
print weeks; " weeks"; |
||
end select |
end select |
||
select case days |
select case days |
||
case 0 |
case 0 |
||
case 1 |
case 1 |
||
⚫ | |||
if LastFound$="days" then print " and "; else print ", "; |
|||
end if |
|||
print days; " day"; |
print days; " day"; |
||
case else |
case else |
||
⚫ | |||
if LastFound$="days" then print " and "; else print ", "; |
|||
end if |
|||
print days; " days"; |
print days; " days"; |
||
end select |
end select |
||
select case hours |
select case hours |
||
case 0 |
case 0 |
||
case 1 |
case 1 |
||
⚫ | |||
if LastFound$="hours" then print " and "; else print ", "; |
|||
end if |
|||
print hours; " hour"; |
print hours; " hour"; |
||
case else |
case else |
||
⚫ | |||
if LastFound$="hours" then print " and "; else print ", "; |
|||
end if |
|||
print hours; " hours"; |
print hours; " hours"; |
||
end select |
end select |
||
select case minutes |
select case minutes |
||
case 0 |
case 0 |
||
case 1 |
|||
⚫ | |||
if years or weeks or days or hours then |
|||
if LastFound$="minutes" then print " and "; else print ", "; |
|||
end if |
|||
print minutes; " minute"; |
print minutes; " minute"; |
||
case else |
|||
⚫ | |||
if years or weeks or days or hours then |
|||
if LastFound$="minutes" then print " and "; else print ", "; |
|||
end if |
|||
print minutes; " minutes"; |
print minutes; " minutes"; |
||
end select |
end select |
||
select case seconds |
select case seconds |
||
case 0 |
case 0 |
||
case 1 |
|||
⚫ | |||
if years or weeks or days or hours or minutes then |
|||
if LastFound$="seconds" then print " and "; else print ", "; |
|||
end if |
|||
print seconds; " second"; |
print seconds; " second"; |
||
case else |
|||
⚫ | |||
if years or weeks or days or hours or minutes then |
|||
if LastFound$="seconds" then print " and "; else print ", "; |
|||
end if |
|||
print seconds; " seconds"; |
print seconds; " seconds"; |
||
end select |
end select |
||
Line 1,411: | Line 1,448: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Enter SECONDS: 100 |
|||
1 minute, 40 seconds |
|||
Enter SECONDS: 7259 |
Enter SECONDS: 7259 |
||
2 hours |
2 hours and 59 seconds |
||
Enter SECONDS: 86400 |
Enter SECONDS: 86400 |
||
1 day |
1 day |
||
Enter SECONDS: 6000000 |
Enter SECONDS: 6000000 |
||
9 weeks, 6 days, 10 hours |
9 weeks, 6 days, 10 hours and 40 minutes |
||
Enter SECONDS: 987654321 |
Enter SECONDS: 987654321 |
||
31 years, 21 weeks, 4 hours, 25 minutes |
31 years, 21 weeks, 4 hours, 25 minutes and 21 seconds |
||
Enter SECONDS: |
Enter SECONDS: |
||
Program complete. |
Program complete. |