RFC: Time Library 0.1

Ashley Yakeley ashley at semantic.org
Wed Jul 6 04:46:37 EDT 2005

In article <b0aab04e050705202412283438 at mail.gmail.com>,
 Brian Smith <brianlsmith at gmail.com> wrote:

> This library looks complicated. I think some tutorial documentation about 
> how to implement the following use cases would be very helpful to people 
> that don't really care about leap seconds, etc. 
> Also, I see references to POXIS and Unix in System.Time.Calendar. What is 
> the portability of this module? Will it be implemented for Windows?

It needs only localtime_r and gettimeofday, everything else is Haskell. 
If those exist on Windows, or can be created, then yes.

ISSUE: Will the dependence on localtime_r be a problem for older systems?

> Use cases (primarily taken from real-world corporate IT applications I have 
> developed) :
> * What is the equivalent (or closest aproximation) of the SQL DateTime type 
> (date and time without any timezone information)? What is the equivalent of 
> the SQL Date type (date without any timezone information)?

SQL DateTime: DayAndTime GregorianDay
ISSUE: Should I make a type synonym for this? I'd call it 

SQL Date: GregorianDay

Neither include timezone.

> * The user enters a date as "7/4/2005." How do I determine if this date is 
> before or after July 1st of this year?

TODO: Parsing

> * How do I present the date "July 1st of this year" to the user in M/D/YYYY 
> format?

    now <- getCalendarTime
    let thisYear = ctYear now
    let day = GregorianDay thisYear 7 1
    return (formatTime defaultTimeLocale "%m/%d/%Y" day)

This actually gives "07/01/2005" rather than "7/1/2005".
ISSUE: Should I make additional %-codes for this?

> * How do I truncate a datetime to midnight of the same day?

  datetime{dtTime = midnight}

> How do I truncate a date to the first of the month?

  date{gregDay = 1}  

> How do I truncate a date to the first day of the year it occurred in?

  date{gregMonth = 1,gregDay = 1}

> * Given a date X, how do I find the last day of the month that X occurs in. 
> For example, If X is July 4th, 2005, then I want the result to be July 31st, 
> 2005. If X is Februrary 5, then I want the result to be Februrary 28 for 
> non-leap-years and February 29 for leap years.

This one's ugly:

  lastOfTheMonth (GregorianDay y m _) = let
    m' = (m % 12) + 1
    y' = if m == 12 then y + 1 else y
    day = (GregorianDay y' m' 1) in
    encodeDay ((decodeDay day) - 1)

ISSUE: What kind of "Gregorian arithmetic" should I add, if any?

> * The user enters a time T with no date, e.g. "17:30". How do I merge this 
> time onto a date D (e.g. July 4, 2005), so that the result has is a datetime 
> with date D and the time T (July 4, 2005 at 17:30).

  DayAndTime d t

> * Given two datetimes T1, T2, how do I determine if they are on the same 
> date?

  dtDay t1 == dtDay t2

Thanks, these are really good.

Ashley Yakeley, Seattle WA

More information about the Libraries mailing list