This repository was archived by the owner on Apr 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/dev-map
- Loading branch information
Showing
10 changed files
with
188 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { _adapters } from 'chart.js' | ||
import dayjs from 'dayjs' | ||
import customParseFormat from 'dayjs/plugin/customParseFormat' | ||
import 'dayjs/locale/en' | ||
import 'dayjs/locale/ja' | ||
import 'dayjs/locale/ko' | ||
import 'dayjs/locale/pt-br' | ||
import 'dayjs/locale/th' | ||
import 'dayjs/locale/vi' | ||
import 'dayjs/locale/zh-cn' | ||
import 'dayjs/locale/zh-tw' | ||
import { NuxtAppOptions } from '@nuxt/types/app' | ||
|
||
const DEFAULT_FORMATS = { | ||
datetime: 'MMM D, YYYY, h:mm:ss a', | ||
millisecond: 'h:mm:ss.SSS a', | ||
second: 'h:mm:ss a', | ||
minute: 'h:mm a', | ||
hour: 'hA', | ||
day: 'MMM D', | ||
week: 'll', | ||
month: 'MMM YYYY', | ||
quarter: '[Q]Q - YYYY', | ||
year: 'YYYY' | ||
} | ||
|
||
export function useDayjsAdapter(nuxtI18n: NuxtAppOptions['i18n']) { | ||
dayjs.extend(customParseFormat) | ||
|
||
// set locale when page onload | ||
setLocale(nuxtI18n.locale) | ||
nuxtI18n.onLanguageSwitched = (_: string, newLocale: string) => { | ||
setLocale(newLocale) | ||
} | ||
|
||
_adapters._date.override({ | ||
_id: 'dayjs', // for debug | ||
|
||
formats() { | ||
return DEFAULT_FORMATS | ||
}, | ||
|
||
parse(time, format) { | ||
const value = format ? dayjs(time, format) : dayjs(time) | ||
|
||
return value.isValid() ? value.valueOf() : null | ||
}, | ||
|
||
format(time, format) { | ||
return dayjs(time).format(format) | ||
}, | ||
|
||
add(time, amount, unit) { | ||
return dayjs(time).add(amount, unit) | ||
}, | ||
|
||
diff(max, min, unit) { | ||
return dayjs(max).diff(dayjs(min), unit) | ||
}, | ||
|
||
startOf(time, unit, _) { | ||
return dayjs(time).startOf(unit) | ||
}, | ||
|
||
endOf(time, unit) { | ||
return dayjs(time).endOf(unit) | ||
} | ||
}) | ||
} | ||
|
||
function setLocale(newLocale: string) { | ||
let locale = newLocale | ||
|
||
if (locale.includes('ja')) { | ||
locale = 'ja' | ||
} | ||
|
||
dayjs.locale(locale) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ConfigType, Dayjs, OpUnitType, QUnitType } from 'dayjs' | ||
|
||
declare module 'chart.js' { | ||
export class _adapters { | ||
static _date: DayjsDateAdapter | ||
} | ||
|
||
interface DayjsDateAdapter { | ||
override: (options: Options) => void | ||
} | ||
|
||
interface Options { | ||
_id: string | ||
formats: () => DateAdapterFormats | ||
parse: (time: ConfigType, format: string | undefined) => number | null | ||
format: (time: ConfigType, format: string) => string | ||
add: (time: ConfigType, amount: number, unit: OpUnitType) => Dayjs | ||
diff: ( | ||
max: ConfigType, | ||
min: ConfigType, | ||
unit: QUnitType | OpUnitType | ||
) => number | ||
startOf: ( | ||
time: ConfigType, | ||
unit: OpUnitType, | ||
weekday: null | undefined | ||
) => Dayjs | ||
endOf: (time: ConfigType, unit: OpUnitType) => Dayjs | ||
} | ||
|
||
export type DateAdapterFormats = { | ||
datetime: string | ||
millisecond: string | ||
second: string | ||
minute: string | ||
hour: string | ||
day: string | ||
week: string | ||
month: string | ||
quarter: string | ||
year: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters