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 f6fb733
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions openvpn_status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from netaddr import EUI, mac_unix


DATETIME_FORMAT_OPENVPN = u'%a %b %d %H:%M:%S %Y'
DATETIME_FORMAT_OPENVPN_V2_5 = u'%Y-%m-%d %H:%M:%S'
DATETIME_FORMAT_OPENVPN_V2_4 = 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)
RE_VIRTUAL_ADDR_NETWORK = re.compile(u'/(\\d{1,3})$')
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_V2_5)
except:
return datetime.datetime.strptime(time, DATETIME_FORMAT_OPENVPN_V2_4)


def parse_peer(peer):
Expand Down

0 comments on commit f6fb733

Please sign in to comment.