Skip to content

Commit

Permalink
fix(next/antd): fix moment timestamp (#3395)
Browse files Browse the repository at this point in the history
* fix(next): fix moment timestamp

* feat(next\antd): update moment timestamp test

* feat(next\antd): add moment timestamp test

* feat(next\antd): add moment timestamp array format test
  • Loading branch information
heihei12305 authored Sep 14, 2022
1 parent 5acb7e1 commit 2054c10
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/antd/__tests__/moment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ test('formatMomentValue is usable', () => {
)
expect(formatMomentValue('12:11', 'HH:mm')).toBe('12:11')
expect(formatMomentValue('12:11:11', 'HH:mm:ss')).toBe('12:11:11')
expect(formatMomentValue(1663155911097, 'YYYY-MM-DD HH:mm:ss')).toBe(
moment(1663155911097).format('YYYY-MM-DD HH:mm:ss')
)
expect(formatMomentValue([1663155911097], ['YYYY-MM-DD HH:mm:ss'])).toEqual([
moment(1663155911097).format('YYYY-MM-DD HH:mm:ss'),
])
expect(
formatMomentValue(
['2021-12-21 15:47:00', '2021-12-29 15:47:00'],
Expand Down
6 changes: 6 additions & 0 deletions packages/antd/src/__builtins__/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const formatMomentValue = (
if (isEmpty(_format)) {
return date
}
if (typeof date === 'number') {
return moment(date).format(_format)
}
return moment(date, _format).format(_format)
} else {
if (isFn(format)) {
Expand All @@ -32,6 +35,9 @@ export const formatMomentValue = (
if (isEmpty(format)) {
return date
}
if (typeof date === 'number') {
return moment(date).format(format)
}
return moment(date, format).format(format)
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/next/__tests__/moment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ test('formatMomentValue is usable', () => {
)
expect(formatMomentValue('12:11', 'HH:mm')).toBe('12:11')
expect(formatMomentValue('12:11:11', 'HH:mm:ss')).toBe('12:11:11')
expect(formatMomentValue(1663155911097, 'YYYY-MM-DD HH:mm:ss')).toBe(
moment(1663155911097).format('YYYY-MM-DD HH:mm:ss')
)
expect(formatMomentValue([1663155911097], ['YYYY-MM-DD HH:mm:ss'])).toEqual([
moment(1663155911097).format('YYYY-MM-DD HH:mm:ss'),
])
expect(
formatMomentValue(
['2021-12-21 15:47:00', '2021-12-29 15:47:00'],
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/__builtins__/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const formatMomentValue = (
if (isEmpty(_format)) {
return date
}
if (typeof date === 'number') {
return moment(date).format(_format)
}
return moment(date, _format).format(_format)
} else {
if (isFn(format)) {
Expand All @@ -36,6 +39,9 @@ export const formatMomentValue = (
if (isEmpty(format)) {
return date
}
if (typeof date === 'number') {
return moment(date).format(format)
}
return moment(date, format).format(format)
}
}
Expand Down

0 comments on commit 2054c10

Please sign in to comment.