FIX: Special handling for ambiguous date formats#349
FIX: Special handling for ambiguous date formats#349TroyDowling wants to merge 1 commit intolucc:mainfrom
Conversation
+ Python now throws a DeprecationWarning when trying to parse a date which has no year. + This small patch adds the special handling required to avoid this.
|
Wouldn't this break for Feb 29th, though? Since 1900 was not a leap year. |
|
Thanks for the feedback, @aeneby. I take your point. 1900-02-29 is not a valid date. I suppose this problem is inherent to dealing with these ambiguous cases. I see a few workarounds:
This means two placeholder values, which seems messy and harder to maintain.
This requires a small change anywhere Khard compares to 1900, and presents an opportunity to pull the placeholder year out to a common variable somewhere.
It appears (at a glance anyway) that the places What do you think? Is there an option I haven't considered? |
|
To be honest, I didn't realise khard already uses 1900 as a placeholder year, and actually so does Python.
I kind of like @lucc's suggestion (#335 (comment))
around extending the datetime class to accommodate yearless dates. This would be more robust than making assumptions about a specific year being a placeholder value.
|
|
Reply to @TroyDowling's last comment:
More general: As noted in #335 (comment) I would prefer a solution with a new type for partial dates. I think this approach can still be accepted. I just added a failing test to main to show that the Feb 29 problem is already present. This PR does not improve or worsen the code in that regard. I understand that this PR only wants to fix the deprecation warning. I suggest we postpone the Feb 29 problem for later. The proper solution can (and in my current opinion will) still be a new partial date type then. Conclusion:
|
This small patch revises the
string_to_datefunction intyping.pyto more gracefully handle parsing dates without a year. The motivation being to address the DeprecationWarning issued by Python in recent versions (and to avoid a possible breakage in the upcoming Python 3.15).This closes #335 on the bug board.
ruff.Before
After
and