Skip to content

Commit

Permalink
fix(date): 升级 date-fns
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jan 29, 2024
1 parent 5cf217f commit 7e7bb5f
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 349 deletions.
3 changes: 0 additions & 3 deletions haoma-compile.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ export default [
target: file => (/src\/(dev|x)\//.test(file) ? 'node' : 'browser'),
outDir: 'lib/_cjs',
emitDts: false,
alias: {
'date-fns/esm': 'date-fns',
},
plugins: [removeIsTypePlugin],
}),
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"benchmark": "^2.1.4",
"cli-table3": "^0.6.0",
"cuid": "^2.1.8",
"date-fns": "^2.24.0",
"date-fns": "^3.3.1",
"decimal.js-light": "^2.5.1",
"fast-xml-parser": "^3.18.0",
"gcoord": "^0.3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/date/anyToDate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseISO, toDate } from 'date-fns'
import { isNumeric } from '../utils'
import { parseISO, toDate } from 'date-fns/esm'

/**
* 增强版的 toDate,支持:
Expand Down
2 changes: 1 addition & 1 deletion src/date/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lightFormat } from 'date-fns/esm'
import { lightFormat } from 'date-fns'

/**
* 日期格式化占位符。
Expand Down
4 changes: 2 additions & 2 deletions src/date/formatDistanceAgo.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { formatDistanceAgo } from './formatDistanceAgo'
import {
subDays,
subHours,
subMinutes,
subMonths,
subSeconds,
subYears,
} from 'date-fns/esm'
} from 'date-fns'
import { formatDistanceAgo } from './formatDistanceAgo'

describe('formatDistanceAgo', () => {
test('表现正常', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/date/formatDistanceAgo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatDistanceToNowStrict } from 'date-fns/esm'
import { zhCN } from 'date-fns/esm/locale'
import { formatDistanceToNowStrict } from 'date-fns'
import { zhCN } from 'date-fns/locale'

/**
* 将时间转化为 `xxx前` 表示。
Expand Down
6 changes: 3 additions & 3 deletions src/date/formatDistancePlus.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { addDays, addYears, subDays, subYears } from 'date-fns/esm'
import { addDays, addYears, subDays, subYears } from 'date-fns'
import { formatDistancePlus } from './formatDistancePlus'

describe('formatDistancePlus', () => {
test('前', () => {
expect(formatDistancePlus(subDays(new Date(), 1))).toBe('1天前')
expect(formatDistancePlus(subDays(new Date(), 1.5))).toBe('1天前')
expect(formatDistancePlus(subDays(new Date(), 1.5))).toBe('2天前')
expect(formatDistancePlus(subYears(new Date(), 10))).toBe('10年前')

expect(
formatDistancePlus(subDays(new Date(), 1), addDays(new Date(), 2)),
).toBe('3天前')
expect(
formatDistancePlus(subDays(new Date(), 1.5), addDays(new Date(), 2)),
).toBe('3天前')
).toBe('4天前')
expect(
formatDistancePlus(subYears(new Date(), 10), addYears(new Date(), 3)),
).toBe('13年前')
Expand Down
4 changes: 2 additions & 2 deletions src/date/formatDistancePlus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatDistanceStrict, isBefore } from 'date-fns/esm'
import { zhCN } from 'date-fns/esm/locale'
import { formatDistanceStrict, isBefore } from 'date-fns'
import { zhCN } from 'date-fns/locale'

/**
* 将时间转化为 `xxx前/后` 表示。
Expand Down

0 comments on commit 7e7bb5f

Please sign in to comment.