打卡定位

This commit is contained in:
2026-09-24 11:41:39 +08:00
parent bef7f00970
commit 403f7e835f
3 changed files with 65 additions and 24 deletions
+29
View File
@@ -92,6 +92,35 @@ export function pad2(n) {
return String(n).padStart(2, '0')
}
/** 弹性:9:009:30 上班,18:0018:30 下班。早于 9:00、晚于 18:30 的分钟计入调休。 */
export function flexCreditMinutes(inTime, outTime) {
const inn = hmMinutes(inTime)
const out = hmMinutes(outTime)
let extra = 0
if (inn != null && inn < 9 * 60) extra += 9 * 60 - inn
if (out != null && out > 18 * 60 + 30) extra += out - (18 * 60 + 30)
return extra
}
export function flexCreditText(minutes) {
const n = Math.max(0, Math.round(Number(minutes) || 0))
if (!n) return '0 分钟'
const h = Math.floor(n / 60)
const m = n % 60
if (h && m) return h + ' 小时 ' + m + ' 分钟'
if (h) return h + ' 小时'
return m + ' 分钟'
}
function hmMinutes(value) {
const m = String(value || '').match(/(\d{1,2}):(\d{2})/)
if (!m) return null
const h = Number(m[1])
const min = Number(m[2])
if (h > 23 || min > 59) return null
return h * 60 + min
}
export function clockText(date) {
const d = date || new Date()
return `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`