disentcorp / dateroll

dateroll makes working with 📅 dates less painful.
Apache License 2.0
11 stars 1 forks source link

Issue with ddh on tenor strings longer than 4 characters #5

Open disentchris opened 2 months ago

disentchris commented 2 months ago

Describe the bug When ddh(x) is called on a tenor string with tenor more than 4 digits long (i.e. '1000d', '10000w', '3000m'), ddh returns error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/ddh/ddh.py", line 37, in __new__
    obj = parserModule.parse_to_dateroll(o)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/parser/parser.py", line 190, in parse_to_dateroll
    return Parser(string)
           ^^^^^^^^^^^^^^
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/parser/parser.py", line 111, in __new__
    part = Parser.parse_maybe_many_parts(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/parser/parser.py", line 148, in parse_maybe_many_parts
    date_or_period = cls.parse_one_part(part)
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/parser/parser.py", line 124, in parse_one_part
    dates, nodates = parsersModule.parseManyDateStrings(notoday, gen)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/parser/parsers.py", line 204, in parseManyDateStrings
    date = parseDateString(match)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/disent/pyenvtest312/lib/python3.12/site-packages/dateroll/parser/parsers.py", line 127, in parseDateString
    raise ParserStringsError(
dateroll.parser.parsers.ParserStringsError: If no slashes or dashes, must be 2 digit year an dmonth, and 2 or 4 digit year in YMD format ONLY

To Reproduce Steps to reproduce the behavior:

  1. call ddh(x) where x = f'{i}{t}', t is in {'d','w','m','bd','y'} and i >=1000 ex. ddh('1000d') ddh('10000m') ddh('4567w')

Expected behavior

>>>ddh('1000d')
Duration(years=0, months=0, days=1000, modified=False)
Batu4 commented 2 months ago

fixed it in patterns.py by changing regex

Batu4 commented 2 months ago

added testcases, found a bug while adding testcases, fixed and did pushed