Replace 000Z suffix with dayjs.utc call #2087
Merged
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.
This is a partial fix for #2079. It addresses only the task status, not the "Invalid Date Invalid Date" further down the page. This microsecond precision thing can be as big of a project as we want it to be, and I've had a couple of doomsday-sized PRs lately, so I'm shooting for a smaller first step here. Happy to follow up with more, and then we can go as deep into this issue as you like.
As per my post on the issue, the correct status for this task is "active" as it has a published date in the past. The problem is that the date has microsecond precision, and so the addition of the
.000Z
suffix makes it unparsable to dayjs: Bothdayjs(published + '.000Z').isBefore(now)
anddayjs(published + '.000Z').isAfter(now)
returnfalse
ifpublished
contains microseconds.Thing is, dayjs does actually support parsing microseconds. So there's no problem with that. It supports UTC too. So my thinking here is we just need to approach this differently. Instead of chucking
.000Z
on the end to tell dayjs we want our date parsed as UTC, we can replace thedayjs(published)
call withdayjs.utc(published)
, which achieves the desired goal without depending on smuggling our intended timezone in via the string param.Want excruciating detail? You got it! The following sample code runs through dayjs date comparison outcomes with three slightly different input formats to explain why I think
dayjs.utc()
is the way to go here.