fix(wecom): 经营报告截账至发送日前一天24点
日报、周报、月报均不含发送当天发生额,避免盘中数据未闭合。
This commit is contained in:
@@ -67,15 +67,21 @@ function lastDayOfShanghaiMonth(year: number, month: number): number {
|
||||
return Number(shanghaiYmd(new Date(shanghaiMonthRange(year, month).endExclusive.getTime() - 1)).slice(8, 10));
|
||||
}
|
||||
|
||||
/** 日报=当天;周报=上一自然周;月报=上一自然月(北京日历) */
|
||||
/** 发送日北京 0 点 = 前一天 24 点,账期不含发送当天 */
|
||||
export function wecomReportAsOf(now = new Date()): Date {
|
||||
return startOfShanghaiDay(now);
|
||||
}
|
||||
|
||||
/** 日报=昨日;周报=上一自然周;月报=上一自然月。期末均为某日 0 点。 */
|
||||
export function wecomReportPeriod(kind: WecomReportKind, now = new Date()): WecomReportPeriod {
|
||||
const asOf = wecomReportAsOf(now);
|
||||
if (kind === 'daily') {
|
||||
const start = startOfShanghaiDay(now);
|
||||
const start = addShanghaiDays(asOf, -1);
|
||||
const ymd = shanghaiYmd(start);
|
||||
return {
|
||||
kind,
|
||||
start,
|
||||
endExclusive: addShanghaiDays(start, 1),
|
||||
endExclusive: asOf,
|
||||
periodKey: ymd,
|
||||
title: `日报(${ymd})`,
|
||||
rangeLabel: ymd,
|
||||
@@ -83,7 +89,7 @@ export function wecomReportPeriod(kind: WecomReportKind, now = new Date()): Weco
|
||||
};
|
||||
}
|
||||
if (kind === 'weekly') {
|
||||
const { start, endExclusive } = previousShanghaiWeek(now);
|
||||
const { start, endExclusive } = previousShanghaiWeek(asOf);
|
||||
const from = shanghaiYmd(start);
|
||||
const to = shanghaiYmd(new Date(endExclusive.getTime() - 1));
|
||||
return {
|
||||
@@ -96,7 +102,7 @@ export function wecomReportPeriod(kind: WecomReportKind, now = new Date()): Weco
|
||||
incrementLabel: '本期新增',
|
||||
};
|
||||
}
|
||||
const { year, month } = previousShanghaiMonth(now);
|
||||
const { year, month } = previousShanghaiMonth(asOf);
|
||||
const { start, endExclusive } = shanghaiMonthRange(year, month);
|
||||
return {
|
||||
kind,
|
||||
@@ -109,9 +115,9 @@ export function wecomReportPeriod(kind: WecomReportKind, now = new Date()): Weco
|
||||
};
|
||||
}
|
||||
|
||||
/** 进行中的周期截到 now,已结束的周期用期末 */
|
||||
export function wecomReportCutoff(period: WecomReportPeriod, now = new Date()): Date {
|
||||
return now.getTime() < period.endExclusive.getTime() ? now : period.endExclusive;
|
||||
/** 账期期末:发送日 0 点或上一周/月结束 0 点,不含发送当天发生额 */
|
||||
export function wecomReportCutoff(period: WecomReportPeriod): Date {
|
||||
return period.endExclusive;
|
||||
}
|
||||
|
||||
export function wecomReportDueAt(kind: WecomReportKind, schedule: WecomReportSchedule, now = new Date()): Date {
|
||||
|
||||
Reference in New Issue
Block a user