[MLton-user] Strange date behaviour

Joe Hurd joe at gilith.com
Sat Jul 7 18:25:08 PDT 2007


Thanks for that. As I said I don't need to handle dates before 1900
right now, but I'll be pleased to pick up the more general code on the
next release.

Joe

On 7/7/07, Matthew Fluet <fluet at tti-c.org> wrote:
> On Thu, 5 Jul 2007, Matthew Fluet wrote:
> > 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
>
> I've checked in a fix for this bug.  As noted above, for those not wishing
> to recompile mlton for this bug, it suffices to effect the following
> patch:
>
> Index: system/date.sml
> ===================================================================
> --- system/date.sml       (revision 5731)
> +++ system/date.sml       (revision 5732)
> @@ -160,8 +160,7 @@
>       (* Check whether date may be passed to ISO/ANSI C functions: *)
>
>       fun okDate (T {year, month, day, hour, minute, second, ...}) =
> -        1900 <= year
> -        andalso 1 <= day    andalso day    <= monthdays year month
> +        1 <= day    andalso day    <= monthdays year month
>           andalso 0 <= hour   andalso hour   <= 23
>           andalso 0 <= minute andalso minute <= 59
>           andalso 0 <= second andalso second <= 61 (* leap seconds *)
>
> The location of system/date.sml depends on your installation.  If mlton
> has been installed system-wide, it is in /usr/local/lib/mlton/sml/basis.
> If mlton has been built from source, it is in <src>/build/lib/sml/basis.
>



More information about the MLton-user mailing list