Actually, because the formatter was created with SimpleDateFormat,
it assumes that the date will be in the local time zone. While I
certainly can't argue for the excellence of my solution (I didn't want
to modify more than I had to), I used the inherited .setTimeZone()
method to tell SimpleDateFormat that the passed string will be in
GMT time. The comment I added was to indicate that, after instantiation,
the xmlFormat field was a DateFormat instance that assumed local
timezone. I'd rather have put in a static method to instantiate it rather
than continuing to use the one-line initializer, but I'm not
entirely familiar with your coding standards or conventions. The
patch is a working example of what should happen, though.
svn -log actually puts out dates in a local time zone but adds an offset
in for information on converting to GMT: "hh:mm:ss Z", or for
example "04:39:24 -8000" The xml string looks like "HH:mm:ss.SSSSSS",
with a trailing Z that the formatter wouldn't know what to do with anyway,
or for example "04:39:24.253407Z". Z is only useful in parse format strings
and isn't understood as content.
-Jen
Mark Phippard wrote:
>I want to apply this patch, but I am confused about the comment you added
>in the patch:
>
> + // This formatter uses local timezone, not GMT.
>
>This seems contradictory. Isn't the issue that svn log --xml outputs
>dates in GMT, and that is what is passed to the method. Therefore, we
>need to tell date formatter that it is getting a date in GMT timezone? If
>so, shouldn't the comment say the opposite, that the formatter expects
>GMT?
>
>Mark
>
>
>
>Jennifer Bevan <jen@alouysius.net> wrote on 01/05/2005 05:31:24 PM:
>
>
>
>>Hi,
>>I believe there is an error in the svnClientAdapter command line xml
>>
>>
>date
>
>
>>parsing. Helper.java (r1184) uses a SimpleDateFormat to parse the XML
>>date, but does not set the time zone to be GMT -- but the XML document
>>parser converts the log message time (format is HH:mm:ss Z) to GMT.
>>So, I kept noticing a double-shift in my reported times. To test, I
>>committed
>>to my test repository at 1:08pm PST:
>>
>>jen@bang:/tmp/hello <1113> svn log
>>------------------------------------------------------------------------
>>r21 | tester | 2005-01-05 13:08:33 -0800 (Wed, 05 Jan 2005) | 3 lines
>>
>>But svnClientAdaptor's CmdLineLogMessage.getDate() kept telling
>>me that the commit occured at 5:08 AM the next day -- which is
>>twice the 8 hour offset. I narrowed it down to the xml parser shifting
>>it by 8 hours to GMT, and then Helper.java:convertXMLDate returning
>>that time as a local time (9:08pm PST, in my case), which of course
>>would then get
>>shifted by 8 hours the next time I printed it out as GMT.
>>
>>So, I have a patch, of course. Now my reported dates match my
>>expected dates. Of course, there are some dependency issues here:
>>is anyone expecting the date returned in CmdLineLogMessage to
>>be a localized date? It would seem like there shouldn't be, but that's
>>why I'm posting here...
>>
>>Thanks,
>>Jennifer Bevan
>>
>>Index: Helper.java
>>===================================================================
>>--- Helper.java (revision 1184)
>>+++ Helper.java (working copy)
>>@@ -35,6 +35,7 @@
>> new SimpleDateFormat("yyyy-MM-dd hh:mm:ss Z");
>>
>> // 2003-10-13T12:54:42.957948Z
>>+ // This formatter uses local timezone, not GMT.
>> private static DateFormat xmlFormat =
>> new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
>>
>>@@ -74,12 +75,15 @@
>> }
>>
>> static Date convertXMLDate(String date) {
>>- if (date == null)
>>- return null;
>>- try {
>>- return xmlFormat.parse(date);
>>- } catch (ParseException e1) {
>>- return null;
>>+ Date result = null;
>>+ if (date != null) {
>>+ try {
>>+
>>xmlFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
>>+ result = xmlFormat.parse(date);
>>+ } catch (ParseException e1) {
>>+ System.out.println(e1.getMessage());
>>+ }
>> }
>>+ return(result);
>> }
>> }
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: dev-unsubscribe@subclipse.tigris.org
>>For additional commands, e-mail: dev-help@subclipse.tigris.org
>>
>>
>>
>>
>>
>_____________________________________________________________________________
>
>
>>Scanned for SoftLanding Systems, Inc. by IBM Email Security Management
>>Services powered by MessageLabs.
>>
>>
>>
>_____________________________________________________________________________
>
>
>_____________________________________________________________________________
>Scanned for SoftLanding Systems, Inc. by IBM Email Security Management Services powered by MessageLabs.
>_____________________________________________________________________________
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@subclipse.tigris.org
>For additional commands, e-mail: dev-help@subclipse.tigris.org
>
>
>
>
Received on Fri Jan 7 03:22:14 2005