Skip to content

Commit

Permalink
close #1358 a little more work to get weeks working again
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Dec 23, 2024
1 parent 272f096 commit b2e0000
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sarracenia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ def durationToSeconds(str_value, default=None) -> float:
first_unit='M'
else:
first_unit='w'
elif second_unit in 'w':
factor *= 60 * 60 * 24 * 7
if 'y' in str_value:
first_unit='y'
elif 'M' in str_value:
first_unit='M'
elif second_unit in 'M':
factor *= 60 * 60 * 24 * days_in_a_month
if 'y' in str_value:
Expand Down
3 changes: 3 additions & 0 deletions tests/sarracenia/__init___test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_durationToSeconds():
assert sarracenia.durationToSeconds('1s', default=None) == 1.0
assert sarracenia.durationToSeconds('-1s') == -1.0
assert sarracenia.durationToSeconds('-1.5h') == -5400.0
assert sarracenia.durationToSeconds('1w') == 24*3600*7
assert sarracenia.durationToSeconds('2h2m') == 7320
assert sarracenia.durationToSeconds('3m2s') == 182
assert sarracenia.durationToSeconds( '6w1d' ) == 24*3600*(6*7.0+1)
Expand All @@ -54,6 +55,8 @@ def test_durationToSeconds():
assert sarracenia.durationToSeconds( '1y' ) == 31557600.0
assert sarracenia.durationToSeconds( '1y28d' ) == 33976800.0
assert sarracenia.durationToSeconds( '1y1M' ) == 34210080.0
assert sarracenia.durationToSeconds( '1000w' ) == 604800000.0



def test_durationToString():
Expand Down

0 comments on commit b2e0000

Please sign in to comment.