Skip to content

Commit

Permalink
chore: optimizing the dayjs utility
Browse files Browse the repository at this point in the history
  • Loading branch information
lgou2w committed May 31, 2023
1 parent 80dc916 commit 90899fc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/gacha/chart/GachaChartCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Stack from '@mui/material/Stack'
import Box from '@mui/material/Box'
import Paper from '@mui/material/Paper'
import Typography from '@mui/material/Typography'
import dayjs from 'dayjs'
import dayjs from '@/utilities/dayjs'

export default function GachaChartCalendar () {
const { facet, gachaRecords: { aggregatedValues } } = useGachaLayoutContext()
Expand Down
2 changes: 1 addition & 1 deletion src/components/gacha/overview/GachaOverviewGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Stack from '@mui/material/Stack'
import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'
import Chip from '@mui/material/Chip'
import dayjs from 'dayjs'
import dayjs from '@/utilities/dayjs'

export default function GachaOverviewGrid () {
const { facet, gachaRecords } = useGachaLayoutContext()
Expand Down
4 changes: 2 additions & 2 deletions src/components/gacha/overview/GachaOverviewLastUpdated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { resolveCurrency } from '@/interfaces/account'
import { useGachaLayoutContext } from '@/components/gacha/GachaLayoutContext'
import Typography from '@mui/material/Typography'
import dayjs from 'dayjs'
import dayjs from '@/utilities/dayjs'

export default function GachaOverviewLastUpdated () {
const { facet, selectedAccount } = useGachaLayoutContext()
Expand All @@ -14,7 +14,7 @@ export default function GachaOverviewLastUpdated () {
<Typography component="span" variant="inherit">{`最近${action}记录更新日期:`}</Typography>
<Typography component="span" variant="inherit">
{lastGachaUpdated
? dayjs(lastGachaUpdated).format('YYYY.MM.DD HH:mm:ss')
? dayjs(lastGachaUpdated).format('LLLL')
: '无'}
</Typography>
</Typography>
Expand Down
6 changes: 3 additions & 3 deletions src/components/gacha/overview/GachaOverviewTooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolveCurrency } from '@/interfaces/account'
import { useGachaLayoutContext } from '@/components/gacha/GachaLayoutContext'
import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'
import dayjs from 'dayjs'
import dayjs from '@/utilities/dayjs'

export default function GachaOverviewTooltips () {
const { facet, gachaRecords } = useGachaLayoutContext()
Expand Down Expand Up @@ -34,11 +34,11 @@ export default function GachaOverviewTooltips () {
<Typography>
{${action}记录日期覆盖范围:`}
<Typography component="span" color="secondary">
{dayjs(firstTime).format('YYYY.MM.DD HH:mm:ss')}
{dayjs(firstTime).format('LLLL')}
</Typography>
{' ~ '}
<Typography component="span" color="secondary">
{dayjs(lastTime).format('YYYY.MM.DD HH:mm:ss')}
{dayjs(lastTime).format('LLLL')}
</Typography>
{'。'}
</Typography>
Expand Down
14 changes: 14 additions & 0 deletions src/utilities/dayjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import localizedFormat from 'dayjs/plugin/localizedFormat'
import relativeTime from 'dayjs/plugin/relativeTime'
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'

dayjs.locale('zh-cn')
dayjs.extend(localizedFormat)
dayjs.extend(relativeTime)
dayjs.extend(isSameOrAfter)
dayjs.extend(isSameOrBefore)

export default dayjs

0 comments on commit 90899fc

Please sign in to comment.