~brettgilio/org-webring

1

Re: [PATCH] Add support for atom feeds

Jamie Beardslee
Details
Message ID
<87wo1ln8ta.fsf@jamzattack.xyz>
DKIM signature
pass
Download raw message
Ah, damn.  I was very worried about the time format so I did a bunch of
research about it, only to find that parse-time-string's docstring says:

| STRING should be an ISO 8601 time string, e.g.,
| "2020-01-15T16:12:21-08:00", or something resembling an RFC 822 (or
| later) date-time, e.g., "WED, 15 Jan 2020 16:12:21 -0800".
(rfc3339 is a subset of ISO 8601)

Turns out this is in the NEWS file for Emacs 27...

Is it too early to consider 27 the baseline?  Maybe we should fallback
to a minimal parser if (fboundp 'iso8601-parse) returns nil, or perhaps
the trusty 1 Jan 1970?

Let me know what you think.

--
Jamie

Re: [PATCH] Add support for atom feeds

Details
Message ID
<87wo1lye2z.fsf@posteo.ro>
In-Reply-To
<87wo1ln8ta.fsf@jamzattack.xyz> (view parent)
DKIM signature
pass
Download raw message
Jamie Beardslee <jdb@jamzattack.xyz> writes:

> Is it too early to consider 27 the baseline?  Maybe we should fallback
> to a minimal parser if (fboundp 'iso8601-parse) returns nil, or perhaps
> the trusty 1 Jan 1970?
>
> Let me know what you think.

The minimal parse you're talking about sounds like a good idea.

While Emacs 26.3 doesn't know how to parse this whole thing:
"2020-01-22T00:00:00+00:00", it can partially understand this:
"2020-01-22".

--8<---------------cut here---------------start------------->8---
(parse-time-string "2020-01-22T00:00:00+00:00")
=> (nil nil nil nil nil nil nil nil nil)

(parse-time-string "2020-01-22")
=> (nil nil nil 22 1 2020 nil nil nil)
--8<---------------cut here---------------end--------------->8---

Here's what RFC 3339 says about the format of timestamps:

--8<---------------cut here---------------start------------->8---
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
--8<---------------cut here---------------end--------------->8---

That means that we can always extract the first 10 characters of the
timestamp (full-date) and get something Emacs can parse.

Better yet, we can extract what is named partial-time in the spec above
as it is the 8 characters after the "T", getting something like
"2020-01-22 00:00:00". And guess what?

--8<---------------cut here---------------start------------->8---
(parse-time-string "2020-01-22 00:00:00")
=> (0 0 0 22 1 2020 nil nil nil)
--8<---------------cut here---------------end--------------->8---

Less nils! This can even be plugged into encode-time! Basically
everything we need. 

Get the first 19 characters of the timestamp and replace "T" with a
space. What do you think?

--
Sergiu
Export thread (mbox)