Skip to content
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

Use dateutil in order to support parsing timestamps that include milliseconds #187

Open
simonbaird opened this issue Dec 6, 2019 · 3 comments

Comments

@simonbaird
Copy link

See https://projects.engineering.redhat.com/browse/ERRATA-9192 .

I believe just adding a '%f' to the format string is enough to get it working. You could consider trying to make it work with either format to make the transition easier, maybe with a wrapper function.

Question: Is there any particular reason why datetime.datetime.strptime is used in some places and time.strptime in others? Could it be made consistent for all the timestamp parsing?

Actually we might still change Errata Tool back to use the old format in the short term, which would mean this isn't needed.

import time
import datetime

short_format = "2019-12-05T00:00:00"
long_format = "2019-12-05T00:00:00.000Z"

#d = short_format
d = long_format

print(time.strptime(str(d), '%Y-%m-%dT%H:%M:%S.%fZ'))
#=> time.struct_time(tm_year=2019, tm_mon=12, tm_mday=5, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=339, tm_isdst=-1)

print(datetime.datetime.strptime(str(d), '%Y-%m-%dT%H:%M:%S.%fZ'))
#=> 2019-12-05 00:00:00
simonbaird added a commit to simonbaird/errata-tool that referenced this issue Dec 6, 2019
This is a minimum viable patch to support the timestamp format
change (possibly) coming in Errata Tool 3.20.9.

I haven't tested it. Note that it is not backward compatible, so it
would require Errata Tool 3.20.9 or higher.

Note also that it's been suggested that we might change the
timestamp format back to the old format in ET 3.20.9. If that
happens then this patch must not be merged.

Github: red-hat-storage#187
JIRA: ERRATA-9192
@simonbaird
Copy link
Author

simonbaird commented Dec 6, 2019

Jon has a WIP patch for Errata Tool to restore the old timestamp format, so I won't spend more time on this.

@jorris
Copy link

jorris commented Dec 6, 2019

Or use dateutil and not have to worry about trivial format changes, especially when you aren't using the time component.
dateutil.parser.parse('2019-12-05T00:00:00.000Z').date().strftime('%Y-%b-%d')
'2019-Dec-05'

@ktdreyer
Copy link
Member

Great idea jorris. I'm going to re-title this to use dateutil.

@ktdreyer ktdreyer changed the title Support parsing timestamps that include milliseconds Use dateutil in order to support parsing timestamps that include milliseconds Dec 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants