Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davep/10e313b66b3b8c6e4f52788c7e9fe532 to your computer and use it in GitHub Desktop.
Save davep/10e313b66b3b8c6e4f52788c7e9fe532 to your computer and use it in GitHub Desktop.
A snippet that shows how to convert a feedparser time.struct_time object to a Django datetime with timezone support.
from django.utils import timezone
import time
# feed = object from DB
# doc = parsed feedparser object
feed.updated_at = doc.feed.get('updated_parsed', timezone.now())
if isinstance(feed.updated_at, time.struct_time):
feed.updated_at = timezone.make_aware(
timezone.datetime(*feed.updated_at[:-3]),
timezone.get_default_timezone())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment