-
Notifications
You must be signed in to change notification settings - Fork 128
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
Invalid format string %04Y on Windows #86
Comments
I agree that Python 3.7.1's |
@timvisher Isn't this a OS specific problem, not Python version? Here is Python 3.5.2 on Windows,
Can we use something like this? Probably the wrong way to patch this 🤷♂️ Windows by default zero-pads year values with DATETIME_FMT_SAFE = "%Y-%m-%dT%H:%M:%S.%fZ"
def strftime(dtime, format_str=DATETIME_FMT):
if dtime.utcoffset() != datetime.timedelta(0):
raise Exception("datetime must be pegged at UTC tzoneinfo")
dt_str = None
try:
dt_str = dtime.strftime(format_str)
if dt_str.startswith('4Y'):
dt_str = dtime.strftime(DATETIME_FMT_SAFE)
except ValueError:
dt_str = dtime.strftime(DATETIME_FMT_SAFE)
return dt_str |
Sorry, I just actually wasn't sure what problem you were seeing. So is the issue that you're identifying that |
@timvisher Correct, I can't parse anything because |
Ah. Got it. :) So we'd definitely accept patches to improve Windows support but I'll let you know up front that the testing burden might be a little high, since none of us have easy access to Windows machines at the moment nor any expertise on developing/debugging Python on Windows issues. I guess at a minimum we'll want to see some unit tests added if they don't already exist that test that 3 digit years are zero padded without In terms of the general design I don't think duck typing is necessarily the wrong way to go here. First try with the Mac/Linux format string, fall back to the windows format string on an exception, otherwise raise. Sound good? |
@timvisher I created #87 We already have tests for zero-padding a small year. The tests failed before and now pass on Windows. |
Pushed 5.3.3 to PyPI. Thanks! :) |
This is still an issue on my Windows machine. I fixed by updating DATETIME_FMT to be the same as DATETIME_FMT_MAC DATETIME_FMT = "%Y-%m-%dT%H:%M:%S.%fZ" |
Invalid format string when using
%04Y
on Windows 10 Python 3.7.1Related issues
utils.strptime
andutils.strftime
are asymmetrical #81%04Y
introduced in Fix formatting of dates when they are < 1000 #52The text was updated successfully, but these errors were encountered: