Convert seconds to compound duration: Difference between revisions
Convert seconds to compound duration (view source)
Revision as of 19:57, 20 February 2021
, 3 years ago→{{header|Haskell}}: Tidied parameterised variant.
(add Standard ML) |
m (→{{header|Haskell}}: Tidied parameterised variant.) |
||
Line 1,847:
<lang haskell>import Data.List (intercalate, mapAccumR)
durationString ::
String ->
String ->
intercalate▼
Int ->
componentGap▼
Int
[String] ->
(timeTags numberLabelGap)▼
Int
String
(zip (weekParts daysPerWeek hoursPerDay n) xs))▼
durationString
componentGap
numberLabelGap
daysPerWeek
hoursPerDay
xs
n =
▲ intercalate
▲ componentGap
( foldr
▲ (timeTags numberLabelGap)
[]
)
timeTags :: String -> (Int, String) -> [String] -> [String]
Line 1,865 ⟶ 1,879:
weekParts :: Int -> Int -> Int -> [Int]
weekParts daysPerWeek hoursPerDay =
snd
snd . flip (mapAccumR byUnits) [0, daysPerWeek, hoursPerDay, 60, 60]▼
. flip
(mapAccumR byUnits)
byUnits :: Int -> Int -> (Int, Int)
Line 1,874 ⟶ 1,891:
| otherwise = (1, rest)
translation :: String -> Int -> Int -> Int -> String
translation local daysPerWeek hoursPerDay n =
intercalate " -> " $
[ show,
durationString
", "
" "
daysPerWeek
hoursPerDay
(words local)
]
<*> [n]
main :: IO ()
|