[m-rev.] for review: Java implementation of time library (revised)
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Dec 15 18:03:53 AEDT 2003
On 15-Dec-2003, James Goddard <goddardjames at yahoo.com> wrote:
> Implemented some library functions for the time library in java.
That looks good now, but I think it is worth adding some test cases
to test the tricky times around the daylight savings time transition.
> +:- pragma foreign_proc("Java",
> + time__c_mktime(Yr::in, Mnt::in, MD::in, Hrs::in, Min::in, Sec::in,
> + _YD::in, _WD::in, N::in, Time::out),
> + [will_not_call_mercury, promise_pure],
> +"
> + java.util.GregorianCalendar gc = new java.util.GregorianCalendar(
> + Yr + 1900, Mnt, MD, Hrs, Min, Sec);
> +
> + Time = gc.getTime();
> +
> + // If the time we constructed is not in daylight savings time, but
> + // it should be, we need to add the DST offset.
> + if (N == 1 && gc.getTimeZone().inDaylightTime(Time) == false) {
> + Time.setTime(Time.getTime() +
> + gc.get(java.util.Calendar.DST_OFFSET));
Here I think it would be worth double-checking that
gc.getTimeZone().inDaylightTime(Time) has the expected value
(true) after the adjustment, and if not, throwing an exception.
> + }
> +
> + // Likewise, if the time is in DST, but should not be, we need to
> + // subtract the offset.
> + if (N == 0 && gc.getTimeZone().inDaylightTime(Time) == true) {
> + Time.setTime(Time.getTime() -
> + gc.get(java.util.Calendar.DST_OFFSET));
Likewise here.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list