fix - ignore milliseconds on dates since the API can't decide on a format #601
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
- No issue, but it's a problem that's been around since the start...
Pull Request Information
About this Pull Request
This PR adjusts how we attempt to decode dates returned from the Lemmy instances.
We have seen many different formats returned by the API. Looking into the Lemmy source they are using
Timestamptz
which is described as;It would appear that we should be able to expect dates in the format
yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ
, however this is not the case, and a sample taken from a live instance earlier gave values with and without milliseconds:The existing set of formats we have suggest that we've also been seeing dates with 4 digit millisecond precision and with/without the separating
T
between the date and time, however I've not seen those on any instance I've tested on.I have seen issues frequently when switching between accounts quickly, where responses will fail to parse (failing on dates) but refreshing will often resolve it. Even though the data itself has not changed 🤯 this suggests the current approach of using a single formatter and adjusting its
.dateFormat
on the fly during decoding may also be introducing problems.This new approach has two separate formatters, one using
yyyy-MM-dd'T'HH:mm:ss
, and a second usingyyyy-MM-dd HH:mm:ss
. The logic has been updated to attempt to match the returned date string from the API using regex to extract the date minus the millisecond portion for the first format, and parse it... if that fails, it attempts to match the second format and parse that.In testing (across three instances) it is always the first format we encounter and so the second formatter here may be redundant.
@ShadowJonathan, I would appreciate your input on this PR if you're free. I have a vague memory from many months ago when we discussed date formats from Lemmy and we did think there may be two formats, was it with and without the
T
separator that you reckoned may appear? If so leaving the second redundant formatter would make sense to ensure we're covered in that scenario.Given the variations we're seeing appear to always be in the millisecond portion of the string I believe this will resolve the failures we're seeing. I can no longer re-create the failures I was seeing when switching quickly between multiple accounts.
Screenshots and Videos
No changes to the UI.