Recognizers-Text icon indicating copy to clipboard operation
Recognizers-Text copied to clipboard

[TimexExpression] First Week of the Year Timex resolves to incorrect End Date

Open nikhilkandur opened this issue 4 years ago • 4 comments

Describe the bug First Week of the Year e.g., 2020-W01, 2021-W02 resolves to incorrect end date

To Reproduce Steps to reproduce the behavior:

def test_datatypes_resolver_dateRange_first_week_of_the_year():
    today = datetime(2021, 1, 1)
    resolution = TimexResolver.resolve(["2021-W01"], today)
    print(f'Timex:{resolution.values[0].timex}') 
    print(f'Type:{resolution.values[0].type}') 
    print(f'Start:{resolution.values[0].start}') 
    print(f'End:{resolution.values[0].end}')
    print("=======")

    resolution = TimexResolver.resolve(["2020-W01"], today)
    print(f'Timex:{resolution.values[0].timex}') 
    print(f'Type:{resolution.values[0].type}') 
    print(f'Start:{resolution.values[0].start}') 
    print(f'End:{resolution.values[0].end}')

Result

Timex:2021-W01
Type:daterange
Start:2020-12-28
End:2020-12-04
=======
Timex:2020-W01
Type:daterange
Start:2019-12-30
End:2019-12-06

Expected behavior

Timex:2021-W01
Type:daterange
Start:2020-12-28
End:2021-01-04
=======
Timex:2020-W01
Type:daterange
Start:2019-12-30
End:2020-01-06

Platform:

  • Platform: Python
  • Environment: console app
  • Version of package: recognizers-text-suite==1.0.2a2, datatypes-timex-expression==1.0.2a2

nikhilkandur avatar Aug 02 '21 20:08 nikhilkandur

This line datatypes_timex_expression/timex_resolver.py#L167 should be of end datetime rather than start datetime i.e.,

Timex(year=end.year, month=end.month, day_of_month=end.day)

nikhilkandur avatar Aug 03 '21 20:08 nikhilkandur

I tried the query of the "The first week of 2021" and "The first week of 2020" and I am getting the following date ranges, which seem correct

Timex:2021-W01 Type:daterange Start:2021-01-04 End:2021-01-11

Timex:2020-W01 Type:daterange Start:2019-12-30 End:2020-01-06

nawanas avatar Aug 04 '21 16:08 nawanas

@nawanas - I have my python code snippet above and I have tried using datatypes-timex-expression==1.0.2a2 library and pointed out the error line as well. I'm able to consistently reproduce the error. It seems like from your results, the week timex resolution logic needs to be updated as well. Here is a snapshot of the same,

image image

nikhilkandur avatar Aug 04 '21 19:08 nikhilkandur

It errors out for the extreme end of the year/month calculation of a week. I tried for 'this week' and end date is incorrect as well.

image

nikhilkandur avatar Aug 04 '21 20:08 nikhilkandur