Skip to content

Commit 5374940

Browse files
Handle the case where the number is just 3600 better
1 parent 292fc36 commit 5374940

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

pylint/checkers/format.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,11 @@ def to_standard_scientific_notation(cls, number: float) -> str:
112112

113113
@classmethod
114114
def to_understandable_time(cls, number: float) -> str:
115-
if number == 0.0 or number % 3600 != 0:
115+
if number == 0.0 or number % 3600 != 0 or number // 3600 == 1:
116116
return "" # Not a suspected time
117117
parts: list[int] = [3600]
118118
number //= 3600
119-
for divisor in (
120-
24,
121-
7,
122-
365,
123-
):
119+
for divisor in (24, 7, 365):
124120
if number % divisor == 0:
125121
parts.append(divisor)
126122
number //= divisor

tests/checkers/unittest_format.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,20 @@ def test_to_another_standard_notation(
245245
assert (
246246
time == ""
247247
), f"Time notation mismatch expected {expected_underscore}, got {time}"
248+
249+
250+
@pytest.mark.parametrize(
251+
"value,expected",
252+
[
253+
(3600, ""),
254+
(86400, "3600 * 24"),
255+
(604800, "3600 * 24 * 7"),
256+
(2592000, "3600 * 24 * 30"),
257+
(31536000, "3600 * 24 * 365"),
258+
(1180800, "3600 * 24 * 14 - (8 * 3600)"),
259+
(315360000, "3600 * 24 * 365 * 10"),
260+
],
261+
)
262+
def test_to_understandable_time(value: int, expected: str) -> None:
263+
actual = FloatFormatterHelper.to_understandable_time(value)
264+
assert actual == expected, f"Expected {expected} for {value}, got {actual}"

0 commit comments

Comments
 (0)