From 5e78e4ad073d9864736ec2f2616a64c4dc5c9d89 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 20 Jan 2022 13:42:25 +0100 Subject: [PATCH] remove moment. localize date time --- .../components/EditCreationFormular.spec.js | 11 +----- admin/src/components/EditCreationFormular.vue | 37 +++++++++++++------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/admin/src/components/EditCreationFormular.spec.js b/admin/src/components/EditCreationFormular.spec.js index ed0f412ba..23b685f39 100644 --- a/admin/src/components/EditCreationFormular.spec.js +++ b/admin/src/components/EditCreationFormular.spec.js @@ -20,16 +20,7 @@ const toastedSuccessMock = jest.fn() const mocks = { $t: jest.fn((t) => t), - $moment: jest.fn(() => { - return { - format: jest.fn((m) => m), - subtract: jest.fn(() => { - return { - format: jest.fn((m) => m), - } - }), - } - }), + $d: jest.fn((d) => d), $apollo: { mutate: apolloMutateMock, }, diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index 172ae5509..34f4d6101 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -154,22 +154,11 @@ export default { value: !this.creationUserData.amount ? 0 : this.creationUserData.amount, rangeMin: 0, rangeMax: 1000, - currentMonth: { - short: this.$moment().format('MMMM'), - long: this.$moment().format('YYYY-MM-DD'), - }, - lastMonth: { - short: this.$moment().subtract(1, 'month').format('MMMM'), - long: this.$moment().subtract(1, 'month').format('YYYY-MM') + '-01', - }, - beforeLastMonth: { - short: this.$moment().subtract(2, 'month').format('MMMM'), - long: this.$moment().subtract(2, 'month').format('YYYY-MM') + '-01', - }, submitObj: null, isdisabled: true, createdIndex: null, selectedOpenCreationAmount: {}, + now: Date.now(), } }, @@ -227,6 +216,30 @@ export default { }) }, }, + computed: { + currentMonth() { + return { + short: this.$d(this.now, 'month'), + long: this.$d(this.now, 'short'), + } + }, + lastMonth() { + const now = new Date(this.now) + const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1) + return { + short: this.$d(lastMonth, 'month'), + long: this.$d(lastMonth, 'short'), + } + }, + beforeLastMonth() { + const now = new Date(this.now) + const beforeLastMonth = new Date(now.getFullYear(), now.getMonth() - 2, 1) + return { + short: this.$d(beforeLastMonth, 'month'), + long: this.$d(beforeLastMonth, 'short'), + } + }, + }, created() { if (this.creationUserData.date) { switch (this.$moment(this.creationUserData.date).format('MMMM')) {