Skip to content

Instantly share code, notes, and snippets.

@christian-fei
Last active February 22, 2016 16:11
Show Gist options
  • Save christian-fei/1536095c610c476fe9ce to your computer and use it in GitHub Desktop.
Save christian-fei/1536095c610c476fe9ce to your computer and use it in GitHub Desktop.
describe_time :: Int -> String
describe_time sec = describe_time_rec (0, 0,0,0) sec
describe_time_rec :: (Int, Int, Int, Int) -> Int -> String
describe_time_rec acc@(days, hours,minutes,seconds) rem
| rem >= 86400 = describe_time_rec (days + 1, hours,minutes,seconds) (rem - 86400)
| rem >= 3600 = describe_time_rec (days, hours + 1,minutes,seconds) (rem - 3600)
| rem >= 60 = describe_time_rec (days, hours,minutes + 1,seconds) (rem - 60)
| rem < 60 = describe_time_rec (days, hours, minutes, rem) 0
| rem == 0 = (show days) ++ " DAYS " ++ (show hours) ++ " HOURS " ++ (show minutes) ++ " MINUTES " ++ (show seconds) ++ " SECONDS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment