Skip to content

Commit

Permalink
replace custom iso8601 datetime parse implementation with built-in
Browse files Browse the repository at this point in the history
  • Loading branch information
GLEF1X committed Jan 8, 2023
1 parent 074fd99 commit 8c3f389
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pyperf/_bench.py
Expand Up @@ -10,7 +10,7 @@
_common_metadata, get_metadata_info,
_exclude_common_metadata)
from pyperf._formatter import DEFAULT_UNIT, format_values
from pyperf._utils import parse_iso8601, median_abs_dev, percentile
from pyperf._utils import median_abs_dev, percentile


# JSON format history:
Expand Down Expand Up @@ -595,7 +595,7 @@ def get_dates(self):
run_start = run._get_date()
if run_start is None:
continue
run_start = parse_iso8601(run_start)
run_start = datetime.datetime.fromisoformat(run_start)

duration = run._get_duration()
duration = int(math.ceil(duration))
Expand Down
16 changes: 0 additions & 16 deletions pyperf/_utils.py
@@ -1,5 +1,4 @@
import contextlib
import datetime
import math
import os
import statistics
Expand All @@ -14,21 +13,6 @@
if MS_WINDOWS:
import msvcrt


def parse_iso8601(date):
if '.' in date:
date, floatpart = date.split('.', 1)
floatpart = float('.' + floatpart)
else:
floatpart = 0
try:
dt = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
except ValueError:
dt = datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S')
dt += datetime.timedelta(seconds=floatpart)
return dt


# A table of 95% confidence intervals for a two-tailed t distribution, as a
# function of the degrees of freedom. For larger degrees of freedom, we
# approximate. While this may look less elegant than simply calculating the
Expand Down
11 changes: 0 additions & 11 deletions pyperf/tests/test_utils.py
@@ -1,4 +1,3 @@
import datetime
import io
import time
import unittest
Expand Down Expand Up @@ -75,16 +74,6 @@ def test_geometric_mean(self):


class TestUtils(unittest.TestCase):
def test_parse_iso8601(self):
# Default format using 'T' separator
self.assertEqual(utils.parse_iso8601('2016-07-20T14:06:07'),
datetime.datetime(2016, 7, 20, 14, 6, 7))
# Microseconds
self.assertEqual(utils.parse_iso8601('2016-07-20T14:06:07.608319'),
datetime.datetime(2016, 7, 20, 14, 6, 7, 608319))
# Space separator
self.assertEqual(utils.parse_iso8601('2016-07-20 14:06:07'),
datetime.datetime(2016, 7, 20, 14, 6, 7))

def test_format_seconds(self):
self.assertEqual(format_seconds(0),
Expand Down

0 comments on commit 8c3f389

Please sign in to comment.