use datetime module to convert string date to numeric date

This commit is contained in:
Axel Kohlmeyer
2021-02-09 14:22:30 -05:00
parent 62a152e4a2
commit 903433d9dd

View File

@ -15,7 +15,7 @@ from .pylammps import *
# convert module string version to numeric version
def get_version_number():
import re
from datetime import datetime
from sys import version_info
vstring = None
if version_info.major == 3 and version_info.minor >= 8:
@ -32,18 +32,7 @@ def get_version_number():
if not vstring:
return 0
vregex = re.compile(r"([0-9]+)([A-Za-z]+)(2[0-9]+)")
m = vregex.match(vstring)
if (m):
month2num = { 'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'May' : 5, 'Jun' : 6,
'Jul' : 7, 'Aug' : 8, 'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12 }
try:
vernum = int(m.group(3))*10000
vernum += month2num[m.group(2)]*100
vernum += int(m.group(1))
except:
exit('Failure to parse version string: %s' % verstr)
return vernum
d = datetime.strptime(vstring, "%d%b%Y")
return d.year*10000 + d.month*100 + d.day
__version__ = get_version_number()