移动端V1.0

This commit is contained in:
2025-07-16 15:34:34 +08:00
commit 194b0750fd
1083 changed files with 178295 additions and 0 deletions

37
utils/time-calculation.js Normal file
View File

@@ -0,0 +1,37 @@
export function calculateDays(startDate, endDate) {
// 计算时间差,单位为毫秒
const timeDiff = endDate - startDate;
// 将时间差转换为小时
const hoursDiff = timeDiff / (1000 * 60 * 60);
// 根据不同的时间差范围计算天数
let days = 0;
if (hoursDiff >= 8) {
// 大于等于8个小时算1天
days = Math.ceil(hoursDiff / 24);
} else if (hoursDiff >= 4) {
// 大于等于4个小时算半天
days = 0.5;
} else if (hoursDiff >= 2) {
// 大于等于2个小时算0.25天
days = 0.25;
}
return days;
}
// 判断值是否为时间戳格式并进行转换
export function convertToTimestamp(value) {
// 如果值已经是时间戳格式,则直接返回
if (typeof value === 'number' && !isNaN(value) && isFinite(value)) {
return value;
}
// 尝试将值转换为时间戳格式
const timestamp = Date.parse(value);
// 如果转换成功,则返回时间戳;否则返回 NaN
return isNaN(timestamp) ? NaN : timestamp;
}