Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup in Date component + formatDate expression #2959

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

olemartinorg
Copy link
Contributor

Description

When implementing #1299 and #2122, I found a few problems with both the Date component and our formatDate expression function. Both fixed here:

  1. The 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).
  2. The formatDate expression parsed dates by passing them to the new 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).
  3. I added fairly generic support for a 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 in formatDate.

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Ole Martin Handeland added 3 commits January 31, 2025 09:53
…e date, and properly warns about invalid dates format tokens
… just a string or number, but it will parse to a Date object when used as an argument
@olemartinorg olemartinorg added the kind/bug Something isn't working label Jan 31, 2025
Copy link
Member

@bjosttveit bjosttveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veldig grundig, som man jo må være med slike ting 💪

@olemartinorg olemartinorg merged commit 9412d83 into main Jan 31, 2025
15 of 16 checks passed
@olemartinorg olemartinorg deleted the chore/date-cleanup branch January 31, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants