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

replace moment with helpers based on date-fns #223

Merged
merged 6 commits into from
Jan 14, 2022
Merged

Conversation

nvdk
Copy link
Member

@nvdk nvdk commented Jan 13, 2022

visually verified the changes and all seems to be ok, there's some small changes (we were inconsistent and sometimes formatted as dd-MM-YYYY, now we are consistently using /).

@nvdk nvdk requested review from Windvis and abeforgit January 13, 2022 16:01
@nvdk nvdk added the internal label Jan 13, 2022
Copy link
Contributor

@Windvis Windvis left a comment

Choose a reason for hiding this comment

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

Looks good! I'm really curious about some build size number differences 😬

package.json Outdated
]
],
"dependencies": {
"date-fns": "^2.28.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I would move it to devDeps for consistency.


export default helper(function plainDate([datetime]/*, hash*/) {
try {
return lightFormat(datetime, 'dd/MM/yyyy');
Copy link
Contributor

@Windvis Windvis Jan 13, 2022

Choose a reason for hiding this comment

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

In OP we created a helper that uses Intl.Datetimeformat (with hardcoded country since we didn't have other requirements).
Maybe something similar can be done here? Or do you prefer providing the format manually?

Copy link
Member Author

Choose a reason for hiding this comment

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

on testing I ended up with a different separator (I think -) and / was preferred here. I can recheck with customer if that's still important

Copy link
Contributor

Choose a reason for hiding this comment

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

The helper I linked has the following output:
image

In any case, it works as intended at the moment so this remark isn't really a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely: formatting as 'dd/MM/yyyy' would give '21/01/2022' and Intl gives '21/1/2022', unless you use Intl.DateTimeFormat("nl-BE", { dateStyle: "short" }).format(datetime);. Weird, but consistent across browsers.


export default helper(function detailedDate([datetime]/*, hash*/) {
try {
return lightFormat(datetime, 'dd/MM/yyyy HH:mm');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be achieved with Intl.Datetimeformat as well by using some of the options:

console.log(new Intl.DateTimeFormat('nl-BE', { dateStyle: 'short', timeStyle: 'short' }).format(date));

app/components/app-chrome.hbs Show resolved Hide resolved
“[BenJay10]” added 4 commits January 14, 2022 10:04
There was more leftover config for the removed dependency "moment" in
environment.js.
Moved date-fns to devDependencies instead of regular dependencies.
With an instance check for Date, the helper no longer tries to format
things that are not dates, such as undefined or other objects.
In some instances, a date is left undefined, such as the end date on
meetings if the meeting isn't finished yet. We don't want unnecessary
errors being printend on the console because of this.
Completely missed this during testing. Used the wrong reference.
@nvdk nvdk merged commit 1dcdb8a into development Jan 14, 2022
@nvdk nvdk deleted the chore/replace-moment branch January 14, 2022 17:18

export default helper(function detailedDate([datetime]/*, hash*/) {
//If not a date (e.g. date is undefined) return "" for printing on screen.
if (!(datetime instanceof Date)) return "";
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's merged already, but this check seems redundant since the try catch handles it already? And the comment above seems redundant as well since it's literally the transcript of what you think when you read the actual line of code 😄.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the intention with the try...catch was to print an error in case the actual dates did not make sense, but we don't want an error when the date is just undefined, because that can happen in a normal situation. I wanted error messages only when really necessary to not cause confusion later.
Yes, the comment is pretty useless like this, sorry for that, but at least it means this check was put there for a reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants