Skip to content
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
10 changes: 9 additions & 1 deletion dcaf/shared/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
from dcaf.shared.validation import validate_non_negative


_FLOAT_TOLERANCE = 1e-12
# A floating point absolute error tolerance of 1e-8 is chosen because this is on the order
# of <1 second over a year
# 1e-8 * 365 days = 0.315 sec
# and <1 ms over a day
# 1e-8 * 1 day = 0.864 ms
# While floating point arithmetic has several orders of magnitude more precision than 1e-8,
# this is already a very strict tolerance for the domain setting; DCAF uses the day as the
# base unit of time.
_FLOAT_TOLERANCE = 1e-8


class PeriodTruncationWarning(UserWarning):
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_time_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def test_is_month_end_when_next_day_is_start_of_next_month(day):


# === _whole_days_with_truncation ===
# NOTE: The function implementation uses a floating point tolerance of 1e-8, corresponding to
# <1 second per year and <1 ms per day.


@pytest.mark.parametrize(
Expand All @@ -66,8 +68,10 @@ def test_is_month_end_when_next_day_is_start_of_next_month(day):
(15.5, (15, True)),
(0.5, (0, True)),
(0.0, (0, False)),
(14.0 + 1e-13, (14, False)), # within tolerance of a whole day
(14.0 - 1e-13, (14, False)),
(14.0 + 1e-12, (14, False)), # within tolerance of a whole day
(14.0 - 1e-12, (14, False)),
(14.0 - 5e-9, (14, False)), # just inside the 1e-8 tolerance
(14.0 - 2e-8, (13, True)), # just outside the 1e-8 tolerance
(14.0 - 1e-6, (13, True)), # outside tolerance, so the partial day is dropped
(14.0 + 1e-6, (14, True)), # outside tolerance, so the partial day is dropped
],
Expand Down
Loading