goog.date.DateTime and RFC822 Date Time Format

447 views
Skip to first unread message

babbos

unread,
Jun 15, 2010, 9:51:53 AM6/15/10
to Closure Library Discuss
Hello there,

I keep being troubled as to how to initialize properly an RFC 822 type
date using goog.date.DateTime().

The server sends RFC822 datetime format, e.g.:
Wed, 26 May 2010 23:17:17 +0200

How do i get a valid instance of goog.date.DateTime() from this value?

I tried using:
var gdate = goog.date.fromIsoString(rfc822datetime);
it returned null of course as it expects an ISO8601 formated string

I also tried chopping up the string into year, month, day [...] parts,
but could not figure out how to set the timezone (+0200)

Be well

Emil A Eklund

unread,
Jun 15, 2010, 2:08:06 PM6/15/10
to closure-lib...@googlegroups.com
On Tue, Jun 15, 2010 at 06:51, babbos <bab...@gmail.com> wrote:
> Hello there,
>
> I keep being troubled as to how to initialize properly an RFC 822 type
> date using goog.date.DateTime().
>
> The server sends RFC822 datetime format, e.g.:
> Wed, 26 May 2010 23:17:17 +0200
>
> How do i get a valid instance of goog.date.DateTime() from this value?

I don't think we have a way to directly construct a goog.ui.DateTime
object from an rfc822 string directly. You could try to go through a
native date object, like this.

var d = new goog.date.DateTime(new Date('Wed, 02 Oct 2002 08:00:00 EST'));

--
Emil

babbos

unread,
Jun 15, 2010, 3:50:11 PM6/15/10
to Closure Library Discuss
Thank you Emil,

So are there any plans on supporting it?

The whole web2.0 relies on this format... (rss, atom...)

Thank you for your time!

Emil A Eklund

unread,
Jun 15, 2010, 4:33:10 PM6/15/10
to closure-lib...@googlegroups.com
On Tue, Jun 15, 2010 at 12:50, babbos <bab...@gmail.com> wrote:
> Thank you Emil,
>
> So are there any plans on supporting it?

Yeah, we should probably add a method like goog.date.fromRfc822String.

--
Emil

Nathan Naze

unread,
Jun 15, 2010, 4:35:18 PM6/15/10
to closure-lib...@googlegroups.com

babbos, can you file an issue? Both Python and Closure don't have
good support for RFC822 which annoys me when working with Atom feeds.

Thanks,

Nathan

Thomas Broyer

unread,
Jun 16, 2010, 8:32:45 AM6/16/10
to Closure Library Discuss

[OFF TOPIC]
Er, Atom is only using a RFC3339/ISO8601/W3C-DateTime/XMLSchema-
DateTime compatible format. (actually a subset of RFC3339 which
happens to also be a subset of the other 3)
See http://tools.ietf.org/html/rfc4287#section-3.3

The crappy thing called "RSS" sure uses RFC 822, but not Atom, which
has been designed to be machine-readable (RSS is so loosely defined
that it isn't even parsed as XML most of the time, which has lead to
many feeds not being well-formed XML on the wild, so parsing RSS
requires you to parse some "tag soup")
See http://en.wikipedia.org/wiki/Atom_%28standard%29#Date_formats

Nathan Naze

unread,
Jun 16, 2010, 1:07:11 PM6/16/10
to closure-lib...@googlegroups.com
On Wed, Jun 16, 2010 at 5:32 AM, Thomas Broyer <t.br...@gmail.com> wrote:
>
> [OFF TOPIC]
>
> On Jun 15, 10:35 pm, Nathan Naze <nn...@google.com> wrote:
>> On Tue, Jun 15, 2010 at 1:33 PM, Emil A Eklund <e...@google.com> wrote:
>>
>> > On Tue, Jun 15, 2010 at 12:50, babbos <bab...@gmail.com> wrote:
>> >> Thank you Emil,
>>
>> >> So are there any plans on supporting it?
>>
>> > Yeah, we should probably add a method like goog.date.fromRfc822String.
>>
>> babbos, can you file an issue?  Both Python and Closure don't have
>> good support for RFC822 which annoys me when working with Atom feeds.
>
> Er, Atom is only using a RFC3339/ISO8601/W3C-DateTime/XMLSchema-
> DateTime compatible format. (actually a subset of RFC3339 which
> happens to also be a subset of the other 3)
> See http://tools.ietf.org/html/rfc4287#section-3.3

Yes, you're right. I don't have the RFC numbers memorized, nor am I an
expert in the area. I just know Atom's preferred format can be hard
to parse in Python. Regardless, an implementation would be useful in
Closure (of both, I guess).

http://en.wikipedia.org/wiki/Atom_(standard)#Date_formats

Nathan

Thomas Broyer

unread,
Jun 17, 2010, 6:53:51 AM6/17/10
to Closure Library Discuss


On 16 juin, 19:07, Nathan Naze <nn...@google.com> wrote:
> On Wed, Jun 16, 2010 at 5:32 AM, Thomas Broyer <t.bro...@gmail.com> wrote:
>
> > [OFF TOPIC]
>
> > On Jun 15, 10:35 pm, Nathan Naze <nn...@google.com> wrote:
> >> On Tue, Jun 15, 2010 at 1:33 PM, Emil A Eklund <e...@google.com> wrote:
>
> >> > On Tue, Jun 15, 2010 at 12:50, babbos <bab...@gmail.com> wrote:
> >> >> Thank you Emil,
>
> >> >> So are there any plans on supporting it?
>
> >> > Yeah, we should probably add a method like goog.date.fromRfc822String.
>
> >> babbos, can you file an issue?  Both Python and Closure don't have
> >> good support for RFC822 which annoys me when working with Atom feeds.
>
> > Er, Atom is only using a RFC3339/ISO8601/W3C-DateTime/XMLSchema-
> > DateTime compatible format. (actually a subset of RFC3339 which
> > happens to also be a subset of the other 3)
> > Seehttp://tools.ietf.org/html/rfc4287#section-3.3
>
> Yes, you're right. I don't have the RFC numbers memorized, nor am I an
> expert in the area.  I just know Atom's preferred format can be hard
> to parse in Python.  Regardless, an implementation would be useful in
> Closure (of both, I guess).
>
> http://en.wikipedia.org/wiki/Atom_(standard)#Date_formats

If you're lazy, this regex is enough to parse an Atom-formatted date:
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d*)?(Z|([+-])
(\d{2}):(\d{2}))/
Usable in both Python and JavaScript, you then just have to pass the
matched groups to some Date constructor (just beware of the timezone,
particularly in JS, but I guess Closure already deals with this)

Also have a look at the Universal Feed Parser and feedvalidator
projects (for both RSS and Atom, parsing only), both written in
Python:
http://feedparser.org/docs/date-parsing.html
http://code.google.com/p/feedvalidator/source/browse/trunk/feedvalidator/src/feedvalidator/validators.py#479

babbos

unread,
Jun 17, 2010, 12:05:35 PM6/17/10
to Closure Library Discuss
Reply all
Reply to author
Forward
0 new messages