Convert seconds to compound duration: Difference between revisions
Convert seconds to compound duration (view source)
Revision as of 15:32, 20 January 2021
, 3 years ago→{{header|AppleScript}}: Tidied.
m (Added Quackery.) |
m (→{{header|AppleScript}}: Tidied.) |
||
Line 294:
=={{header|AppleScript}}==
<lang AppleScript>
-------------------- COMPOUND DURATIONS ------------------
script angloNames▼
on |λ|(n)▼
(n as string) & " -> " & ¬▼
localCompoundDuration(["wk", "d", "hr", "min", "sec"], n)▼
end |λ|▼
end script▼
unlines(map(angloNames, [7259, 86400, 6000000]))▼
-- DURATION STRINGS ----------------------------------------------------------▼
-- weekParts Int -> [Int]
Line 312 ⟶ 301:
unitParts(intSeconds, [missing value, 7, 24, 60, 60])
end weekParts
-- localCompoundDuration :: Int -> String
Line 333 ⟶ 323:
end localCompoundDuration
-- unitParts :: Int -> [maybe Int] -> [Int]
Line 357 ⟶ 347:
{remaining:intTotal, parts:[]}, unitList)
end unitParts
on run
▲ script angloNames
▲ on |λ|(n)
▲ (n as string) & " -> " & ¬
▲ localCompoundDuration(["wk", "d", "hr", "min", "sec"], n)
▲ end |λ|
▲ end script
▲ unlines(map(angloNames, [7259, 86400, 6000000]))
end run
-- foldr :: (
on foldr(f, startValue, xs)
tell mReturn(f)
Line 373 ⟶ 375:
end foldr
set {dlm, my text item delimiters} to {my text item delimiters, strText}▼
set
{my text item delimiters, delim}
set s to xs as text
set my text item delimiters to dlm
s
end intercalate
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
-- The list obtained by applying f
-- to each element of xs.
tell mReturn(f)
set lng to length of xs
Line 392 ⟶ 399:
end tell
end map
-- min :: Ord a => a -> a -> a
Line 402 ⟶ 410:
end min
-- mReturn ::
on mReturn(f)
if script is class of f then
f
else
Line 413 ⟶ 422:
end if
end mReturn
-- unlines :: [String] -> String
on unlines(xs)
-- A single string formed by the intercalation
▲ intercalate(linefeed, xs)
-- of a list of strings with the newline character.
{my text item delimiters, linefeed}
set s to xs as text
set my text item delimiters to dlm
s
end unlines
-- zip :: [a] -> [b] -> [(a, b)]
on zip(xs, ys)
-- A list of step-wise pairs drawn from xs and ys
-- up to the length of the shorter of those lists.
set lng to min(length of xs, length of ys)
set
repeat with i from 1 to lng
set end of
end repeat
return
end zip</lang>
{{Out}}
|