RFC 2822 filestamp

One thing that was a real pain when I was trying to generate an RSS feed from a script was how to format the timestamp on the files.

Both stat and the ls commands out of the gate produced a format that produced lots of nonsense when trying to validate:

element pubDate: Schemas validity error : Element 'pubDate': [facet 'pattern'] The value 'Thu May 28 22:53:18 EDT 2009' is not accepted by the pattern '(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)), *)?\d\d? +((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec)) +\d\d(\d\d)? +\d\d:\d\d(:\d\d)? +(([+\-]?\d\d\d\d)|(UT)|(GMT)|(EST)|(EDT)|(CST)|(CDT)|(MST)|(MDT)|(PST)|(PDT)|\w)'.

element lastBuildDate: Schemas validity error : Element 'lastBuildDate': 'Thu May 28 22:53:18 EDT 2009' is not a valid value of the atomic type 'Rfc822FormatDate'.

The XSD I have calls it “RFC 822”, but the date man page calls it “RFC 2822”, whatever you call it, I finally produced it like this:

% ls -l myfile --time-style=+'%a, %d %b %Y %T %z' | cut -f6-11 -d' '

The date command has a nice flag (-R) that will print in this format too:

% date -R ; date +'%a, %d %b %Y %T %z' 
Fri, 29 May 2009 10:14:53 -0400
Fri, 29 May 2009 10:14:53 -0400

It’s nutty…http://brianin3d-demos.appspot.com/static/rss.xml

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: