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

timefhuman.categorize starts crashing by the end of the month #18

Open
StanczakDominik opened this issue Mar 26, 2020 · 2 comments
Open

Comments

@StanczakDominik
Copy link
Contributor

It looks like

(("weekdays",), DayRange(monday, monday + 4))):

is crashing if monday is 4 days away from the 31st day of the month.

Ipython debug log

[ins] In [3]: import timefhuman                                                                                                                                                              

[ins] In [4]: timefhuman.timefhuman('october 27th')                                                                                                                                          
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-ed924c5d5f0d> in <module>
----> 1 timefhuman.timefhuman('october 27th')

~/.local/lib/python3.8/site-packages/timefhuman/main.py in timefhuman(string, now, raw)
     56         now = datetime.datetime.now()
     57 
---> 58     tokens = timefhuman_tokens(string, now)
     59 
     60     if raw:

~/.local/lib/python3.8/site-packages/timefhuman/main.py in timefhuman_tokens(string, now)
     73     """Convert string into timefhuman parsed, imputed, combined tokens"""
     74     tokens = tokenize(string)
---> 75     tokens = categorize(tokens, now)
     76     tokens = build_tree(tokens, now)
     77     return tokens

~/.local/lib/python3.8/site-packages/timefhuman/categorize.py in categorize(tokens, now)
     30     tokens = convert_words_to_numbers(tokens)
     31     tokens = convert_day_of_week(tokens, now)
---> 32     tokens = convert_relative_days_ranges(tokens, now)
     33     tokens = convert_time_of_day(tokens)
     34     tokens = maybe_substitute_hour_minute(tokens)

~/.local/lib/python3.8/site-packages/timefhuman/categorize.py in convert_relative_days_ranges(tokens, now)
    117             (("yesterday",), DayToken.from_datetime(now - datetime.timedelta(1))),
    118             (("weekend",), DayRange(saturday, saturday + 1)),
--> 119             (("weekdays",), DayRange(monday, monday + 4))):
    120         for keyword in keywords:
    121             tokens = [replacement if token == keyword else token \

~/.local/lib/python3.8/site-packages/timefhuman/data.py in __add__(self, other)
    179         """
    180         assert isinstance(other, int)
--> 181         return DayToken(self.month, self.day + other, self.year)
    182 
    183     def __radd__(self, other):

~/.local/lib/python3.8/site-packages/timefhuman/data.py in __init__(self, month, day, year)
    135 
    136         assert month is None or 1 <= month <= 12
--> 137         assert day is None or 1 <= day <= 31
    138 
    139     def combine(self, time):

AssertionError: 

[ins] In [5]: %debug                                                                                                                                                                         
> /home/dominik/.local/lib/python3.8/site-packages/timefhuman/data.py(137)__init__()
    135 
    136         assert month is None or 1 <= month <= 12
--> 137         assert day is None or 1 <= day <= 31
    138 
    139     def combine(self, time):

ipdb> day                                                                                                                                                                                    
34
ipdb> up                                                                                                                                                                                     
> /home/dominik/.local/lib/python3.8/site-packages/timefhuman/data.py(181)__add__()
    179         """
    180         assert isinstance(other, int)
--> 181         return DayToken(self.month, self.day + other, self.year)
    182 
    183     def __radd__(self, other):

ipdb> self.day                                                                                                                                                                               
30
ipdb> other                                                                                                                                                                                  
4
ipdb> l                                                                                                                                                                                      
    176         >>> d1 = DayToken(3, 2, None)
    177         >>> d1 + 3
    178         3/5
    179         """
    180         assert isinstance(other, int)
--> 181         return DayToken(self.month, self.day + other, self.year)
    182 
    183     def __radd__(self, other):
    184         """
    185         >>> d1 = DayToken(3, 2, None)
    186         >>> 3 + d1

ipdb> up                                                                                                                                                                                     
> /home/dominik/.local/lib/python3.8/site-packages/timefhuman/categorize.py(119)convert_relative_days_ranges()
    117             (("yesterday",), DayToken.from_datetime(now - datetime.timedelta(1))),
    118             (("weekend",), DayRange(saturday, saturday + 1)),
--> 119             (("weekdays",), DayRange(monday, monday + 4))):
    120         for keyword in keywords:
    121             tokens = [replacement if token == keyword else token \

ipdb> monday                                                                                                                                                                                 
3/30/2020
ipdb> monday + 4                                                                                                                                                                             
*** AssertionError
ipdb> monday + 1                                                                                                                                                                             
3/31/2020
ipdb> monday + 2                                                                                                                                                                             
*** AssertionError

Originally posted by @StanczakDominik in #17 (comment)

@StanczakDominik
Copy link
Contributor Author

I'd also suggest a cron job test on Travis to find these issues :D

@alvinwan
Copy link
Owner

Oh wow oops thanks @StanczakDominik One test should probably just run timefhuman on every day of some particular month.

A monthly cron job may not be a bad idea...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants