abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Berry <chriswbe...@gmail.com>
Subject Re: AtomDate bug
Date Mon, 03 Dec 2007 14:33:40 GMT
Hi James,
I ended up grabbing a copy of AtomDate from the SVN Head and using it  
(since it has no further dependencies)
I ended out finding a couple of other issues w/ the 0.3.0 version. It  
also did not properly recognize the timezones (e.g. +06:00)
And the SVN Head copy works a charm.
Thanks,
-- Chris 

On Dec 2, 2007, at 6:07 PM, James M Snell wrote:

> In the trunk, AtomDate has been changed to use a regex pattern to  
> parse
> dates in order to improve performance.  If you would, please try your
> tests with the trunk and let me know what problems you're seeing.  We
> can tweak the regex accordingly.
>
> - James
>
> Chris Berry wrote:
>> Greetings,
>> I have found a subtle but dangerous bug in AtomDate (v0.3.0)
>> AtomDate walks thru a series of masks, trying each, until it either
>> finds a match, or, if not, throws an Exception.
>> The problem is that, when a date string with a bad "time section" is
>> used, SimpleDateFormat will go on to match the "date section"
>> And thus, give the user something entirely different from what they
>> wanted, rather than throw an Exception
>>
>> Here is an example:
>>
>>         String ddd = "2007-11-30T23:59:59:000Z";
>>         Date upmin = AtomDate.parse( ddd );
>>         log.debug( "********************* ddd= " + ddd );
>>         log.debug( "********************* upmin= " + upmin );
>>         log.debug( "********************* upmin GMT= " +
>> upmin.toGMTString() );
>>
>> NOTE: The correct string should be "2007-11-30T23:59:59.000Z";  <===
>> 59dot000 (59.000) instead of 59colon000 (59:000) -- a pretty easy
>> mistake, and hard to see
>>
>> AtomDate then sees this as::
>>
>> AtomDate: parsing:: 2007-11-30T23:59:59:000Z
>> trying mask= yyyy-MM-dd'T'HH:mm:ss.SSSz
>> trying mask= yyyy-MM-dd't'HH:mm:ss.SSSz
>> trying mask= yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
>> trying mask= yyyy-MM-dd't'HH:mm:ss.SSS'z'
>> trying mask= yyyy-MM-dd'T'HH:mm:ssz
>> trying mask= yyyy-MM-dd't'HH:mm:ssz
>> trying mask= yyyy-MM-dd'T'HH:mm:ss'Z'
>> trying mask= yyyy-MM-dd't'HH:mm:ss'z'
>> trying mask= yyyy-MM-dd'T'HH:mmz
>> trying mask= yyyy-MM-dd't'HH:mmz
>> trying mask= yyyy-MM-dd'T'HH:mm'Z'
>> trying mask= yyyy-MM-dd't'HH:mm'z'
>> trying mask= yyyy-MM-dd
>> [12/02/07 17:11:48:683] DEBUG - EntryURIHelperTest         -
>> ********************* ddd= 2007-11-30T23:59:59:000Z
>> [12/02/07 17:11:48:684] DEBUG - EntryURIHelperTest         -
>> ********************* upmin= Thu Nov 29 18:00:00 CST 2007
>> [12/02/07 17:11:48:685] DEBUG - EntryURIHelperTest         -
>> ********************* upmin GMT= 30 Nov 2007 00:00:00 GMT
>>
>> NOTE: AtomDate has matched "yyyy-MM-dd"
>> And thus, changed the value from   "30 Nov 2007 23:59:59 GMT"  to   
>> "30
>> Nov 2007 00:00:00 GMT" -- 24 hrs earlier !!!
>>
>> I'm not too sure how this should be fixed?? (Using setLenient(false)
>> will NOT fix it)
>> I think just checking String length before switching to "date  
>> only" will
>> result in the correct behavior.
>>
>> Something like this works (but isn't too pretty ;-)
>>
>>    private static final int checkLengthStartingIndex = 12;
>>
>>   /**
>>    * Parse the serialized string form into a java.util.Date
>>    * @param date The serialized string form of the date
>>    * @return The created java.util.Date
>>    */
>>   public static Date parse(String date) {
>>
>>     .....
>>
>>     Date d = null;
>>     SimpleDateFormat sdf = new SimpleDateFormat();
>>     for (int n = 0; n < masks.length; n++) {
>>       try {
>>         sdf.applyPattern(masks[n]);
>>         sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
>>
>>         //sdf.setLenient(true);
>>         // cwb >>>
>>         sdf.setLenient(false);
>>         if ( n >= checkLengthStartingIndex ) {
>>             if ( date.length() != masks[n].length() )
>>                 continue;
>>         }
>>         // cwb <<<
>>
>> Cheers,
>> -- Chris
>> S'all good  ---   chriswberry at gmail dot com
>>
>>
>>
>>

S'all good  ---   chriswberry at gmail dot com




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message