Skip to content
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

make use of the newer format for dates #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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