来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
/** 中国时区 YYYY-MM-DD。微信部分运行时无 Intl,不用 DateTimeFormat。中国无夏令时。 */
|
|
const SHANGHAI_OFFSET_MS = 8 * 60 * 60 * 1000;
|
|
|
|
function shanghaiIso(date = new Date()) {
|
|
const d = date instanceof Date ? date : new Date(date);
|
|
if (Number.isNaN(d.getTime())) return '';
|
|
return new Date(d.getTime() + SHANGHAI_OFFSET_MS).toISOString();
|
|
}
|
|
|
|
function formatChinaDate(date = new Date()) {
|
|
const iso = shanghaiIso(date);
|
|
return iso ? iso.slice(0, 10) : '';
|
|
}
|
|
|
|
/** 中国时区 YYYY-MM-DD HH:mm:ss。不用 toLocaleString / Intl(真机可能打出 GMT 英文串)。 */
|
|
function formatChinaDateTime(date = new Date()) {
|
|
const iso = shanghaiIso(date);
|
|
return iso ? `${iso.slice(0, 10)} ${iso.slice(11, 19)}` : '';
|
|
}
|
|
|
|
function chinaTodayYmd() {
|
|
return formatChinaDate(new Date());
|
|
}
|
|
|
|
function shiftChinaYmd(ymd, days) {
|
|
const anchor = new Date(`${ymd}T12:00:00+08:00`);
|
|
if (Number.isNaN(anchor.getTime())) return String(ymd || '');
|
|
anchor.setUTCDate(anchor.getUTCDate() + (Number(days) || 0));
|
|
return formatChinaDate(anchor);
|
|
}
|
|
|
|
/** 业务日历日:纯日期原样;带时区的时间戳按中国日历,不用 UTC 的 slice(0,10) */
|
|
function calendarDayYmd(raw) {
|
|
if (raw == null || raw === '') return '';
|
|
const asText = String(raw).trim();
|
|
if (/^\d{4}-\d{2}-\d{2}$/.test(asText)) return asText;
|
|
const china = formatChinaDate(raw);
|
|
if (/^\d{4}-\d{2}-\d{2}$/.test(china)) return china;
|
|
const sliced = asText.slice(0, 10);
|
|
return /^\d{4}-\d{2}-\d{2}$/.test(sliced) ? sliced : '';
|
|
}
|
|
|
|
module.exports = {
|
|
formatChinaDate,
|
|
formatChinaDateTime,
|
|
chinaTodayYmd,
|
|
shiftChinaYmd,
|
|
calendarDayYmd,
|
|
};
|