Skip to content

Commit 356d1c3

Browse files
committed
date-fnsをdayjsに置き換え(CompositionAPIの中で$dayjsが効かないので、ここだけdayjsをimport)
1 parent 53a8f69 commit 356d1c3

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/components/CalendarBar.vue

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
<v-col cols="1" class="pa-0 ma-1">
1919
<v-card class="calendar-bar-ym" flat>
2020
<v-card-title class="calendar-bar-ym-title">
21-
{{ currentMonthString }}
21+
{{ currentMonthString() }}
2222
</v-card-title>
2323
<v-card-subtitle class="calendar-bar-ym-subtitle">
24-
{{ currentYearString }}
24+
{{ currentYearString() }}
2525
</v-card-subtitle>
2626
</v-card>
2727
</v-col>
@@ -56,11 +56,7 @@
5656

5757
<script lang="ts">
5858
import { Vue, Component, Prop, Emit, Watch } from 'vue-property-decorator'
59-
import add from 'date-fns/add'
60-
import format from 'date-fns/format'
61-
import formatISO from 'date-fns/formatISO'
62-
import isValid from 'date-fns/isValid'
63-
import ja from 'date-fns/locale/ja'
59+
import dayjs from 'dayjs'
6460
6561
export type View = 'Day' | 'Weekday' | 'Week'
6662
export type StartWeekOn =
@@ -106,7 +102,7 @@ class DateListWindowImpl implements DateListWindow {
106102
this.startWeekOn = view === 'Weekday' ? 'Monday' : startWeekOn
107103
this.currentDate = this.calcCurrentDate(
108104
view,
109-
isValid(date) ? date : new Date()
105+
dayjs(date).isValid() ? date : new Date()
110106
)
111107
this.list = this.generateDateList(
112108
this.view,
@@ -143,7 +139,7 @@ class DateListWindowImpl implements DateListWindow {
143139
selectDate(date: Date): DateListWindow {
144140
this.currentDate = this.calcCurrentDate(
145141
this.view,
146-
isValid(date) ? date : new Date()
142+
dayjs(date).isValid() ? date : new Date()
147143
)
148144
this.list = this.generateDateList()
149145
@@ -155,13 +151,13 @@ class DateListWindowImpl implements DateListWindow {
155151
private calcCurrentDate(view: View, date: Date): Date {
156152
let currentDate: Date = date
157153
if (view === 'Weekday' && date.getDay() === 0) {
158-
currentDate = add(date, { days: 1 })
154+
currentDate = dayjs(date).add(1, 'd').toDate()
159155
}
160156
return currentDate
161157
}
162158
163159
private addDays(value: number): DateListWindow {
164-
return this.selectDate(add(this.currentDate, { days: value }))
160+
return this.selectDate(dayjs(this.currentDate).add(value, 'd').toDate())
165161
}
166162
167163
private firstDateOfList: (
@@ -187,7 +183,9 @@ class DateListWindowImpl implements DateListWindow {
187183
default: {
188184
const idx = dowList.indexOf(startWeekOn)
189185
const startDay: number = idx >= 0 ? idx : 1
190-
firstDate = add(date, { days: (startDay - (7 + date.getDay())) % 7 })
186+
firstDate = dayjs(date)
187+
.add((startDay - (7 + date.getDay())) % 7, 'd')
188+
.toDate()
191189
break
192190
}
193191
}
@@ -207,7 +205,7 @@ class DateListWindowImpl implements DateListWindow {
207205
const size: number = this.sizeOfList(view)
208206
const list = Array<Date>(size)
209207
for (let i = 0; i < list.length; i++) {
210-
list[i] = add(firstDate, { days: i })
208+
list[i] = dayjs(firstDate).add(i, 'd').toDate()
211209
}
212210
return list
213211
}
@@ -256,32 +254,28 @@ export default class CalendarBar extends Vue {
256254
this.dateListWindow.selectDate(newValue)
257255
}
258256
259-
get currentMonthString(): string {
260-
return format(this.dateListWindow.currentDate, 'M') + ''
257+
currentMonthString(): string {
258+
return this.$dayjs(this.dateListWindow.currentDate).format('MMM')
261259
}
262260
263-
get currentYearString(): string {
264-
return format(this.dateListWindow.currentDate, 'yyyy')
261+
currentYearString(): string {
262+
return this.$dayjs(this.dateListWindow.currentDate).format('YYYY')
265263
}
266264
267265
fmtd(date: Date): String {
268-
return format(date, 'd')
266+
return this.$dayjs(date).format('D')
269267
}
270268
271269
fmteeeee(date: Date): String {
272-
return format(date, 'EEEEE', { locale: ja })
270+
return this.$dayjs(date).format('ddd')
273271
}
274272
275273
fmtft(date: Date): String {
276-
return format(date, 'yyyy-MM-dd HH:mm:ss EEE')
274+
return this.$dayjs(date).format('YYYY-MM-DD HH:mm:ss ddd')
277275
}
278276
279277
fmtym(date: Date): String {
280-
return format(date, 'yyyy年M月', { locale: ja })
281-
}
282-
283-
fmtISO(date: Date): String {
284-
return formatISO(date)
278+
return this.$dayjs(date).format('YYYY MMM')
285279
}
286280
}
287281
</script>

0 commit comments

Comments
 (0)