Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import Data.Time.Clock
  2. import Data.Time.Calendar
  3. import Data.Time.LocalTime
  4.  
  5.  
  6. main = do
  7. putStrLn "Please enter your birthyear:"
  8. birthyearstring <- getLine
  9. let birthyear = read birthyearstring :: Integer
  10. putStrLn "For the right timeunit, enter the respective digit:"
  11. putStrLn "1: Years, 2: Days"
  12. timeunitchoice <- getLine
  13. let timeunit =
  14. if timeunitchoice == "1" then "year"
  15. else if timeunitchoice == "2" then "day"
  16. else "Clever ;)"
  17. now <- getCurrentTime
  18. timezone <- getCurrentTimeZone
  19. let zoneNow = utcToLocalTime timezone now
  20. let (year, month, day) = toGregorian $ localDay zoneNow
  21. let ageint =
  22. if timeunitchoice == "1" then year-birthyear
  23. else if timeunitchoice == "2" then (year-birthyear)*365
  24. else 0
  25. let age = show ageint
  26. putStrLn ("Yikes, your survived " ++ age ++ timeunit ++ " s!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement