From 556090e7d52ab2706ef2f58236d185379591fd33 Mon Sep 17 00:00:00 2001 From: yupeng <1196194875@qq.com> Date: Wed, 4 Sep 2024 15:12:25 +0800 Subject: [PATCH] Fix: leap year calculation --- src/ext.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ext.js b/src/ext.js index 29de6cb..05281a5 100644 --- a/src/ext.js +++ b/src/ext.js @@ -1,3 +1,15 @@ +function isLeapYear(year) { + if (year % 4 === 0) { + if (year % 100 === 0) { + if (year % 400 === 0) { + return true; + } + return false; + } + return true; + } + return false; +} /* ----------------------------------------------------------------------------- * * procedure days2mdhms @@ -35,7 +47,7 @@ * none. * --------------------------------------------------------------------------- */ export function days2mdhms(year, days) { - const lmonth = [31, (year % 4) === 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + const lmonth = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; const dayofyr = Math.floor(days); // ----------------- find month and day of month ----------------