I have a graph where I need to react to user interactions that change the x axis range, which is of type date. I use the relayoutData property as input to my callback to, which normally looks like this:
{"xaxis.range[0]": "2021-07-02 23:59:59.0888", "xaxis.range[1]": "2021-07-03 00:00:08.7182"}
So, to use this range in subsequent functions, I parsed it using strptime()
from the datetime
module and format %Y-%m-%d %H:%M:%S.%f
.
However, testing this a bit I found that if I’m “lucky” enough to exactly land on a full second, the relayoutData
may instead look like this:
{"xaxis.range[0]": "2021-07-02 23:59:58", "xaxis.range[1]": "2021-07-02 23:59:58.0007"}
Note how there are no milliseconds for xaxis.range[0]
. If I land exactly on a new day it might even just be 2021-07-03
.
This inconsistent formatting breaks strptime, of course, because the format doesn’t match anymore. What would be the best way to deal with this? Can I get around doing laborious parsing for each case?