Browse Source

BI-133009 fix: 季末日期计算有误

research/test
Oliver.Ke 1 year ago
parent
commit
7ff1c2d8c7
  1. 22
      packages/fineui/src/core/func/date.js

22
packages/fineui/src/core/func/date.js

@ -56,7 +56,7 @@ export function getMonthDays(date, month = date.getMonth()) {
if (((0 === (year % 4)) && ((0 !== (year % 100)) || (0 === (year % 400)))) && month === 1) { if (((0 === (year % 4)) && ((0 !== (year % 100)) || (0 === (year % 400)))) && month === 1) {
return 29; return 29;
} }
return _MD[month]; return _MD[month];
} }
@ -85,7 +85,7 @@ export function getDayOfYear(date) {
const now = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); const now = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
const then = getDate(date.getFullYear(), 0, 0, 0, 0, 0); const then = getDate(date.getFullYear(), 0, 0, 0, 0, 0);
const time = now - then; const time = now - then;
return Math.floor(time / DAY); return Math.floor(time / DAY);
} }
@ -108,7 +108,7 @@ export function getWeekNumber(date) {
const ms = d.valueOf(); const ms = d.valueOf();
d.setMonth(0); d.setMonth(0);
d.setDate(1); d.setDate(1);
return Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; return Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
} }
@ -135,7 +135,7 @@ export function getOffsetQuarter(date, n) {
} }
dt.setDate(day); dt.setDate(day);
dt.setMonth(dt.getMonth() + parseInt(n, 10) * 3); dt.setMonth(dt.getMonth() + parseInt(n, 10) * 3);
return dt; return dt;
} }
@ -159,7 +159,7 @@ export function getQuarterStartMonth(date) {
if (nowMonth > 8) { if (nowMonth > 8) {
quarterStartMonth = 9; quarterStartMonth = 9;
} }
return quarterStartMonth; return quarterStartMonth;
} }
@ -179,8 +179,8 @@ export function getQuarterStartDate(date) {
*/ */
export function getQuarterEndDate(date) { export function getQuarterEndDate(date) {
const quarterEndMonth = getQuarterStartMonth(date) + 2; const quarterEndMonth = getQuarterStartMonth(date) + 2;
return getDate(date.getFullYear(), quarterEndMonth, getMonthDays(date)); return getDate(date.getFullYear(), quarterEndMonth, getMonthDays(date, quarterEndMonth));
} }
/** /**
@ -198,7 +198,7 @@ export function getOffsetMonth(date, n) {
} }
dt.setDate(day); dt.setDate(day);
dt.setMonth(dt.getMonth() + parseInt(n, 10)); dt.setMonth(dt.getMonth() + parseInt(n, 10));
return dt; return dt;
} }
@ -210,7 +210,7 @@ export function getOffsetMonth(date, n) {
export function getWeekStartDate(date) { export function getWeekStartDate(date) {
const w = date.getDay(); const w = date.getDay();
const startOfWeek = StartOfWeek % 7; const startOfWeek = StartOfWeek % 7;
return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)]); return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)]);
} }
@ -222,7 +222,7 @@ export function getWeekStartDate(date) {
export function getWeekEndDate(date) { export function getWeekEndDate(date) {
const w = date.getDay(); const w = date.getDay();
const startOfWeek = StartOfWeek % 7; const startOfWeek = StartOfWeek % 7;
return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)] + 6); return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)] + 6);
} }
@ -349,7 +349,7 @@ export function print(date, str) {
if (!_global.navigator) { if (!_global.navigator) {
return false; return false;
} }
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent); return /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
}; };

Loading…
Cancel
Save