Jump to content

Convert seconds to compound duration: Difference between revisions

Add Jakt
(Add Vale)
(Add Jakt)
Line 2,193:
fmtsecs 6000000
9 wk, 6 d, 10 hr, 40 min</syntaxhighlight>
 
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn main() {
for seconds in [
7259
86400
6000000
] {
println("{}", time_string(seconds))
}
}
 
fn time_string(mut seconds: i64) throws -> String {
mut result = ""
 
mut minutes = seconds / 60
seconds %= 60
if seconds > 0 {
result = format("{} sec", seconds, result)
}
 
mut hours = minutes / 60
minutes %= 60
if minutes > 0 {
result = format(match result {
"" => "{} min"
else => "{} min, {}"
}, minutes, result)
}
 
mut days = hours / 24
hours %= 24
if hours > 0 {
result = format(match result {
"" => "{} hr"
else => "{} hr, {}"
}, hours, result)
}
 
mut weeks = days / 7
days %= 7
if days > 0 {
result = format(match result {
"" => "{} d"
else => "{} d, {}"
}, days, result)
}
if weeks > 0 {
result = format(match result {
"" => "{} wk"
else => "{} wk, {}"
}, weeks, result)
}
 
return result
}
</syntaxhighlight>
 
=={{header|Java}}==
89

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.