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

Remove moment usage from main codebase #880

Merged
merged 2 commits into from
Apr 3, 2020

Conversation

sandrina-p
Copy link
Contributor

@sandrina-p sandrina-p commented Apr 3, 2020

Closes #874

Now dates are displayed based browser language (navigator) using Date .toLocaleDateString().

A nice thing I like about this is that it handles date translations for us automatically! For example, in "en-US" it says "April 3" but in PT-PT it says "3 de Abril" (as expected).

@sandrina-p sandrina-p requested review from taoeffect and pieer April 3, 2020 00:25
Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Great work! 👍 See comments!

@@ -157,6 +155,10 @@ export default {
this.payments.map(payment => {
payment.checked = this.tableChecked
})
},
dueDate (datems) {
const date = datems || new Date() // remote new Date() when dealing with real data.
Copy link
Member

Choose a reason for hiding this comment

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

Can you enforce consistency here and everywhere else in the type usage?

I.e. either humanDate accepts milliseconds or a Date object, but not both.

So in this case, new Date() would be replaced with Date.now(), or even better, simply add a default value to the humanDate function (e.g. humanDate(datems = Date.now(), I think that might be possible, double-check me on that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default value is a clean solution. Changed, as well as the other comments!

Comment on lines 2 to 4
const date = new Date(datems)
const locale = navigator.languages ? navigator.languages[0] : navigator.language
return date.toLocaleDateString(locale, opts)
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to fetch the locale each time this function is called, that can be done once at the top of this file.

Then this function can be a one-liner:

return new Date(datems).toLocaleDateString(locale, opts)

Comment on lines 13 to 18
// TODO remove new Date() when dealing with real data.
strong {{ humanDate(this.payment.date || new Date(), { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' }) }}
li.c-payment-list-item
i18n.has-text-1(tag='label') Relative to
strong {{ moment(payment.relativeTo).format('MMMM')}}
// TODO remove new Date() when dealing with real data.
strong {{ humanDate(payment.relativeTo || new Date(), { month: 'long' }) }}
Copy link
Member

Choose a reason for hiding this comment

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

See comment below re Date.now() usage

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Fantastic! 👍

@taoeffect taoeffect merged commit d53c968 into master Apr 3, 2020
@taoeffect taoeffect deleted the task/874-remove-moment-dependency branch April 3, 2020 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove moment usage everywhere
2 participants