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

Replace custom iso8601 datetime parse implementation with built-in #154

Merged
merged 1 commit into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pyperf/_bench.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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