Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
use the pendulum parser to parse the dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Lechte authored and djrobstep committed Oct 14, 2016
1 parent c49ec75 commit e24d0ff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dmutils/formats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import pytz
import pendulum

DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
DATE_FORMAT = "%Y-%m-%d"
Expand Down Expand Up @@ -40,7 +41,7 @@ def __init__(self, tz_name='UTC'):

def _format(self, value, fmt):
if not isinstance(value, datetime):
value = datetime.strptime(value, DATETIME_FORMAT)
value = pendulum.parse(value)
if value.tzinfo is None:
value = pytz.utc.localize(value)
return value.astimezone(self.timezone).strftime(fmt)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ WTForms==2.1
Flask-Script==2.0.5
waitress==0.9.0
workdays==1.4
pendulum==0.6.2

0 comments on commit e24d0ff

Please sign in to comment.