Skip to content

Commit

Permalink
fix(date-picker): 修复预置农历下切换 1891 年以前组件报错问题 (#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
maoguoping committed Jun 4, 2024
1 parent 33f44eb commit 3585fd8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-rice-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/date-picker": patch
---

fix(date-picker): 修复预置农历下切换 1891 年以前组件报错问题 (#2611)
5 changes: 5 additions & 0 deletions .changeset/yellow-yaks-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(date-picker): 修复预置农历下切换 1891 年以前组件报错问题 (#2611)
12 changes: 9 additions & 3 deletions packages/ui/date-picker/src/utils/toLunar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,16 @@ const Lunar = {
},
// 转换农历
toLunar: function (year: number, month: number, day: number) {
let yearData = this.lunarInfo[year - this.MIN_YEAR]
if (year === this.MIN_YEAR && month <= 2 && day <= 9) {
return [1891, 1, 1, '辛卯', '兔', '正月', '初一']
const emptyData = [this.MIN_YEAR, month, day, '', '', '', '']
// 超出数据外时间直接返回空农历数据
if (year < this.MIN_YEAR || year > this.MAX_YEAR) {
return emptyData
}
// 1891年2月9日前不返回农历数据x
if (year === this.MIN_YEAR && (month === 1 || (month === 2 && day < 9))) {
return emptyData
}
let yearData = this.lunarInfo[year - this.MIN_YEAR]
return this.lunarByBetween(year, this.betweenSolarDays(year, month, day, yearData[1], yearData[2]))
},

Expand Down

0 comments on commit 3585fd8

Please sign in to comment.