[MLton-user] Strange date behaviour

Matthew Fluet matthew.fluet at gmail.com
Thu Jul 5 11:08:38 PDT 2007


On 7/5/07, Joe Hurd <joe at gilith.com> wrote:
> Am I being stupid here, or is Date.fmt throwing a bogus exception?
>
> I'm experiencing this on both Mac OS X (i386) and Linux (i386).
>
> Joe
>
> fel-hurd:~$ mlton
> MLton MLTONVERSION (built Mon Oct 30 23:08:10 2006 on frogbat.local)
> fel-hurd:~$ cat t.sml
> print (Date.fmt
>          "%d/%m/%Y"
>          (Date.date
>             {year = 1876, month = Date.Apr, day = 19,
>              hour = 0, minute = 0, second = 0,
>              offset = NONE}));
> fel-hurd:~$ mlton t.sml
> fel-hurd:~$ ./t
> unhandled exception: Date

There appears to be a check in $(SML_LIB)/basis/system/date.sml that
raises Date when the year is <= 1900 and converting a date to a struct
tm (defined in <time.h>).  The comment claims to check whether the
date may be passed to ISO/ANSI C functions.  The documentation for
<time.h> [1] says that the struct tm includes the component:
   int    tm_year  Years since 1900.
That seems to be the origin of the check.  However, later in the
documentation, it says:
   tm_year is a signed value; therefore, years before 1900 may be represented.
Hence, it seems that the check can safely be removed.

[1] http://www.opengroup.org/onlinepubs/009695399/basedefs/time.h.html



More information about the MLton-user mailing list