3. Dates and Times

Introduction

--ghc mtime1 = now >>= (\d -> putStrLn (calendarTimeToString d))
--ghc mtime2 = do d <- now
--ghc             putStrLn ("Today is day "^d.ctYDay^" of the current year")
--ghc             putStrLn ("Today is day "^d.ctDay^ " of the current month")
--ghc 
--ghc 

Finding Today's Date

--ghc (day,month,year) = (now >>> ctDay, now >>> ctMonth, now >>> ctYear)
--ghc tl = now >>= localtime
--ghc 
--ghc mtime3 = do date <- tl
--ghc             putStrLn ("The current date is "^date.ctYear^" "^date.ctMonth^" "^date.ctDay)
--ghc 
--ghc mtime4 = do d <- now
--ghc             putStrLn (strftime "%Y-%m-%d" d)
--ghc 
--ghc -- TODO 3.2, 3.3
--ghc 

Converting DMYHMS to Epoch Seconds

Converting Epoch Seconds to DMYHMS

Adding to or Subtracting from a Date

--ghc add_sec sec d = d.toClockTime.addToClockTime (nulltime {tdSec= sec})
--ghc when_ = now >>> (\d -> d.add_sec 100)
--ghc then_ = now >>> (\d -> d.add_sec (-100))
--ghc 

Difference of Two Dates

Day in a Week/Month/Year or Week Number

--ghc (monthday, weekday, yearday) = (now >>> ctDay, now >>> ctWDay, now >>> ctYDay)
--ghc 
--ghc weeknum = now >>> (\d -> d.strftime "%U".read + 1)
--ghc 
--ghc -- TODO 3.9
--ghc usec = now >>> ctPicosec -- is this ?
--ghc 
--ghc -- TODO _3.10
--ghc -- have sleep::Int but not Double :(

----------------------------------------------------------------------------------------------------

Parsing Dates and Times from Strings

Printing a Date

High-Resolution Timers

Short Sleeps

Program: hopdelta