Invalid format string %04Y on Windows
See original GitHub issueInvalid format string when using %04Y
on Windows 10 Python 3.7.1
$ python
>>> from datetime import datetime
>>> datetime(90, 1, 1).strftime("%04Y")
ValueError: Invalid format string
>>> datetime.strptime("2018-10-31 22:29:29.553000", "%Y-%m-%d %H:%M:%S.%f").strftime("%04Y-%m-%dT%H:%M:%S.%fZ")
ValueError: Invalid format string
Some platforms support modifiers from POSIX 2008 (and others). On Linux the format “%04Y” assures a minimum of four characters and zero-padding. The internal code (as used on Windows and by default on macOS) uses zero-padding by default
https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/strptime#l_sections
Related issues
- https://github.com/singer-io/singer-python/issues/81
%04Y
introduced in https://github.com/singer-io/singer-python/pull/52- macOS support added in https://github.com/singer-io/singer-python/pull/69
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
String.Format Method (System) - Microsoft Learn
Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to...
Read more >Invalid Format Specification: '%' - TechNet - Microsoft
I am receiving an sql exception of "Invalid Format Specification: ... select @string = 'error in my table %1! into my database %2!';...
Read more >FormatException Class (System) - Microsoft Learn
The exception that is thrown when the format of an argument is invalid, or when a composite format string is not well formed....
Read more >String wrong format error - Power Platform Community
I'm creating a Realdatatime that conects Forms+Flow (Power Automate)+ PowerBI. As user answer forms the dashboards are updated in PowerBI, but i ...
Read more >Strings.Format(Object, String) Method (Microsoft.VisualBasic)
Returns a string formatted according to instructions contained in a format ... Dim testDateTime As Date = #1/27/2001 5:04:23 PM# Dim testStr As...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pushed 5.3.3 to PyPI. Thanks! 😃
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
%04D
on Windows and that they continue to be padded on Mac/Linux.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?