Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
dayjsのtypeをimportして適用(ref: MeditationDuck/covid19@8d588b0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizumaki committed May 13, 2022
1 parent a68a3cc commit 6a20efb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions plugins/chartjs-adapter-dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import 'dayjs/locale/zh-tw'

import { NuxtAppOptions } from '@nuxt/types/app'
import Chart from 'chart.js'
import dayjs, { extend, locale } from 'dayjs'
import dayjs, {
ConfigType,
extend,
locale as dayjsLocale,
ManipulateType,
OpUnitType,
QUnitType,
} from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'

const DEFAULT_FORMATS = {
Expand Down Expand Up @@ -41,29 +48,29 @@ export function useDayjsAdapter(nuxtI18n: NuxtAppOptions['i18n']) {
return DEFAULT_FORMATS
},

parse(time, format) {
parse(time: ConfigType, format: string | undefined) {
const value = format ? dayjs(time, format) : dayjs(time)

return value.isValid() ? value.valueOf() : null
},

format(time, format) {
format(time: ConfigType, format: string) {
return dayjs(time).format(format)
},

add(time, amount, unit) {
return dayjs(time).add(amount, unit)
add(time: ConfigType, amount: number, unit: OpUnitType) {
return dayjs(time).add(amount, unit as ManipulateType)
},

diff(max, min, unit) {
diff(max: ConfigType, min: ConfigType, unit: QUnitType | OpUnitType) {
return dayjs(max).diff(dayjs(min), unit)
},

startOf(time, unit, _) {
startOf(time: ConfigType, unit: OpUnitType, _: null | undefined) {
return dayjs(time).startOf(unit)
},

endOf(time, unit) {
endOf(time: ConfigType, unit: OpUnitType) {
return dayjs(time).endOf(unit)
},
})
Expand All @@ -76,5 +83,5 @@ function setLocale(newLocale: string) {
loc = 'ja'
}

locale(loc)
dayjsLocale(loc)
}

0 comments on commit 6a20efb

Please sign in to comment.