Skip to content

Commit ad8cf9b

Browse files
authored
Merge pull request #610 from kaizumaki/feature/modify-dayjs
日付をローカライズ・date-fnsをdayjsに置き換え
2 parents 90ed9e9 + 0d883f0 commit ad8cf9b

26 files changed

+150
-109
lines changed

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint-staged

nuxt-i18n.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ const options = {
1515
code: 'ja',
1616
displayName: '日本語',
1717
file: 'ja.json',
18+
format: 'ja',
1819
},
1920
{
2021
code: 'en',
2122
displayName: 'English',
2223
file: 'en.json',
24+
format: 'en',
2325
},
2426
{
2527
code: 'zh-goyu',
2628
displayName: '台灣華語',
2729
file: 'zh_TW.json',
30+
format: 'zh-tw',
2831
},
2932
],
3033
}

nuxt.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ export default {
124124
'nuxt-svg-loader',
125125
['nuxt-i18n', i18nConfig],
126126
['@nuxtjs/google-analytics', { id: process.env.GAID }],
127+
'@nuxtjs/dayjs',
127128
],
129+
dayjs: {
130+
locales: ['ja', 'en', 'zh-tw'],
131+
defaultLocale: 'ja',
132+
defaultTimeZone: 'Asia/Tokyo',
133+
plugins: ['utc', 'timezone', 'minMax', 'isToday', 'localizedFormat'],
134+
},
128135
/*
129136
** Axios module configuration
130137
** See https://axios.nuxtjs.org/options

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"test:unit": "jest --config jest.config.js",
1111
"start": "nuxt start",
1212
"generate": "nuxt generate",
13-
"lint": "eslint --ext .js,.vue,.ts --ignore-path .eslintignore ."
13+
"lint": "eslint --ext .js,.vue,.ts --ignore-path .eslintignore .",
14+
"prepare": "husky install"
1415
},
1516
"lint-staged": {
1617
"*.{js,ts,css,vue}": [
@@ -28,6 +29,7 @@
2829
"@babel/core": "^7.14.3",
2930
"@babel/runtime-corejs3": "^7.14.0",
3031
"@nuxtjs/axios": "^5.13.4",
32+
"@nuxtjs/dayjs": "^1.4.0",
3133
"@nuxtjs/dotenv": "^1.4.1",
3234
"@nuxtjs/google-analytics": "^2.4.0",
3335
"@nuxtjs/pwa": "^3.3.5",
@@ -36,8 +38,6 @@
3638
"aws-amplify": "^4.0.2",
3739
"core-js": "^3.12.1",
3840
"cross-env": "^7.0.3",
39-
"date-fns": "^2.21.3",
40-
"dayjs": "^1.10.4",
4141
"express": "^4.17.1",
4242
"nuxt": "^2.15.6",
4343
"nuxt-i18n": "^6.27.0",

src/components/AppLanguageSelector.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,29 @@
1515
<script lang="ts">
1616
import Vue from 'vue'
1717
18-
type LocaleListItem = { text: string; value: string }
18+
type LocaleListItem = { text: string; value: string; format: string }
1919
type LocalData = {
2020
locales: LocaleListItem[]
2121
}
2222
2323
export default Vue.extend({
2424
data(): LocalData {
2525
if (!this.$root.$i18n.locales)
26-
return { locales: [{ text: 'N/A', value: '' }] }
26+
return { locales: [{ text: 'N/A', value: '', format: '' }] }
2727
2828
return {
2929
// @ts-ignore
3030
locales: this.$root.$i18n.locales.map((l) => {
31-
if (typeof l === 'string') return { text: l, value: l }
32-
else return { text: l.displayName, value: l.code }
31+
if (typeof l === 'string') return { text: l, value: l, format: l }
32+
else return { text: l.displayName, value: l.code, format: l.format }
3333
}),
3434
}
3535
},
36+
watch: {
37+
'$root.$i18n.locale'(locale) {
38+
this.$dayjs.locale(this.locales?.find((v) => v.value === locale)?.format)
39+
},
40+
},
3641
})
3742
</script>
3843

src/components/BaseInputField.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
@input="$emit('input', $event)"
1616
>
1717
<template #prepend-inner>
18-
<v-icon :color="prependIconColor">{{ prependIcon }}</v-icon>
18+
<v-icon :color="prependIconColor">
19+
{{ prependIcon }}
20+
</v-icon>
1921
</template>
2022
<template #append>
2123
<v-icon
@@ -41,7 +43,9 @@
4143
@input="$emit('input', $event)"
4244
>
4345
<template #prepend-inner>
44-
<v-icon :color="prependIconColor">{{ prependIcon }}</v-icon>
46+
<v-icon :color="prependIconColor">
47+
{{ prependIcon }}
48+
</v-icon>
4549
</template>
4650
</v-text-field>
4751
<v-text-field
@@ -60,7 +64,9 @@
6064
@input="$emit('input', $event)"
6165
>
6266
<template #prepend-inner>
63-
<v-icon :color="prependIconColor">{{ prependIcon }}</v-icon>
67+
<v-icon :color="prependIconColor">
68+
{{ prependIcon }}
69+
</v-icon>
6470
</template>
6571
</v-text-field>
6672
<v-text-field
@@ -79,7 +85,9 @@
7985
@input="$emit('input', $event)"
8086
>
8187
<template #prepend-inner>
82-
<v-icon :color="prependIconColor">{{ prependIcon }}</v-icon>
88+
<v-icon :color="prependIconColor">
89+
{{ prependIcon }}
90+
</v-icon>
8391
</template>
8492
</v-text-field>
8593
</template>

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>

src/components/EditLessonScreen.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
<script lang="ts">
5454
import Vue from 'vue'
55-
import dayjs from 'dayjs'
5655
import { vxm } from '@/store'
5756
import BaseActionButton from '@/components/BaseActionButton.vue'
5857
import EditLessonScreenInner1 from '@/components/EditLessonScreenInner1.vue'
@@ -255,10 +254,10 @@ export default Vue.extend({
255254
buildLessonData(): classData.Lesson {
256255
const startTimeStr: string =
257256
this.lessonData.date + ' ' + this.lessonData.startTime
258-
const startTimeDate: Date = dayjs(startTimeStr).toDate()
257+
const startTimeDate: Date = this.$dayjs(startTimeStr).toDate()
259258
const endTimeStr: string =
260259
this.lessonData.date + ' ' + this.lessonData.endTime
261-
const endTimeDate: Date = dayjs(endTimeStr).toDate()
260+
const endTimeDate: Date = this.$dayjs(endTimeStr).toDate()
262261
const videoData = []
263262
if (this.lessonData.videoUrl)
264263
videoData.push({

src/components/EditLessonScreenInner1.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
:return-value.sync="tempFormData.date"
77
width="290px"
88
>
9-
<v-date-picker v-model="tempFormData.date">
9+
<v-date-picker
10+
v-model="tempFormData.date"
11+
:locale="$root.$i18n.locale"
12+
:day-format="(date) => $dayjs(date).format('D')"
13+
>
1014
<v-spacer />
1115
<v-btn text color="primary" @click="datePickerOpen = false">
1216
{{ $t('common.general.buttons.cancel') }}

0 commit comments

Comments
 (0)