-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
frontend/views/utils/humanDate.js
Outdated
const date = new Date(datems) | ||
const locale = navigator.languages ? navigator.languages[0] : navigator.language | ||
return date.toLocaleDateString(locale, opts) |
There was a problem hiding this comment.
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)
// 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' }) }} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic! 👍
Closes #874
Now dates are displayed based browser language (
navigator
) usingDate .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).