Skip to content

Commit

Permalink
Merge pull request #2854 from maoguoping/hotfix/date-picker/2611
Browse files Browse the repository at this point in the history
fix(date-picker): 修复预置农历下切换 1891 年以前组件报错问题 (#2611)
  • Loading branch information
solarjoker committed Jun 12, 2024
2 parents 1640bc4 + f8db2ef commit 7e2138d
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日前不返回农历数据
if (year === this.MIN_YEAR && (month === 1 || (month === 2 && day < 9))) {
return emptyData
}
const 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 7e2138d

Please sign in to comment.