Convert seconds to compound duration: Difference between revisions
Convert seconds to compound duration (view source)
Revision as of 22:55, 12 April 2024
, 1 month ago→{{header|langur}}
Thundergnat (talk | contribs) m (→{{header|C sharp}}: Regularize header markup to recommended on category page) |
Langurmonkey (talk | contribs) |
||
(30 intermediate revisions by 17 users not shown) | |||
Line 74:
=={{header|11l}}==
{{trans|Julia}}
<
[Int] t
L(dm) [60, 60, 24, 7]
Line 85:
print(duration(7259))
print(duration(86400))
print(duration(6000000))</
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<
DEFINE PTR="CARD"
Line 154:
Test("6000000")
RETURN
</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Convert_seconds_to_compound_duration.png Screenshot from Atari 8-bit computer]
Line 164:
=={{header|Ada}}==
<
procedure Convert is
Line 207:
IO.New_Line;
end loop;
end Convert;</
{{out}}
Line 222:
=={{header|ALGOL 68}}==
<
MODE DURATION = STRUCT( INT weeks, days, hours, minutes, seconds );
Line 264:
print( ( TOSTRING TODURATION 7259, newline ) );
print( ( TOSTRING TODURATION 86400, newline ) );
print( ( TOSTRING TODURATION 6000000, newline ) )</
{{out}}
<pre>
Line 274:
=={{header|ALGOL W}}==
Based on Algol 68 but Algol W does not have dynamic string handling which makes this more complex.
<
% record structure to hold a compound duration %
record Duration ( integer weeks, days, hours, minutes, seconds );
Line 360:
write( durationToString( toDuration( 86400 ) ) );
write( durationToString( toDuration( 6000000 ) ) )
end.</
{{out}}
<pre>
Line 370:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
names←'wk' 'd' 'hr' 'min' 'sec'
parts←0 7 24 60 60⊤⍵
fmt←⍕¨(parts≠0)/parts,¨names
¯2↓∊fmt,¨⊂', '
}</
{{out}}
<pre> duration 7259
Line 385:
=={{header|AppleScript}}==
===Functional===
<syntaxhighlight lang="applescript">
-------------------- COMPOUND DURATIONS ------------------
Line 538:
end repeat
return zs
end zip</
{{Out}}
<pre>7259 -> 2 hr, 59 sec
Line 545:
----
===Straightforward===
<syntaxhighlight lang="applescript">on secondsToCompoundDuration(sec)
if ((sec's class is not integer) or (sec < 0)) then ¬
error "secondsToCompoundDuration() handler only accepts positive integers."
-- The task description notwithstanding, return "0 sec" if the input is 0.
if (sec = 0)
-- Otherwise perform the described task.
set units to {weeks, days, hours, minutes, 1}
set suffixes to {" wk, ", " d, ", " hr, ", " min, ", " sec, "}
repeat with i from 1 to 5
set
if (unitValue > 0) then set output to output & unitValue & suffixes's item i
end repeat
return output's text 1 thru -3
end secondsToCompoundDuration
return secondsToCompoundDuration(7259) & linefeed & ¬
secondsToCompoundDuration(86400) & linefeed & ¬
secondsToCompoundDuration(6000000)</
{{output}}
<
1 d
9 wk, 6 d, 10 hr, 40 min"</
=={{header|Applesoft BASIC}}==
<
110 FOR I = 0 TO 4
120 READ M(I), U$(I)
Line 615 ⟶ 597:
270 END
</syntaxhighlight>
=={{header|Arturo}}==
{{trans|Nim}}
<syntaxhighlight lang="rebol">Units: [" wk", " d", " hr", " min", " sec"]
Quantities: @[7 * 24 * 60 * 60, 24 * 60 * 60, 60 * 60, 60, 1]
durationString: function [d][
dur: d
idx: 0
result: new []
while [not? zero? dur][
q: dur / Quantities\[idx]
if not? zero? q [
dur: dur % Quantities\[idx]
'result ++ ~{|q||Units\[idx]|}
]
idx: idx +1
]
return join.with:", " result
]
loop [7259 86400 6000000] 't [
print [t "s => " durationString t]
]</syntaxhighlight>
{{out}}
<pre>7259 s => 2 hr, 59 sec
86400 s => 1 d
6000000 s => 9 wk, 6 d, 10 hr, 40 min</pre>
=={{header|AutoHotkey}}==
<
sec:=1, min:=60*sec, hr:=60*min, day:=24*hr, wk:=7*day
w :=n//wk , n:=Mod(n,wk)
Line 626 ⟶ 638:
s :=n
return trim((w?w " wk, ":"") (d?d " d, ":"") (h?h " hr, ":"") (m?m " min, ":"") (s?s " sec":""),", ")
}</
Examples:<
(
7259
Line 637 ⟶ 649:
res .= A_LoopField "`t: " duration(A_LoopField) "`n"
MsgBox % res
return</
Outputs:<pre>7259 : 2 hr, 59 sec
86400 : 1 d
Line 643 ⟶ 655:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f CONVERT_SECONDS_TO_COMPOUND_DURATION.AWK
BEGIN {
Line 678 ⟶ 690:
return(str)
}
</syntaxhighlight>
<p>Output:</p>
<pre>
Line 696 ⟶ 708:
==={{header|Commodore BASIC}}===
<
20 REM ADAPTED FROM RUN BASIC VERSION
30 REM ===============================================================
Line 730 ⟶ 742:
1190 PRINT SC;"SEC"
1200 PRINT
1210 RETURN</
{{out}}
7259 sec
Line 742 ⟶ 754:
==={{header|BaCon}}===
<
'--- SAY_TIME Convert seconds to compound duration
'--- Weeks, days hours, minutes ,seconds
Line 781 ⟶ 793:
'---result 9 wk, 6 d, 10 h, 40 min, 7 sec
SAY_TIME(6000007)
</
==={{header|BBC BASIC}}===
<
PRINT FN_convert(7259)
PRINT FN_convert(86400)
Line 805 ⟶ 817:
ENDIF
NEXT
= compound$</
{{out}}
<pre>2 hr, 59 sec
Line 812 ⟶ 824:
==={{header|IS-BASIC}}===
<
110 NUMERIC UN(1 TO 5),SEC,UNIT
120 STRING T$(1 TO 5)*3
Line 826 ⟶ 838:
220 END IF
230 NEXT
240 PRINT</
=={{header|Batch File}}==
<
::The Main Thing...
for %%d in (7259 86400 6000000) do call :duration %%d
Line 854 ⟶ 866:
if %1 gtr 0 echo %1 sec = %output:~1,-1%
goto :EOF
::/The Function.</
{{Out}}
<pre>
Line 864 ⟶ 876:
=={{header|beeswax}}==
<
pq":X~7~ :X@~++8~8@:X:X@~-~4~.+~8@T_
## ## #### #`K0[`}`D2[`}BF3< <
>{` wk, `>g?"p{` d, `>g?"p{` hr, `>g?"p{` min, `>g"b{` sec, `b
> d > d > d > d</
{{Out}}
Line 891 ⟶ 903:
The value to convert is read from stdin, and the corresponding compound duration is written to stdout.
<
v-7*"l~"/7\"d"\%7:/*83\+*:"xD"\%*83:/"<"<
> \:! #v_v#-#<",",#$48*#<,#<.#<>#_:"~"%,v
^_@#:$$< > .02g92p ^ ^!:/"~"<</
{{out}}
Line 907 ⟶ 919:
===C: Version written in C89. Average skill level.===
<
* Program seconds2string, C89 version.
*
Line 969 ⟶ 981:
return EXIT_FAILURE;
}</
===C: Version written in C99. Low skill level.===
<syntaxhighlight lang="c">
#include <inttypes.h> /* requires c99 */
#include <stdbool.h> /* requires c99 */
Line 1,113 ⟶ 1,125:
return minutes*60;
}
</syntaxhighlight>
{{out}}
Line 1,130 ⟶ 1,142:
===C#: Standard method===
<
using System.Collections.Generic;
using System.Linq;
Line 1,181 ⟶ 1,193:
}
}</
{{out}}
Line 1,197 ⟶ 1,209:
{{libheader|System.Linq}}
{{works with|C sharp|6}}
<
{
if (seconds < 0) throw new ArgumentOutOfRangeException(nameof(seconds));
Line 1,210 ⟶ 1,222:
where parts[index] > 0
select parts[index] + units[index]);
}</
=={{header|C++}}==
{{works with|C++11}}
<
#include <iostream>
#include <vector>
Line 1,250 ⟶ 1,262:
std::cout << " 86400 sec is "; print(convert( 86400));
std::cout << "6000000 sec is "; print(convert(6000000));
}</
{{out}}
<pre>
Line 1,259 ⟶ 1,271:
=={{header|Clojure}}==
<
(def seconds-in-minute 60)
Line 1,286 ⟶ 1,298:
(seconds->duration 7259)
(seconds->duration 86400)
(seconds->duration 6000000)</
{{out}}
Line 1,296 ⟶ 1,308:
=={{header|CLU}}==
<
own units: array[string] := array[string]$["wk","d","hr","min","sec"]
own sizes: array[int] := array[int]$[2:7,24,60,60]
Line 1,323 ⟶ 1,335:
stream$putl(po, int$unparse(test) || " => " || duration(test))
end
end start_up</
{{out}}
<pre>7259 => 2 hr, 59 sec
Line 1,330 ⟶ 1,342:
=={{header|COBOL}}==
<
program-id. fmt-dura.
data division.
Line 1,403 ⟶ 1,415:
.
end program fmt.
end program fmt-dura.</
<pre>Enter duration (seconds): 7259
2 hr, 59 sec
Line 1,412 ⟶ 1,424:
=={{header|Common Lisp}}==
<
(defconstant +seconds-in-hour* (* 60 +seconds-in-minute*))
(defconstant +seconds-in-day* (* 24 +seconds-in-hour*))
Line 1,433 ⟶ 1,445:
(seconds->duration 86400)
(seconds->duration 6000000)
</syntaxhighlight>
{{out}}
<pre>
Line 1,442 ⟶ 1,454:
=={{header|D}}==
<syntaxhighlight lang="d">
import std.stdio, std.conv, std.algorithm;
Line 1,482 ⟶ 1,494:
6_000_000.ConvertSeconds.writeln;
}
</syntaxhighlight>
{{out}}
<pre>
Line 1,489 ⟶ 1,501:
9 wk, 6 d, 10 hr, 40 min
</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls,DateUtils}}
<syntaxhighlight lang="Delphi">
const TestData: array [0..2] of integer = (7259,86400,6000000);
function SecondsToFormatDate(Sec: integer): string;
var DT: TDateTime;
var Weeks: integer;
var AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word;
const SecPerDay = 60 * 60 * 24;
begin
{Convert seconds to Delphi TDateTime}
{which is floating point days}
DT:=Sec / SecPerDay;
{Get weeks and subtract them off}
Weeks:=Trunc(DT/7);
DT:=DT - Weeks * 7;
{Decode date}
DecodeDateTime(DT,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);
{Compensate because TDateTime starts on Dec 30th 1899}
if aDay<30 then aDay:=aDay + 1 else aDay:=aDay - 30;
Result:='';
if Weeks<>0 then Result:=Result+IntToStr(Weeks)+' wk, ';
if ADay<>0 then Result:=Result+IntToStr(ADay)+' d, ';
if AHour<>0 then Result:=Result+IntToStr(AHour)+' hr, ';
if AMinute<>0 then Result:=Result+IntToStr(AMinute)+' min, ';
if ASecond<>0 then Result:=Result+IntToStr(ASecond)+' sec, ';
end;
procedure ShowFormatedDataTime(Memo: TMemo);
var I: integer;
begin
for I:=0 to High(TestData) do
Memo.Lines.Add(IntToStr(TestData[I])+' = '+SecondsToFormatDate(TestData[I]));
end;
</syntaxhighlight>
{{out}}
<pre>
7259 = 2 hr, 59 sec,
86400 = 1 d,
6000000 = 9 wk, 6 d, 10 hr, 40 min,
Elapsed Time: 2.900 ms.
</pre>
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
func$ split sec .
n$[] = [ "sec" "min" "hr" "d" "wk" ]
for
sec = sec div divs[i]
for i =
if r[i] <> 0
if s$ <> ""
s$ &= ", "
.
s$ &= r[i] & " " & n$[i]
.
.
return
.
print
</syntaxhighlight>
{{out}}
Line 1,525 ⟶ 1,587:
=={{header|Elixir}}==
<
@minute 60
@hour @minute*60
Line 1,545 ⟶ 1,607:
Enum.each([7259, 86400, 6000000], fn sec ->
:io.fwrite "~10w sec : ~s~n", [sec, Convert.sec_to_str(sec)]
end)</
{{out}}
Line 1,561 ⟶ 1,623:
Function ''intercalate/2'' is copied from [https://github.com/tim/erlang-oauth/blob/master/src/oauth.erl a Tim Fletcher's GitHub repository].
<
-module(convert_seconds).
Line 1,651 ⟶ 1,713:
% **************************************************
</syntaxhighlight>
Output:
Line 1,661 ⟶ 1,723:
=={{header|F_Sharp|F#}}==
<
let convert seconds =
Line 1,681 ⟶ 1,743:
|> Seq.map (fun str -> let sec = UInt32.Parse str in (sec, convert sec))
|> Seq.iter (fun (s, v) -> printfn "%10i = %s" s v)
0</
{{out}}
<pre>>RosettaCode 7259 86400 6000000
Line 1,689 ⟶ 1,751:
=={{header|Factor}}==
<
sequences.generalizations ;
Line 1,701 ⟶ 1,763:
[ first "0" = ] reject [ " " join ] map ", " join print ;
7259 86400 6000000 [ .time ] tri@</
{{out}}
<pre>
Line 1,711 ⟶ 1,773:
=={{header|Forth}}==
{{works with|Gforth|0.7.3}}
<
: ., C @ IF ." , " THEN 1 C ! ;
: .TIME ( n --)
Line 1,718 ⟶ 1,780:
[ 60 60 * ]L /MOD ?DUP-IF ., . ." hr" THEN
[ 60 ]L /MOD ?DUP-IF ., . ." min" THEN
?DUP-IF ., . ." sec" THEN 0 C ! ;</
{{out}}
<pre>2 hr, 59 sec
Line 1,728 ⟶ 1,790:
If the time to describe was not an integer but a floating-point value with fractional parts, then there is a complication. The number of seconds can be less than sixty, but, on output, 60 seconds can appear. If the number of seconds was to be written with one decimal digit (say) and the output format was F4.1 for that, then if the value was 59·95 or more, it will be rounded up for output, in this example to 60·0. Various systems make this mistake, as also with latitude and longitude, and it is a general problem. A fixup pass is necessary before generating the output: maintain an array with the integer values of the various units, then (for one decimal digit usage) check that the seconds part is less than 59·95. If not, set it to zero and augment the minutes count. If this is 60 or more, set it to zero and augment the hours count, and so on. Thus the array.
<syntaxhighlight lang="fortran">
SUBROUTINE PROUST(T) !Remembrance of time passed.
INTEGER T !The time, in seconds. Positive only, please.
Line 1,766 ⟶ 1,828:
CALL PROUST(-666)
END
</syntaxhighlight>
Output:
<pre>
Line 1,778 ⟶ 1,840:
=={{header|FreeBASIC}}==
<
Sub Show(m As Long)
Line 1,814 ⟶ 1,876:
Show 86400 seconds
Show 6000000 seconds
sleep</
Output:
<pre>
Line 1,825 ⟶ 1,887:
Frink's <CODE>-></CODE> operator can break a unit of measure into its constituent parts. However, it does not suppress zero-valued elements unless they are at the beginning or the end, so we have to do that manually.
<
wk := week
n = eval[input["Enter duration in seconds: "]]
Line 1,831 ⟶ 1,893:
res =~ %s/, 0[^,]+//g
println[res]
</syntaxhighlight>
=={{header|FutureBasic}}==
{{trans|C}}
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
local fn CompoundDurationString( seconds as long ) as CFStringRef
long s = 1, m = s * 60, h = m * 60, d = h * 24, w = d * 7
long v(4) : v(0) = w : v(1) = d : v(2) = h : v(3) = m : v(4) = s
long i, value
CFArrayRef abbr = @[@"wk",@"d",@"hr",@"min",@"sec"]
CFMutableStringRef string = fn MutableStringWithCapacity(0)
for i = 0 to 4
value = seconds / v(i)
seconds = seconds mod v(i)
if ( value )
if ( len(string) ) then MutableStringAppendString( string, @", " )
MutableStringAppendFormat( string, @"%ld %@", value, abbr[i] )
end if
next
end fn = string
NSLog(@"%@",fn CompoundDurationString(7259))
NSLog(@"%@",fn CompoundDurationString(86400))
NSLog(@"%@",fn CompoundDurationString(6000000))
HandleEvents
</syntaxhighlight>
{{out}}
<pre>
2 hr, 59 sec
1 d
9 wk, 6 d, 10 hr, 40 min
</pre>
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=d7f00b8a96a6f792f0164f622f0686df Click this link to run this code]'''
<
Dim iInput As Integer[] = [7259, 86400, 6000000] 'Input details
Dim iChecks As Integer[] = [604800, 86400, 3600, 60] 'Weeks, days, hours, mins in seconds
Line 1,865 ⟶ 1,963:
Next
End</
Output:
<pre>
Line 1,874 ⟶ 1,972:
=={{header|Go}}==
<
import "fmt"
Line 1,923 ⟶ 2,021:
return
}
</syntaxhighlight>
{{Out}}
<pre>
Line 1,932 ⟶ 2,030:
=={{header|Haskell}}==
<
import Data.List (intercalate, mapAccumR)
import System.Environment (getArgs)
Line 1,959 ⟶ 2,057:
forM_ args $ \arg -> case readMaybe arg of
Just n -> printf "%7d seconds = %s\n" n (compoundDuration n)
Nothing -> putStrLn $ "Invalid number of seconds: " ++ arg</
{{out}}
Line 1,971 ⟶ 2,069:
Or, parameterising both the local names for these durations, and also the working assumptions about hours per day, and days per week:
<
---------------- COMPOUND DURATION STRINGS ---------------
Line 2,041 ⟶ 2,139:
putStrLn "\nor, at 8 hours per day, 5 days per week:"
mapM_ (putStrLn . translation names 5 8) tests</
{{Out}}
<pre>Assuming 24/7:
Line 2,057 ⟶ 2,155:
Implementation:
<
seq=. 0 7 24 60 60 #: y
}: ;:inv ,(0 ~: seq) # (8!:0 seq) ,. <;.2'wk,d,hr,min,sec,'
)</
The first line uses integer division with remainder to break the value in seconds into its components (weeks, days, hours, minutes, seconds).
Line 2,068 ⟶ 2,166:
Task examples:
<
2 hr, 59 sec
fmtsecs 86400
1 d
fmtsecs 6000000
9 wk, 6 d, 10 hr, 40 min</
=={{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}}==
This is a relatively simple task in Java, using the modulus-remainder operator.
<syntaxhighlight lang="java">
String duration(int seconds) {
StringBuilder string = new StringBuilder();
if (seconds >= 604_800 /* 1 wk */) {
string.append("%,d wk".formatted(seconds / 604_800));
seconds %= 604_800;
}
if (seconds >= 86_400 /* 1 d */) {
if (!string.isEmpty()) string.append(", ");
string.append("%d d".formatted(seconds / 86_400));
seconds %= 86_400;
}
if (seconds >= 3600 /* 1 hr */) {
if (!string.isEmpty()) string.append(", ");
string.append("%d hr".formatted(seconds / 3600));
seconds %= 3600;
}
if (seconds >= 60 /* 1 min */) {
if (!string.isEmpty()) string.append(", ");
string.append("%d min".formatted(seconds / 60));
seconds %= 60;
}
if (seconds > 0) {
if (!string.isEmpty()) string.append(", ");
string.append("%d sec".formatted(seconds));
}
return string.toString();
}
</syntaxhighlight>
<pre>
2 hr, 59 sec
1 d
9 wk, 6 d, 10 hr, 40 min
</pre>
<br />
An alternate demonstration
<syntaxhighlight lang="java">public class CompoundDuration {
public static void main(String[] args) {
Line 2,106 ⟶ 2,299:
return sec;
}
}</
<pre>2 hr, 59 sec
Line 2,118 ⟶ 2,311:
====ES5====
<
'use strict';
Line 2,177 ⟶ 2,370:
})();
</syntaxhighlight>
{{Out}}
Line 2,186 ⟶ 2,379:
====ES6====
<
// ---------------- COMPOUND DURATION ----------------
// compoundDuration :: [String] -> Int -> String
const compoundDuration = labels =>
.map((v, i) => [v, labels[i]])
.reduce((a, x) =>
a.concat(
] : []
), []
)
.join(
const weekParts = nSeconds => [0, 7, 24, 60, 60]
.reduceRight((a, x) => {
const
r = a[0],
mod = x !== 0 ? r % x : r;
return [
(r - mod) / (x || 1),
[mod, ...a[1]]
];
}, [nSeconds, []])[1];
// ---------------------- TEST -----------------------
// main :: IO ()
const main = () => {
const localNames = ["wk", "d", "hr", "min", "sec"];
return [7259, 86400, 6E6]
.map(nSeconds =>
`${nSeconds} -> ${
compoundDuration(localNames)(nSeconds)
}`).join("\n");
};
// MAIN ---
return main();
})();</
{{Out}}
<pre>7259 -> 2 hr, 59 sec
Line 2,239 ⟶ 2,434:
=={{header|jq}}==
{{works with|jq|1.4}}
'''Also works with gojq, the Go implementation'''
<syntaxhighlight lang="jq">def seconds_to_time_string:
def nonzero(text): floor | if . > 0 then "\(.) \(text)" else empty end;
if . == 0 then "0 sec"
Line 2,249 ⟶ 2,445:
(. % 60 | nonzero("sec"))]
| join(", ")
end;</
''Examples''':
<
{{out}}
<
0: 0 sec
7259: 2 hr, 59 sec
86400: 1 d
6000000: 9 wk, 6 d, 10 hr, 40 min</
=={{header|Julia}}==
<
function duration(sec::Integer)::String
t = Array{Int}([])
Line 2,275 ⟶ 2,471:
@show duration(86400)
@show duration(6000000)
</syntaxhighlight>
{{out}}
Line 2,283 ⟶ 2,479:
duration(6000000) = "9w, 6d, 10h, 40m"
</pre>
=={{header|K}}==
{{works with|ngn/k}}<syntaxhighlight lang=K>F:{", "/" "/'+($x[s]),s:,&0<x}(" "\"wk d hr min sec")!0 7 24 60 60\</syntaxhighlight>
Examples:
<syntaxhighlight lang=K>F 100
"1 min, 40 sec"
F 7259
"2 hr, 59 sec"
F 86400
"1 d"
F 6000000
"9 wk, 6 d, 10 hr, 40 min"</syntaxhighlight>
tested in ngn/k
=={{header|Kotlin}}==
<
if (n < 0) return "" // task doesn't ask for negative integers to be converted
if (n == 0) return "0 sec"
Line 2,323 ⟶ 2,535:
val durations = intArrayOf(0, 7, 84, 7259, 86400, 6000000)
durations.forEach { println("$it\t-> ${compoundDuration(it)}") }
}</
{{out}}
Line 2,333 ⟶ 2,545:
86400 -> 1 d
6000000 -> 9 wk, 6 d, 10 hr, 40 min
</pre>
=={{header|langur}}==
<syntaxhighlight lang="langur">val .duration = fn(var .sec) {
[
fw/wk d hr min sec/,
for[=[]] .dm in [7 * 24 * 60 * 60, 24 * 60 * 60, 60 * 60, 60] {
_for ~= [.sec \ .dm]
.sec rem= .dm
} ~ [.sec],
]
}
for .seconds in [7259, 86400, 6000000] {
val .dur = .duration(.seconds)
write $"\.seconds:7; sec = "
writeln join ", ", for[=[]] .k of .dur[1] {
if .dur[2][.k] != 0: _for ~= [$"\.dur[2][.k]; \.dur[1][.k];"]
}
}
</syntaxhighlight>
{{out}}
<pre> 7259 sec = 2 hr, 59 sec
86400 sec = 1 d
6000000 sec = 9 wk, 6 d, 10 hr, 40 min
</pre>
=={{header|Liberty BASIC}}==
I got a bit carried away and added 'years'...
<syntaxhighlight lang="lb">
[start]
input "Enter SECONDS: "; seconds
Line 2,426 ⟶ 2,664:
print
goto [start]
</syntaxhighlight>
{{out}}
<pre>
Line 2,442 ⟶ 2,680:
=={{header|Lua}}==
<
local units, dur = {"wk", "d", "hr", "min"}, ""
for i, v in ipairs({604800, 86400, 3600, 60}) do
Line 2,459 ⟶ 2,697:
print(duration(7259))
print(duration(86400))
print(duration(6000000))</
=={{header|Maple}}==
<syntaxhighlight lang="maple">
tim := proc (s) local weeks, days, hours, minutes, seconds;
weeks := trunc((1/604800)*s);
Line 2,471 ⟶ 2,709:
printf("%s", cat(`if`(0 < weeks, cat(weeks, "wk, "), NULL), `if`(0 < days, cat(days, "d, "), NULL), `if`(0 < hours, cat(hours, "hr, "), NULL), `if`(0 < minutes, cat(minutes, "min, "), NULL), `if`(0 < seconds, cat(seconds, "sec"), NULL)))
end proc;
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
StringJoin @@ (Riffle[
ToString /@ ((({Floor[x/604800],
Line 2,485 ⟶ 2,723:
Grid[Table[{n, "secs =",
compoundDuration[n]}, {n, {7259, 86400, 6000000}}],
Alignment -> {Left, Baseline}]</
{{out}}
Line 2,493 ⟶ 2,731:
=={{header|Nim}}==
<
const
Line 2,520 ⟶ 2,758:
when isMainModule:
for sec in [7259, 86400, 6000000]:
echo sec, "s = ", $$sec</
{{out}}
Line 2,531 ⟶ 2,769:
It is also possible to use the Duration type in the “times” module and the procedure “toParts” which decomposes a duration in units of time (nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days and weeks).
<
from algorithm import reversed
from strutils import addSep
Line 2,557 ⟶ 2,795:
when isMainModule:
for sec in [7259, 86400, 6000000]:
echo sec, "s = ", $$sec</
{{out}}
Line 2,565 ⟶ 2,803:
=={{header|OCaml}}==
{{works with|OCaml|4.03+}}
<
(max_int, "wk"); (* many wk = many wk *)
(7, "d"); (* 7 d = 1 wk *)
Line 2,636 ⟶ 2,874:
n calc s
in
List.iter testit test_cases</
{{out}}
[PASS] 7259 seconds -> 2 hr, 59 sec; expected: 2 hr, 59 sec
Line 2,651 ⟶ 2,889:
{{Works with|PARI/GP|2.7.4 and above}}
<
\\ Convert seconds to compound duration
\\ 4/11/16 aev
Line 2,668 ⟶ 2,906:
print(secs2compdur(6000000));
}
</
{{Output}}
Line 2,677 ⟶ 2,915:
9 wk, 6 d, 10 hr, 40 min
</pre>
=={{header|Pascal}}==
{{works with|Extended Pascal}}
<syntaxhighlight lang="pascal">program convertSecondsToCompoundDuration(output);
const
suffixUnitWeek = 'wk';
suffixUnitDay = 'd';
suffixUnitHour = 'hr'; { Use `'h'` to be SI-compatible. }
suffixUnitMinute = 'min';
suffixUnitSecond = 'sec'; { NB: Only `'s'` is SI-approved. }
suffixSeparator = ' '; { A non-breaking space would be appropriate. }
quantitySeparator = ', ';
{ Maximum expected length of `string` “12345 wk, 6 d, 7 hr, 8 min, 9 sec” }
timeSpanPrintedMaximumLength = 4 * length(quantitySeparator) +
20 + length(suffixUnitWeek) + 1 + length(suffixUnitDay) +
2 + length(suffixUnitHour) + 2 + length(suffixUnitMinute) +
2 + length(suffixUnitSecond) + 5 * length(suffixSeparator);
{ Units of time expressed in seconds. }
minute = 60;
hour = 60 * minute;
day = 24 * hour;
week = 7 * day;
type
wholeNumber = 0..maxInt;
naturalNumber = 1..maxInt;
canonicalTimeSpan = record
weeks: wholeNumber;
days: 0..6;
hours: 0..23;
minutes: 0..59;
seconds: 0..59;
end;
stringFitForTimeSpan = string(timeSpanPrintedMaximumLength);
{
\brief turns a time span expressed in seconds into a `canonicalTimeSpan`
\param duration the non-negative duration expressed in seconds
\return a `canonicalTimeSpan` representing \param duration seconds
}
function getCanonicalTimeSpan(duration: wholeNumber): canonicalTimeSpan;
{ Perform `div`ision and update `duration`. }
function split(protected unit: naturalNumber): wholeNumber;
begin
split := duration div unit;
duration := duration mod unit
end;
var
result: canonicalTimeSpan;
begin
with result do
begin
weeks := split(week);
days := split(day);
hours := split(hour);
minutes := split(minute);
seconds := duration
end;
{ In Pascal there needs to be _exactly_ one assignment to the }
{ result variable bearing the same name as of the `function`. }
getCanonicalTimeSpan := result
end;
{
\brief turns a non-trivial duration into a string
\param n a positive duration expressed in seconds
\return \param n expressed in some human-readable form
}
function timeSpanString(protected n: naturalNumber): stringFitForTimeSpan;
const
qs = quantitySeparator;
var
result: stringFitForTimeSpan;
begin
with getCanonicalTimeSpan(n) do
begin
{ `:1` specifies the minimum-width. Omitting it would cause }
{ the compiler to insert a vendor-defined default, e. g. 20. }
writeStr(result, weeks:1, suffixSeparator, suffixUnitWeek);
{ For strings, `:n` specifies the _exact_ width (padded with spaces). }
writeStr(result, result:ord(weeks > 0) * length(result));
if days > 0 then
begin
writeStr(result, result, qs:ord(length(result) > 0) * length(qs),
days:1, suffixSeparator, suffixUnitDay);
end;
if hours > 0 then
begin
writeStr(result, result, qs:ord(length(result) > 0) * length(qs),
hours:1, suffixSeparator, suffixUnitHour);
end;
if minutes > 0 then
begin
writeStr(result, result, qs:ord(length(result) > 0) * length(qs),
minutes:1, suffixSeparator, suffixUnitMinute);
end;
if seconds > 0 then
begin
writeStr(result, result, qs:ord(length(result) > 0) * length(qs),
seconds:1, suffixSeparator, suffixUnitSecond);
end
end;
timeSpanString := result
end;
{ === MAIN ============================================================= }
begin
writeLn( 7259, ' seconds are “', timeSpanString(7259), '”');
writeLn( 86400, ' seconds are “', timeSpanString(86400), '”');
writeLn(6000000, ' seconds are “', timeSpanString(6000000), '”')
end.</syntaxhighlight>
{{out}}
7259 seconds are “2 hr, 59 sec”
86400 seconds are “1 d”
6000000 seconds are “9 wk, 6 d, 10 hr, 40 min”
=={{header|Perl}}==
===Direct calculation===
<
use warnings;
Line 2,698 ⟶ 3,058:
for (7259, 86400, 6000000) {
printf "%7d sec = %s\n", $_, compound_duration($_)
}</
{{out}}
<pre> 7259 sec = 2 hr, 59 sec
Line 2,706 ⟶ 3,066:
===Using polymod===
More general approach for mixed-radix conversions.
<
use warnings;
use Math::AnyNum 'polymod';
Line 2,724 ⟶ 3,084:
for (<7259 86400 6000000 3380521>) {
printf "%7d sec = %s\n", $_, compound_duration($_)
}</
{{out}}
<pre> 7259 sec = 2 hr, 59 sec
Line 2,733 ⟶ 3,093:
=={{header|Phix}}==
There is a standard function for this, for more details see builtins/pelapsed.e (which will be kept up to date, unlike having a copy here)
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">7259</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">86400</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000000</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 2,746 ⟶ 3,106:
</pre>
You may also be interested in the timedelta() function, which converts durations to seconds, eg:
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000000</span><span style="color: #0000FF;">-</span><span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hours</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">10</span><span style="color: #0000FF;">))</span>
<!--</
{{out}}
<pre>
Line 2,757 ⟶ 3,117:
=={{header|PicoLisp}}==
<
(tab (-10 -30)
Sec
Line 2,767 ⟶ 3,127:
(pack @ " " Str) ) )
(604800 86400 3600 60 1)
'("wk" "d" "hr" "min" "sec") ) ) ) )</
Output:
<pre>7259 2 hr, 59 sec
Line 2,774 ⟶ 3,134:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
/* Convert seconds to Compound Duration (weeks, days, hours, minutes, seconds). */
Line 2,802 ⟶ 3,162:
end;
end cvt;
</syntaxhighlight>
Results:
<pre>
Line 2,818 ⟶ 3,178:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
function Get-Time
{
Line 2,935 ⟶ 3,295:
}
}
</syntaxhighlight>
{{Out}}
Line 2,973 ⟶ 3,333:
See below for examples.
<
% helper to perform the operation with just a number.
Line 3,016 ⟶ 3,376:
time_type(hr, 60 * 60).
time_type(min, 60).
time_type(sec, 1).</
{{out}}
Line 3,031 ⟶ 3,391:
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">
EnableExplicit
Line 3,087 ⟶ 3,447:
CloseConsole()
EndIf
</syntaxhighlight>
{{out}}
Line 3,099 ⟶ 3,459:
===Python: Procedural===
<
t= []
for dm in (60, 60, 24, 7):
Line 3,116 ⟶ 3,476:
86400 sec = 1 d
6000000 sec = 9 wk, 6 d, 10 hr, 40 min
>>> </
===Python: Functional===
<
return ', '.join('%d %s' % (num, unit)
for num, unit in zip([(seconds // d) % m
Line 3,135 ⟶ 3,495:
86400 sec = 1 d
6000000 sec = 9 wk, 6 d, 10 hr, 40 min
>>> </
Or, composing a solution from pure curried functions, including the '''mapAccumR''' abstraction (a combination of of '''map''' and '''reduce''', implemented in a variety of languages and functional libraries, in which a new list is derived by repeated application of the same function, as an accumulator (here, a remainder) passes from right to left):
<
from functools import reduce
Line 3,225 ⟶ 3,585:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>Compound durations from numbers of seconds:
Line 3,235 ⟶ 3,595:
=={{header|Quackery}}==
<
witheach [ /mod swap ]
$ ""
Line 3,253 ⟶ 3,613:
say " seconds is "
duration$ echo$
say "." cr ]</
{{Out}}
Line 3,265 ⟶ 3,625:
=={{header|Racket}}==
<
(require racket/string
racket/list)
Line 3,296 ⟶ 3,656:
(check-equal? (seconds->compound-duration-string 6000000) "9 wk, 6 d, 10 hr, 40 min"))
;; Tim Brown 2015-07-21</
{{out}}
Line 3,306 ⟶ 3,666:
The built-in <code>polymod</code> method (which is a generalization of the <code>divmod</code> function known from other languages), is a perfect match for a task like this:
<syntaxhighlight lang="raku"
($seconds.polymod(60, 60, 24, 7) Z <sec min hr d wk>)
.grep(*[0]).reverse.join(", ")
Line 3,315 ⟶ 3,675:
for 7259, 86400, 6000000 {
say "{.fmt: '%7d'} sec = {compound-duration $_}";
}</
{{out}}
Line 3,326 ⟶ 3,686:
=={{header|REXX}}==
===version 1===
<
* Format seconds into a time string
*--------------------------------------------------------------------*/
Line 3,371 ⟶ 3,731:
a=what%how
b=what//how
Return a b</
{{out}}
<pre>2 hr, 59 sec
Line 3,382 ⟶ 3,742:
===version 2===
This REXX version can also handle fractional (seconds) as well as values of zero (time units).
<
parse arg @; if @='' then @=7259 86400 6000000 /*Not specified? Then use the default.*/
Line 3,400 ⟶ 3,760:
return $
/*──────────────────────────────────────────────────────────────────────────────────────*/
timeU: parse arg u,$; _= x%u; if _==0 then return ''; x= x - _*u; return _ $","</
{{out|output|text= when using the default (internal) inputs:}}
<pre>
Line 3,416 ⟶ 3,776:
=={{header|Ring}}==
<
sec = 6000005
week = floor(sec/60/60/24/7)
Line 3,433 ⟶ 3,793:
if second > 0 see second
see " seconds" + nl ok
</syntaxhighlight>
=={{header|RPL}}==
≪ MOD LAST / FLOOR ≫ '<span style="color:blue">'''DIVMOD'''</span>' STO
≪ {" wk" " d" " hr" " min" " sec" } → unit
≪ 60 <span style="color:blue">'''DIVMOD'''</span> 60 <span style="color:blue">'''DIVMOD'''</span> 24 <span style="color:blue">'''DIVMOD'''</span> 7 <span style="color:blue">'''DIVMOD'''</span>
1 SF ""
1 unit SIZE '''FOR''' j
'''IF''' SWAP '''THEN'''
LAST →STR unit j GET +
'''IF''' 1 FC?C '''THEN''' ", " SWAP + '''END'''
+ '''END'''
'''NEXT'''
≫ ≫ '<span style="color:blue">'''→CDUR'''</span>' STO
Users of HP-48G and newer models can replace the <code>60 <span style="color:blue">'''DIVMOD'''</span> 60 <span style="color:blue">'''DIVMOD'''</span> 24 <span style="color:blue">'''DIVMOD'''</span> 7 <span style="color:blue">'''DIVMOD'''</span></code> line by:
{ 60 60 24 7 } 1 ≪ MOD LAST / FLOOR ≫ DOSUBS OBJ→ DROP
7259 <span style="color:blue">'''→CDUR'''</span>
86400 <span style="color:blue">'''→CDUR'''</span>
6000000 <span style="color:blue">'''→CDUR'''</span>
10! <span style="color:blue">'''→CDUR'''</span>
{{out}}
<pre>
4: "2 hr, 59 sec"
3: "1 d"
2: "9 wk, 6 d, 10 hr, 40 min"
1: "6 wk"
</pre>
=={{header|Ruby}}==
<
HOUR = MINUTE*60
DAY = HOUR*24
Line 3,450 ⟶ 3,838:
end
[7259, 86400, 6000000].each{|t| puts "#{t}\t: #{sec_to_str(t)}"}</
Output:
<pre>
Line 3,459 ⟶ 3,847:
=={{header|Run BASIC}}==
<
week = int(sec/60/60/24/7)
day = int(sec/60/60/24) mod 7
Line 3,471 ⟶ 3,859:
if hour > 0 then print hour;" hours ";
if minute > 0 then print minute;" minutes ";
if second > 0 then print second;" seconds"</
=={{header|Rust}}==
This solution deviates from the prompt a bit in order to make it more general. The benefit of doing it this way is that any values can be filled in for days, hours, minutes and seconds and the `balance` method will do the balancing accordingly. Also, rather than converting the value into a String, it simply implements the `Display` trait.
<
Line 3,520 ⟶ 3,908:
ct.balance();
println!("After: {}", ct);
}</
=={{header|Scala}}==
<
object seconds{
Line 3,551 ⟶ 3,939:
println("Second = " + sec)
}
}</
=={{header|Scheme}}==
Line 3,559 ⟶ 3,947:
This version uses delete from SRFI 1 and string-join from SRFI 13:
<
(import (scheme base)
(scheme write)
Line 3,588 ⟶ 3,976:
(display (seconds->duration 86400)) (newline)
(display (seconds->duration 6000000)) (newline)
</syntaxhighlight>
{{out}}
Line 3,599 ⟶ 3,987:
=={{header|Sidef}}==
{{trans|Raku}}
<
gather {
divs.each { |i|
Line 3,617 ⟶ 4,005:
[7259, 86400, 6000000].each { |s|
say "#{'%7d' % s} sec = #{compound_duration(s)}"
}</
{{out}}
Line 3,627 ⟶ 4,015:
=={{header|Standard ML}}==
<
fun fmtNonZero (0, _, list) = list
| fmtNonZero (n, s, list) = Int.toString n ^ " " ^ s :: list
Line 3,642 ⟶ 4,030:
end
val () = app (fn s => print (compoundDuration s ^ "\n")) [7259, 86400, 6000000]</
=={{header|Swift}}==
<syntaxhighlight lang="swift">func duration (_ secs:Int) -> String {
if secs <= 0 { return "" }
let units = [(604800,"wk"), (86400,"d"), (3600,"hr"), (60,"min")]
var secs = secs
var result = ""
for (period, unit) in units {
if secs >= period {
result += "\(secs/period) \(unit), "
secs = secs % period
}
}
if secs == 0 {
result.removeLast(2) // remove ", "
} else {
result += "\(secs) sec"
}
return result
}
print(duration(7259))
print(duration(86400))
print(duration(6000000))</syntaxhighlight>
=={{header|Tcl}}==
Line 3,648 ⟶ 4,060:
The data-driven procedure below can be customised to use different breakpoints, simply by editing the dictionary.
<
set factors {
sec 60
Line 3,685 ⟶ 4,097:
check {sec2str 7259} {2 hr, 59 sec}
check {sec2str 86400} {1 d}
check {sec2str 6000000} {9 wk, 6 d, 10 hr, 40 min}</
{{Out}}
Line 3,694 ⟶ 4,106:
=={{header|uBasic/4tH}}==
Since uBasic/4tH is integer-only, it is hard to return a string. However, it is capable to transform an integer value as required.
<syntaxhighlight lang="text">Proc _CompoundDuration(7259)
Proc _CompoundDuration(86400)
Proc _CompoundDuration(6000000)
Line 3,732 ⟶ 4,144:
_d Print " d"; : Return
_hr Print " hr"; : Return
_min Print " min"; : Return</
{{out}}
<pre>2 hr, 59 sec
Line 3,739 ⟶ 4,151:
0 OK, 0:94</pre>
=={{header|Vale}}==
{{works with|Vale|0.2.0}}
<syntaxhighlight lang="vale">
import stdlib.*;
import stdlib.stdin.*;
import stdlib.math.*;
exported func main() {
foreach testCase in [#][
7259,
86400,
6000000,
] {
testCase.timeString().println();
}
}
func timeString(seconds int) str {
result = "";
minutes = seconds / 60;
set seconds = seconds.mod(60);
if seconds > 0 {
set result = seconds.str() + " sec";
}
hours = minutes / 60;
set minutes = minutes.mod(60);
if minutes > 0 {
set result = minutes.str() + if result != "" {
" min, " + result
} else {
" min"
};
}
days = hours / 24;
set hours = hours.mod(24);
if hours > 0 {
set result = hours.str() + if result != "" {
" hr, " + result
} else {
" hr"
};
}
weeks = days / 7;
set days = days.mod(7);
if days > 0 {
set result = days.str() + if result != "" {
" d, " + result
} else {
" d"
};
}
if weeks > 0 {
set result = weeks.str() + if result != "" {
" wk, " + result
} else {
" wk"
};
}
return result;
}
</syntaxhighlight>
=={{header|VBA}}==
<
minutes = 60
hours = 60 * minutes
Line 3,771 ⟶ 4,250:
Debug.Print compound_duration(86400)
Debug.Print compound_duration(6000000)
End Sub</
<pre>2 hr, 59 sec
1 d
Line 3,777 ⟶ 4,256:
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
Function compound_duration(n)
Do Until n = 0
Line 3,815 ⟶ 4,294:
WScript.StdOut.WriteLine compound_duration(86400)
WScript.StdOut.WriteLine compound_duration(6000000)
</syntaxhighlight>
{{Out}}
Line 3,825 ⟶ 4,304:
=={{header|Wren}}==
<
if (s < 1) return "0 sec"
var dur = ""
Line 3,843 ⟶ 4,322:
}
for (s in [7259, 86400, 6000000]) System.print(duration.call(s))</
{{out}}
<pre>
2 hr, 59 sec
1 d
9 wk, 6 d, 10 hr, 40 min
</pre>
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">char Str(80);
func Duration(Sec); \Convert seconds to compound duration
int Sec, Amt, Unit, DoComma, I, Quot;
[Amt:= [7*24*60*60, 24*60*60, 60*60, 60, 1];
Unit:= [" wk", " d", " hr", " min", " sec"];
DoComma:= false;
for I:= 0 to 4 do
[Quot:= Sec/Amt(I);
Sec:= rem(0);
if Quot # 0 then
[if DoComma then Text(8, ", ");
DoComma:= true;
IntOut(8, Quot);
Text(8, Unit(I));
];
];
ChOut(8, $0D); ChOut(8, $8A); \terminating CR+LF
I:= 0;
loop [Str(I):= ChIn(8);
if Str(I) >= $80 then return Str;
I:= I+1;
];
];
[Text(0, Duration(7259));
Text(0, Duration(86400));
Text(0, Duration(6_000_000));
]</syntaxhighlight>
{{out}}
Line 3,853 ⟶ 4,369:
=={{header|zkl}}==
<
r,b:=List(),0;
foreach u in (T(60,60,24,7)){
Line 3,860 ⟶ 4,376:
}
r.append(sec).reverse()
}</
Or, if you like to be concise:
<
T(60,60,24,7).reduce(fcn(n,u,r){ n,u=n.divr(u); r.append(u); n },
sec,r:=List()):r.append(_).reverse();
}</
were the ":" op takes the left result and stuffs it into the "_" position.
<
foreach s in (T(7259,86400,6000000)){
toWDHMS(s).zip(units).pump(List,fcn([(t,u)]){ t and String(t,u) or "" })
.filter().concat(", ").println();
}</
{{out}}
<pre>
Line 3,881 ⟶ 4,397:
=={{header|ZX Spectrum Basic}}==
{{trans|AWK}}
<
20 DATA 10,7259,86400,6000000,0,1,60,3600,604799,604800,694861
30 READ n
Line 3,902 ⟶ 4,418:
200 NEXT i
210 STOP
220 DEF FN m(a,b)=a-INT (a/b)*b</
|