Cleanup in Date component + formatDate expression #2959
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.
Description
When implementing #1299 and #2122, I found a few problems with both the
Date
component and ourformatDate
expression function. Both fixed here:Date
component did not properly use the current language to format the date (that matters for format tokens that print out the day of the week, for example). It was also lacking some error handling for when the format was unsupported (this was printed out to the user, not the developer).formatDate
expression parsed dates by passing them to thenew Date(str)
constructor and hoping for the best. That works allright on frontend, but it makes it nearly impossible to implement the exact same date parsing on the backend. Instead I set up a list of regexes for input-formats we support, added lots of shared tests (including tests copied over from the JSON Schema project), along with tests for all the output-formats possible (according to our docs).Date
data type in the expression engine for this, so that the upcoming expressions for comparing dates can use the same functionality that is now used to parse dates for use informatDate
.Related Issue(s)
Verification/QA
kind/*
label to this PR for proper release notes grouping