abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Berry <chriswbe...@gmail.com>
Subject AtomDate
Date Wed, 09 Jan 2008 03:54:36 GMT
Greetings,

The AtomDate class is not adhering to the RFC3339 spec (see below)   
IIRC, this is somewhat by design??

But unfortunately, it its current state the regex PATTERN in AtomDate

     private static final Pattern PATTERN = Pattern.compile(
       "(\\d{4})(?:-(\\d{2}))?(?:-(\\d{2}))?(?:[Tt](?:(\\d{2}))?(?::(\ 
\d{2}))?(?::(\\d{2}))?(?:\\.(\\d{3}))?)?([Zz])?(?:([+-])(\\d{2}):(\\d 
{2}))?");

allows dates like this:: "12012007" to be interpreted as::   
'1200-12-31 18:00:00.0' in the CST timezone.
Obviously the caller should have used "20071201".
But it seems to me that Abdera should be strict about these dates  
(and adhere strictly to the spec)?? (e.g. "2007-12-01")
Otherwise these dates (and thus, errors) can slip through the cracks.  
(In my case to be rejected eventually by the database)

So you could use something like this;

    private static final Pattern PATTERN = Pattern.compile(
       "(\\d{4})-(\\d{2})-(\\d{2})?(?:[Tt](?:(\\d{2}))?(?::(\\d{2}))? 
(?::(\\d{2}))?(?:\\.(\\d{3}))?)?([Zz])?(?:([+-])(\\d{2}):(\\d{2}))?");

  Or better, if you want to be even more specific and restrict month  
and day numbers correctly...

     private static final Pattern PATTERN = Pattern.compile(
     "((?:19|20)\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])?(?: 
[Tt](?:(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(?:\\.(\\d{3}))?)?([Zz])? 
(?:([+-])(\\d{2}):(\\d{2}))?");

NOTE: I have not entirely corrected PATTERN. Only the Date portion.

Thanks,
-- Chris 

======================================
RFC 3339       Date and Time on the Internet: Timestamps       July 2002


5.6. Internet Date/Time Format

    The following profile of ISO 8601 [ISO8601] dates SHOULD be used in
    new protocols on the Internet.  This is specified using the syntax
    description notation defined in [ABNF].

    date-fullyear   = 4DIGIT
    date-month      = 2DIGIT  ; 01-12
    date-mday       = 2DIGIT  ; 01-28, 01-29, 01-30, 01-31 based on
                              ; month/year
    time-hour       = 2DIGIT  ; 00-23
    time-minute     = 2DIGIT  ; 00-59
    time-second     = 2DIGIT  ; 00-58, 00-59, 00-60 based on leap second
                              ; rules
    time-secfrac    = "." 1*DIGIT
    time-numoffset  = ("+" / "-") time-hour ":" time-minute
    time-offset     = "Z" / time-numoffset

    partial-time    = time-hour ":" time-minute ":" time-second
                      [time-secfrac]
    full-date       = date-fullyear "-" date-month "-" date-mday
    full-time       = partial-time time-offset

    date-time       = full-date "T" full-time

       NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
       syntax may alternatively be lower case "t" or "z" respectively.

       This date/time format may be used in some environments or  
contexts
       that distinguish between the upper- and lower-case letters  
'A'-'Z'
       and 'a'-'z' (e.g. XML).  Specifications that use this format in
       such environments MAY further limit the date/time syntax so that
       the letters 'T' and 'Z' used in the date/time syntax must always
       be upper case.  Applications that generate this format SHOULD use
       upper case letters.

       NOTE: ISO 8601 defines date and time separated by "T".
       Applications using this syntax may choose, for the sake of
       readability, to specify a full-date and full-time separated by
       (say) a space character.




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




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