strptime() with year-weekday pair can produce invalid data.
>>> time.strptime('2015 0', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=1, tm_isdst=-1)
>>> time.strptime('2015 1', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1)
>>> time.strptime('2015 2', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=1, tm_isdst=-1)
>>> time.strptime('2015 3', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=1, tm_isdst=-1)
>>> time.strptime('2015 4', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=-1)
>>> time.strptime('2015 5', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=1, tm_isdst=-1)
>>> time.strptime('2015 6', '%Y %w')
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=1, tm_isdst=-1)
You get Jan 1 with any weekday.
|
Actually you can got invalid data for any date.
>>> time.strptime('2015 3 20', '%Y %m %d')
time.struct_time(tm_year=2015, tm_mon=3, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=79, tm_isdst=-1)
>>> time.strptime('2015 3 20 0', '%Y %m %d %w')
time.struct_time(tm_year=2015, tm_mon=3, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=79, tm_isdst=-1)
All date values are known, the problem is that they contradict.
|
>>>> time.strptime('2015 3 20 0', '%Y %m %d %w')
> time.struct_time(tm_year=2015, tm_mon=3, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=79, tm_isdst=-1)
>
> All date values are known, the problem is that they contradict.
Garbage in, garbage out. :-) Clearly today is not Sunday. I not sure
there is a correct answer in the face of contradictory inputs.
|