fix(v2): always use UTC when dealing with blog dates #4983
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.
Motivation
Fix #4881. This issue contains two bugs, the first (wrong displayed date) is related to
formattedDate
, the second (wrong generated URL) is related totoUrl
. By always dealing with the blog date object in the UTC timezone, both bugs should be fixed. (@josh-kaplan inspired me on how to fix the first one.)Although in the documentation, it is suggested to use
YYYY-MM-DD
for the blog date, numbers without a preceding zero will not be rejected and will be correctly parsed. However, this causes the date to be treated as a local time object instead of a UTC one when creating the date object, as documented. By forcing the date object to be created in UTC, this problem is solved.In
formattedDate
, the default timezone is the one of the runtime instead of UTC (documentation). We need to force it to UTC.Have you read the Contributing Guidelines on pull requests?
Yep
Test Plan
I can't demonstrate this error as a test case because this timezone is set in the local runtime environment. However, I constructed some examples:
Previous
Now
Let me know how to create a test case if there's such a need...