Skip to content

Commit

Permalink
make use of the newer format for dates
Browse files Browse the repository at this point in the history
  • Loading branch information
vpiserchia committed Sep 19, 2023
1 parent 6eb97d1 commit 686b424
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion openvpn_status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from netaddr import EUI, mac_unix


DATETIME_FORMAT_OPENVPN_OLD = u'%Y-%m-%d %H:%M:%S'
DATETIME_FORMAT_OPENVPN = u'%a %b %d %H:%M:%S %Y'
RE_VIRTUAL_ADDR_MAC = re.compile(
u'^{0}:{0}:{0}:{0}:{0}:{0}$'.format(u'[a-f0-9]{2}'), re.I)
Expand All @@ -21,7 +22,11 @@ def parse_time(time):
"""Parses date and time from input string in OpenVPN logging format."""
if isinstance(time, datetime.datetime):
return time
return datetime.datetime.strptime(time, DATETIME_FORMAT_OPENVPN)
try:
# firs use the newer format
return datetime.datetime.strptime(time, DATETIME_FORMAT_OPENVPN)
except:
return datetime.datetime.strptime(time, DATETIME_FORMAT_OPENVPN_OLD)


def parse_peer(peer):
Expand Down

0 comments on commit 686b424

Please sign in to comment.