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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/views/containers/payments/MonthOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
i18n.c-summary-title.is-title-4(
tag='h4'
data-test='thisMonth'
:args='{ month: moment(new Date()).format("MMMM") }'
:args='{ month: humanDate(Date.now(), { month: "long" }) }'
) {month} overview

.c-summary-item(
Expand All @@ -27,7 +27,7 @@ import currencies from '@view-utils/currencies.js'
import { mapGetters } from 'vuex'
import ProgressBar from '@components/graphs/Progress.vue'
import L from '@view-utils/translations.js'
import moment from 'moment'
import { humanDate } from '@view-utils/humanDate.js'

export default {
name: 'MonthOverview',
Expand Down Expand Up @@ -74,7 +74,7 @@ export default {
}
},
methods: {
moment,
humanDate,
// TEMP
statusIsSent (user) {
return ['completed', 'pending'].includes(user.status)
Expand Down
8 changes: 4 additions & 4 deletions frontend/views/containers/payments/PaymentDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ modal-template(ref='modal' v-if='payment')
ul.c-payment-list
li.c-payment-list-item
i18n.has-text-1(tag='label') Date & Time
strong {{ moment(payment.date).format('hh:mm - MMMM DD, YYYY') }}
strong {{ humanDate(this.payment.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')}}
strong {{ humanDate(payment.relativeTo, { month: 'long' }) }}
li.c-payment-list-item
i18n.has-text-1(tag='label') Mincome at the time
strong {{ currency(groupSettings.mincomeAmount) }}
Expand All @@ -31,11 +31,11 @@ modal-template(ref='modal' v-if='payment')
<script>
import { mapGetters } from 'vuex'
import L from '@view-utils/translations.js'
import moment from 'moment'
import sbp from '~/shared/sbp.js'
import { CLOSE_MODAL } from '@utils/events.js'
import ModalTemplate from '@components/modal/ModalTemplate.vue'
import currencies from '@view-utils/currencies.js'
import { humanDate } from '@view-utils/humanDate.js'

export default {
name: 'PaymentDetail',
Expand Down Expand Up @@ -76,7 +76,7 @@ export default {
console.log('Todo: Implement cancel payment')
this.closeModal()
},
moment
humanDate
},
validations: {
form: {}
Expand Down
11 changes: 6 additions & 5 deletions frontend/views/containers/payments/PaymentsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ table.table.table-in-card.c-payments(:class='{"is-editing": paymentsType === "ed
// TODO: replace condition to indicate whether or not the payment date is < or > than the current date using payment.paymentStatusText
i18n.c-user-month(
:class='index === 0 ? "has-text-1" : "pill is-danger"'
:args='{date: moment(payment.date).format("MMMM DD")}'
:args='{date: dueDate(payment.date) }'
) Due {date}
td.c-payments-amount(v-if='paymentsType !== "edit"')

Expand Down Expand Up @@ -66,7 +66,7 @@ table.table.table-in-card.c-payments(:class='{"is-editing": paymentsType === "ed

td
.c-actions
.c-actions-month(:class='!(index !== 0 && paymentsType === "todo") ? "has-text-1" : "pill is-danger"') {{ moment(payment.date).format('MMMM D') }}
.c-actions-month(:class='!(index !== 0 && paymentsType === "todo") ? "has-text-1" : "pill is-danger"') {{ dueDate(payment.date) }}
payments-list-menu.c-actions-menu(
v-if='paymentsType !== "edit"'
:payment='payment'
Expand Down Expand Up @@ -94,8 +94,7 @@ import AvatarUser from '@components/AvatarUser.vue'
import Tooltip from '@components/Tooltip.vue'
import PaymentsListMenu from '@containers/payments/PaymentsListMenu.vue'
import currencies from '@view-utils/currencies.js'
import moment from 'moment'

import { humanDate } from '@view-utils/humanDate.js'
export default {
name: 'PaymentsList',
components: {
Expand All @@ -119,7 +118,6 @@ export default {
},
data () {
return {
moment,
// Temp
tableChecked: false
}
Expand Down Expand Up @@ -157,6 +155,9 @@ export default {
this.payments.map(payment => {
payment.checked = this.tableChecked
})
},
dueDate (datems) {
return humanDate(datems, { month: 'short', day: 'numeric' })
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/views/utils/humanDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const locale = navigator.languages ? navigator.languages[0] : navigator.language

export function humanDate (datems = Date.now(), opts = {}) {
return new Date(datems).toLocaleDateString(locale, opts)
}