18
18
<v-col cols =" 1" class =" pa-0 ma-1" >
19
19
<v-card class =" calendar-bar-ym" flat >
20
20
<v-card-title class =" calendar-bar-ym-title" >
21
- {{ currentMonthString }}
21
+ {{ currentMonthString() }}
22
22
</v-card-title >
23
23
<v-card-subtitle class =" calendar-bar-ym-subtitle" >
24
- {{ currentYearString }}
24
+ {{ currentYearString() }}
25
25
</v-card-subtitle >
26
26
</v-card >
27
27
</v-col >
56
56
57
57
<script lang="ts">
58
58
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'
64
60
65
61
export type View = ' Day' | ' Weekday' | ' Week'
66
62
export type StartWeekOn =
@@ -106,7 +102,7 @@ class DateListWindowImpl implements DateListWindow {
106
102
this .startWeekOn = view === ' Weekday' ? ' Monday' : startWeekOn
107
103
this .currentDate = this .calcCurrentDate (
108
104
view ,
109
- isValid (date ) ? date : new Date ()
105
+ dayjs (date ). isValid ( ) ? date : new Date ()
110
106
)
111
107
this .list = this .generateDateList (
112
108
this .view ,
@@ -143,7 +139,7 @@ class DateListWindowImpl implements DateListWindow {
143
139
selectDate(date : Date ): DateListWindow {
144
140
this .currentDate = this .calcCurrentDate (
145
141
this .view ,
146
- isValid (date ) ? date : new Date ()
142
+ dayjs (date ). isValid ( ) ? date : new Date ()
147
143
)
148
144
this .list = this .generateDateList ()
149
145
@@ -155,13 +151,13 @@ class DateListWindowImpl implements DateListWindow {
155
151
private calcCurrentDate(view : View , date : Date ): Date {
156
152
let currentDate: Date = date
157
153
if (view === ' Weekday' && date .getDay () === 0 ) {
158
- currentDate = add (date , { days: 1 } )
154
+ currentDate = dayjs (date ). add ( 1 , ' d ' ). toDate ( )
159
155
}
160
156
return currentDate
161
157
}
162
158
163
159
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 ( ))
165
161
}
166
162
167
163
private firstDateOfList: (
@@ -187,7 +183,9 @@ class DateListWindowImpl implements DateListWindow {
187
183
default : {
188
184
const idx = dowList .indexOf (startWeekOn )
189
185
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 ()
191
189
break
192
190
}
193
191
}
@@ -207,7 +205,7 @@ class DateListWindowImpl implements DateListWindow {
207
205
const size: number = this .sizeOfList (view )
208
206
const list = Array <Date >(size )
209
207
for (let i = 0 ; i < list .length ; i ++ ) {
210
- list [i ] = add (firstDate , { days: i } )
208
+ list [i ] = dayjs (firstDate ). add ( i , ' d ' ). toDate ( )
211
209
}
212
210
return list
213
211
}
@@ -256,32 +254,28 @@ export default class CalendarBar extends Vue {
256
254
this .dateListWindow .selectDate (newValue )
257
255
}
258
256
259
- get currentMonthString(): string {
260
- return format (this .dateListWindow .currentDate , ' M ' ) + ' 月 '
257
+ currentMonthString(): string {
258
+ return this . $dayjs (this .dateListWindow .currentDate ). format ( ' MMM ' )
261
259
}
262
260
263
- get currentYearString(): string {
264
- return format (this .dateListWindow .currentDate , ' yyyy ' )
261
+ currentYearString(): string {
262
+ return this . $dayjs (this .dateListWindow .currentDate ). format ( ' YYYY ' )
265
263
}
266
264
267
265
fmtd(date : Date ): String {
268
- return format (date , ' d ' )
266
+ return this . $dayjs (date ). format ( ' D ' )
269
267
}
270
268
271
269
fmteeeee(date : Date ): String {
272
- return format (date , ' EEEEE ' , { locale: ja } )
270
+ return this . $dayjs (date ). format ( ' ddd ' )
273
271
}
274
272
275
273
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 ' )
277
275
}
278
276
279
277
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' )
285
279
}
286
280
}
287
281
</script >
0 commit comments