惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

www.infosecurity-magazine.com
www.infosecurity-magazine.com
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
Cloudbric
Cloudbric
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
S
Schneier on Security
L
LangChain Blog
Jina AI
Jina AI
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
T
Tenable Blog
B
Blog RSS Feed
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
W
WeLiveSecurity
I
InfoQ
The Hacker News
The Hacker News
雷峰网
雷峰网
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
Hacker News: Ask HN
Hacker News: Ask HN
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
人人都是产品经理
人人都是产品经理
V
V2EX
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cybersecurity and Infrastructure Security Agency CISA
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
阮一峰的网络日志
阮一峰的网络日志
SecWiki News
SecWiki News
Microsoft Azure Blog
Microsoft Azure Blog

John Bokma's Hacking and Hiking

Failed to verify signature archive-contents.sig in Emacs Aquamacs 3.6 Hangs When Saving An Encrypted File PAR trouble How To Create a Bootable LibreELEC Installation using Mac OS Running pdflatex Using the Alpine Pandoc LaTeX Docker Image A Docker Image for Sass Timezones in Alpine Docker Containers A Tale of Three Docker Images Debugging a Perl Docker container Perl Time::Piece Unicode Issue Giving Docker Desktop for macOS a Second Chance Flashing another TP-Link TL-WDR4300 with OpenWrt firmware Rehousing two tarantulas Getting started with the Perl version of tumblelog on Ubuntu 18.04 LTS A visit to Avonturia De Vogelkelder Flashing a TP-Link TL-WDR4300 with OpenWrt firmware Mounting a VDI File in a Different VirtualBox Guest Wireless Headless Raspberry Pi - John Bokma A Matter of Time - John Bokma Hand coding an RSS 2.0 feed in Python RFC #822 and RFC #3339 dates in Python Hand coding an RSS 2.0 feed in Perl Nav Element with no Heading Rewriting CommonMark Nodes in Perl "right" this time
RFC #822 and RFC #3339 dates in Perl
John Bokma · 2019-10-10 · via John Bokma's Hacking and Hiking

October 9, 2019

When adding a JSON feed and an RSS feed to tumblelog I needed a publication date and time for each article published. As I don't have an actual publication time I decided to use the end of day, as explained in A Matter of Time.

Edit: this blog post has been updated with additional code to make the RFC #822 solution work for a non-USA locale.

The end of day

In order to obtain a Time::Piece Perl object for the local end of day for a given date I came up with the following idea:

  • parse the date with a time of 23:59:59 attached to it
  • create a new object using this result but in the local time zone using the localtime constructor

I accomplished this in Perl as follows:

sub get_end_of_day {

    return Time::Piece->localtime(
        Time::Piece->strptime( shift . ' 23:59:59', '%Y-%m-%d %H:%M:%S' )
    );
}

RFC #822

For the RSS feed I needed the pubDate to be in RFC #822 format, which I obtained by as follows:

my @MON_LIST = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @DAY_LIST = qw( Sun Mon Tue Wed Thu Fri Sat );

my $pub_date = $DAY_LIST[ $end_of_day->_wday() ]
    . sprintf( ', %02d ', $end_of_day->mday() )
    . $MON_LIST[ $end_of_day->_mon ]
    . $end_of_day->strftime( ' %Y %H:%M:%S %z' );

Note that the short month name and the short day name are both looked up instead of returned by strftime. The reason for this is that strftime returns those names in the current locale while RFC #822 requires the USA locale.

Moreover, it's tempting to use %Z instead of %z but note that, for example, CEST is not valid according to the RSS feed validator, which refers to section 5.1 of RFC #822. Hence, why digits must be used instead for a general solution.

An example of a $pub_date value is:

Wed, 09 Oct 2019 23:59:59 +0200

RFC #3339

For the JSON feed I needed a date_published in RFC #3339 format. I also used the strftime method, which almost gives the correct result except that the time returned by %z doesn't contain a colon, so the substitution operator is used to insert this required character.

( my $date_published = $end_of_day->strftime( '%Y-%m-%dT%H:%M:%S%z' ) )
    =~ s/(\d\d)$/:$1/;

An example of a $date_published value is:

2019-10-09T23:59:59+02:00

See Also