Convert seconds to compound duration: Difference between revisions
Content added Content deleted
(add Standard ML) |
m (→{{header|Haskell}}: Tidied parameterised variant.) |
||
Line 1,847: | Line 1,847: | ||
<lang haskell>import Data.List (intercalate, mapAccumR) |
<lang haskell>import Data.List (intercalate, mapAccumR) |
||
---------------- COMPOUND DURATION STRINGS --------------- |
|||
durationString :: |
durationString :: |
||
String -> |
|||
durationString componentGap numberLabelGap daysPerWeek hoursPerDay xs n = |
|||
String -> |
|||
⚫ | |||
Int -> |
|||
⚫ | |||
Int -> |
|||
[String] -> |
|||
⚫ | |||
Int -> |
|||
String |
|||
⚫ | |||
durationString |
|||
componentGap |
|||
numberLabelGap |
|||
daysPerWeek |
|||
hoursPerDay |
|||
xs |
|||
n = |
|||
⚫ | |||
⚫ | |||
( foldr |
|||
⚫ | |||
[] |
|||
⚫ | |||
) |
|||
timeTags :: String -> (Int, String) -> [String] -> [String] |
timeTags :: String -> (Int, String) -> [String] -> [String] |
||
Line 1,865: | Line 1,879: | ||
weekParts :: Int -> Int -> Int -> [Int] |
weekParts :: Int -> Int -> Int -> [Int] |
||
weekParts daysPerWeek hoursPerDay = |
weekParts daysPerWeek hoursPerDay = |
||
snd |
|||
⚫ | |||
. flip |
|||
(mapAccumR byUnits) |
|||
⚫ | |||
byUnits :: Int -> Int -> (Int, Int) |
byUnits :: Int -> Int -> (Int, Int) |
||
Line 1,874: | Line 1,891: | ||
| otherwise = (1, rest) |
| otherwise = (1, rest) |
||
--------------------------- TEST ------------------------- |
|||
translation :: String -> Int -> Int -> Int -> String |
translation :: String -> Int -> Int -> Int -> String |
||
translation local daysPerWeek hoursPerDay n = |
translation local daysPerWeek hoursPerDay n = |
||
intercalate " -> " $ |
intercalate " -> " $ |
||
[ show, |
|||
[show, durationString ", " " " daysPerWeek hoursPerDay (words local)] <*> [n] |
|||
durationString |
|||
", " |
|||
" " |
|||
daysPerWeek |
|||
hoursPerDay |
|||
(words local) |
|||
] |
|||
<*> [n] |
|||
main :: IO () |
main :: IO () |