From 06e2723fe0fb66f42bc4ec692702540b374c2635 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 21 Jun 2019 14:42:10 -0400 Subject: [PATCH] Improve date parsing performance strptime attempts are moderately expensive. Detect one common scenario using quicker mechanisms. Change-Id: Id9346678f7def12981417da4d2e6374f457967c5 --- pyghmi/util/parse.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyghmi/util/parse.py b/pyghmi/util/parse.py index eeed100a..a86fddb1 100644 --- a/pyghmi/util/parse.py +++ b/pyghmi/util/parse.py @@ -20,8 +20,9 @@ def parse_time(timeval): if timeval is None: return None try: - retval = datetime.strptime(timeval, '%Y-%m-%dT%H:%M:%SZ') - return retval.replace(tzinfo=tz.tzutc()) + if '+' not in timeval and len(timeval.split('-')) <= 3: + retval = datetime.strptime(timeval, '%Y-%m-%dT%H:%M:%SZ') + return retval.replace(tzinfo=tz.tzutc()) except ValueError: pass try: