tomasbedrich / pycaching

A Python 3 interface for working with Geocaching.com website.
https://pycaching.readthedocs.io/
GNU Lesser General Public License v3.0
61 stars 46 forks source link

Add more date patterns #201

Closed BelKed closed 1 year ago

BelKed commented 1 year ago

It seems that the date format no longer depends on the language settings. In Settings > Preferences, you can find a Date Format section, where you can set a variety of date formats:

Screenshot


This PR adds support for all of them. Related to stale #155.

FriedrichFroebel commented 1 year ago

Thanks for the updated PR. Is there any reason for dropping the г format completely, whereas only Windows is affected (maybe related to https://bugs.python.org/issue8304)? We already have exceptions for Windows date formats inside our code and should probably use a similar approach here: https://github.com/tomasbedrich/pycaching/blob/2a6067bb6340eb23a41fd6f8d7789645fc155e4f/pycaching/util.py#L99

Just for the record, the offending exceptions is the following one:

>           formatted_date = datetime.datetime.strftime(date, pattern)
E           UnicodeEncodeError: 'locale' codec can't encode character '\u0433' in position 9: encoding error
BelKed commented 1 year ago

Just the Windows build was failing… I’ll take a look at it in the evening and hopefully add a commit with fix for Windows :)

BelKed commented 1 year ago

As I promised, I fixed it...

Feel free to let me know about any issues with this solution :)

FriedrichFroebel commented 1 year ago

Thanks, seems legit to me. Nevertheless, I would probably prefer to avoid this overhead for Linux and macOS. Could you make the offending section conditional, please? Meaning:

if platform.system() == "Windows":
    # Use solution with encoding and decoding.
else:
   # Use old solution.
BelKed commented 1 year ago

Sure, https://github.com/tomasbedrich/pycaching/pull/201/commits/8e2acd2d2fcd8e0501ee3fa91e673db9e0de5ab1