-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include timezone in feed_dates #769
base: master
Are you sure you want to change the base?
Conversation
This is happening because the import datetime
from dateutil.parser import parse
print parse("2024-12-04T21:12:00").strftime("%a, %d %b %Y %H:%M:%S %Z")
print parse("2024-12-04T21:12:00Z").strftime("%a, %d %b %Y %H:%M:%S %Z") outputs:
I was looking over the RFC822 spec. But it doesn't identify "UTC" in the documentation. "UT", "GMT", "Z", "+0000" are and are equivalent. However, as shown above, "UTC" is output for the "%Z" specifier. That's not to say it is compatible. Some Stackoverflow discussion on this point. I'd probably just use "Z". Also, please merge from master to bring this branch forward. |
Thanks @bradchoate that makes sense! |
Yeah, "Z" or "+0000" are the desired outcomes. It looks like |
I added a new helper, I can only build the containers if I check out the |
# Make sure the datetime object is timezone aware | ||
if time.tzinfo == None or time.tzinfo.utcoffset(time) == None: | ||
time.replace(tzinfo=timezone.utc) | ||
return time.strftime("%a, %d %b %Y %H:%M:%S %Z") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the comment for the PR reference.
Also, the "Z" I was suggesting earlier was to use a literal Z
instead of %Z
.
I don't think the parse
import is needed, is it? I don't see it being used.
The current build failure is coming from an invalid import of timezone
, which doesn't exist for Python 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to remove the parse
and timezone
imports. I'd simplify to:
datetime_format = "%a, %d %b %Y %H:%M:%S"
# If time argument has no timezone information, assume UTC ("Z")
if time.tzinfo == None or time.tzinfo.utcoffset(time) == None:
format = datetime_format + " Z"
else:
format = datetime_format + " %Z"
return time.strftime(format)
On Slack, snarkout writes:
Indeed, looking at the RSS feed, I see e.g.
<pubDate>Wed, 04 Dec 2024 00:53:36 </pubDate>
. Interestingly we do try to include timezones when formatting the dates, but I suppose since the timezone isn't stored explicitly, the%Z
just resolves to an empty string after the time.This PR replaces all the non-functional
%Z
with hardcodedUTC
.