Time library design proposal
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Tue Feb 1 18:50:09 EST 2005
"S. Alexander Jacobson" <haskell at alexjacobson.com> writes:
> The Y2K problem
> ---------------
> It would be nice if the library was explicit about whether year was 2
> or 4 digits. Why not define year like this:
>
> newtype Year = Year Int -- don't export constructor
> mkYear century centyear = Year (100*century+centyear)
> mkBigYear millenium cent centyear = ...
Because it's easier to use the actual year number.
> The type of hour minute and second should protect the user from 28
> o'clock and making appointments for 31:101 PM So we probably want:
>
> data Hour = H0 | H1 | H2 ... H23
> data Minute = M0 | M1 | M2 ... M59
> data Second = S0 | S1 | S2 ... S59
> data AMPM = AM | PM
Again, it's simpler to use actual numbers. These values almost never
appear as literals in a program, so they would have to be converted
to/from numbers anyway, which is unnecessary and no other language
does this.
> There are also lots of contexts where you want a time but not a date
> e.g. an alarm clock....
And there are contexts where you want a weekday and hour/minute but
not a month or second (a weekly schedule), contexts where you want
month/day but not a year (a holiday with a fixed date) etc. Where
to stop?
--
__("< Marcin Kowalczyk
\__/ qrczak at knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
More information about the Libraries
mailing list