Skip to content

Commit

Permalink
fix(next): fix time format moment (#3330)
Browse files Browse the repository at this point in the history
  • Loading branch information
heihei12305 authored Aug 11, 2022
1 parent f7e1b7d commit 8b7bbd2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/antd/__tests__/moment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ test('formatMomentValue is usable', () => {
expect(formatMomentValue('2021-12-21 15:47:00', (date: string) => date)).toBe(
'2021-12-21 15:47:00'
)
expect(formatMomentValue('12:11', 'HH:mm')).toBe('12:11')
expect(formatMomentValue('12:11:11', 'HH:mm:ss')).toBe('12:11:11')
expect(
formatMomentValue(
['2021-12-21 15:47:00', '2021-12-29 15:47:00'],
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/src/__builtins__/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const formatMomentValue = (
if (isEmpty(_format)) {
return date
}
return moment(date).format(_format)
return moment(date, _format).format(_format)
} else {
if (isFn(format)) {
return format(date)
}
if (isEmpty(format)) {
return date
}
return moment(date).format(format)
return moment(date, format).format(format)
}
}
if (isArr(value)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/__tests__/moment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ test('formatMomentValue is usable', () => {
expect(formatMomentValue('2021-12-21 15:47:00', (date: string) => date)).toBe(
'2021-12-21 15:47:00'
)
expect(formatMomentValue('12:11', 'HH:mm')).toBe('12:11')
expect(formatMomentValue('12:11:11', 'HH:mm:ss')).toBe('12:11:11')
expect(
formatMomentValue(
['2021-12-21 15:47:00', '2021-12-29 15:47:00'],
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/__builtins__/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export const formatMomentValue = (
if (isEmpty(_format)) {
return date
}
return moment(date).format(_format)
return moment(date, _format).format(_format)
} else {
if (isFn(format)) {
return format(date)
}
if (isEmpty(format)) {
return date
}
return moment(date).format(format)
return moment(date, format).format(format)
}
}
if (isArr(value)) {
Expand Down

0 comments on commit 8b7bbd2

Please sign in to comment.