users@jaxb.java.net

Re: Daylight Savings Time problem and JAXB: HELP!

From: Lawrence, Gabriel <glawrence_at_ucsd.edu>
Date: Wed, 23 Apr 2003 12:08:55 -0700

So... the xsd definition for the problem elements looks like:

  <attribute name="NotBefore" type="dateTime" use="optional"/>
  <attribute name="NotOnOrAfter" type="dateTime" use="optional"/>

so the idea is that when I get the document I need to check to make sure
that now is after NotBefore and before NotOnOrAfter.

The problem I seem to be having is that for some reason the Calendar
objects I'm getting are not correct. So the now.after(notbefore) &&
now.before(notonorafter) is false... This only happened when the time
changed...

Here's the output of the calendar objects themselves:

     [java] now
     [java]
java.util.GregorianCalendar[time=1051124555853,areFieldsSet=true,are
AllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Ameri
ca/Los_A
ngeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions
=185,las
tRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,d
stSaving
s=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay
=1,start
DayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDa
y=-1,end
DayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDays
InFirstW
eek=1,ERA=1,YEAR=2003,MONTH=3,WEEK_OF_YEAR=17,WEEK_OF_MONTH=4,DAY_OF_MON
TH=23,DA
Y_OF_YEAR=113,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=0,HOUR_O
F_DAY=12
,MINUTE=2,SECOND=35,MILLISECOND=853,ZONE_OFFSET=-28800000,DST_OFFSET=360
0000]
     [java] getNotBefore
     [java]
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSe
t=false,lenient=true,zone=java.util.SimpleTimeZone[id=custom,offset=-288
00000,ds
tSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,
startDay
=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=0,endMonth=0,end
Day=0,en
dDayOfWeek=0,endTime=0,endTimeMode=0],firstDayOfWeek=1,minimalDaysInFirs
tWeek=1,
ERA=?,YEAR=2003,MONTH=3,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=23,D
AY_OF_YE
AR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=12,
MINUTE=2
,SECOND=33,MILLISECOND=916,ZONE_OFFSET=?,DST_OFFSET=?]
     [java] getNotAfter
     [java]
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSe
t=false,lenient=true,zone=java.util.SimpleTimeZone[id=custom,offset=-288
00000,ds
tSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,
startDay
=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=0,endMonth=0,end
Day=0,en
dDayOfWeek=0,endTime=0,endTimeMode=0],firstDayOfWeek=1,minimalDaysInFirs
tWeek=1,
ERA=?,YEAR=2003,MONTH=3,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=23,D
AY_OF_YE
AR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=12,
MINUTE=7
,SECOND=33,MILLISECOND=916,ZONE_OFFSET=?,DST_OFFSET=?]

And when I compare them as above things are not happy.

Ugh.

-gabe

-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Wednesday, April 23, 2003 11:28 AM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: Daylight Savings Time problem and JAXB: HELP!

I tried the following schema:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="foo" type="xs:dateTime" />
    </xs:schema>

... with the following document:

    <foo>2003-04-23T09:47:23.211-08:00</foo>

and unmarshalled a document, then marshalled it back to XML, and I got:

    <foo>2003-04-23T09:47:23.211-08:00</foo>

I also printed out the Calendar object in the content tree, and I got:

    java.util.GregorianCalendar[time=?,areFieldsSet=false,
    areAllFieldsSet=false,lenient=true,zone=java.util.SimpleTimeZone[i
    d=custom,offset=-28800000,dstSavings=3600000,useDaylight=false,
    startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,
    startTime=0,startTimeMode=0,endMode=0,endMonth=0,endDay=0,
    endDayOfWeek=0,endTime=0,endTimeMode=0],firstDayOfWeek=1,
    minimalDaysInFirstWeek=1,ERA=?,YEAR=2003,MONTH=3,WEEK_OF_YEAR=?,
    WEEK_OF_MONTH=?,DAY_OF_MONTH=23,DAY_OF_YEAR=?,DAY_OF_WEEK=?,
    DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=9,MINUTE=47,
    SECOND=23,MILLISECOND=211,ZONE_OFFSET=?,DST_OFFSET=?]

If you look at it, it shows it's not seting the daylight saving time
with the time zone, which is correct. (Since you can't tell if you
should apply time zone just from "-08:00")

Now, if I call the Calendar.getTime() method, it will turn it into a
Date object, but the Date object don't keep the time zone in it. So it
just uses the default system time zone, which is why you see PDT.

I don't fully understand the problem you described, but hopefully this
will give you enough clue to get things right.


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com