2e2594d154
- 修复 cloud.clearAll 静默失败导致重启后数据恢复 - 清除数据弹窗改用自定义 ui-modal 替代 wx.showModal - TTS 语音合成增加 fileID 持久化缓存,重启不再重新合成 - 排行榜限制前15名,maxRank 参数化到 config.js - 新增 config.js 统一管理版本号/更新日期/开发者/排行榜限制 - progress-ring 消除 getSystemInfoSync 弃用警告 - voice.js 增加 InnerAudioContext 错误监听 - storage/util 完善用户资料、打卡日期精度、记录日志
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
const formatTime = (seconds) => {
|
|
const m = Math.floor(seconds / 60)
|
|
const s = seconds % 60
|
|
return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
|
|
}
|
|
|
|
const formatDuration = (seconds) => {
|
|
if (seconds < 60) return `${seconds}秒`
|
|
const m = Math.floor(seconds / 60)
|
|
const s = seconds % 60
|
|
return s > 0 ? `${m}分${s}秒` : `${m}分钟`
|
|
}
|
|
|
|
const getDaysInMonth = (year, month) => new Date(year, month, 0).getDate()
|
|
|
|
const getMonthCalendar = (year, month) => {
|
|
const firstDay = new Date(year, month - 1, 1)
|
|
const daysInMonth = new Date(year, month, 0).getDate()
|
|
const startDayOfWeek = firstDay.getDay()
|
|
|
|
const weeks = []
|
|
let week = [null, null, null, null, null, null, null]
|
|
|
|
for (let d = 1; d <= daysInMonth; d++) {
|
|
const dow = (startDayOfWeek + d - 1) % 7
|
|
week[dow] = d
|
|
if (dow === 6 || d === daysInMonth) {
|
|
weeks.push(week.slice())
|
|
week = [null, null, null, null, null, null, null]
|
|
}
|
|
}
|
|
|
|
return weeks
|
|
}
|
|
|
|
/**
|
|
* Format a Date as `YYYY-MM-DD HH:MM:SS` in local time.
|
|
*
|
|
* Used as the canonical `record.date` string so each record has a
|
|
* precise timestamp (e.g. "2026-06-11 14:30:45"). Use `_dateOnly()`
|
|
* to strip back to YYYY-MM-DD for date-level comparisons (streak,
|
|
* leaderboard day filter, etc.).
|
|
*/
|
|
const formatDate = (date) => {
|
|
const y = date.getFullYear()
|
|
const mo = String(date.getMonth() + 1).padStart(2, '0')
|
|
const d = String(date.getDate()).padStart(2, '0')
|
|
const h = String(date.getHours()).padStart(2, '0')
|
|
const mi = String(date.getMinutes()).padStart(2, '0')
|
|
const s = String(date.getSeconds()).padStart(2, '0')
|
|
return `${y}-${mo}-${d} ${h}:${mi}:${s}`
|
|
}
|
|
|
|
/** Strip the time portion of a formatDate string → "YYYY-MM-DD". */
|
|
const _dateOnly = (s) => (typeof s === 'string' && s.length >= 10) ? s.substring(0, 10) : ''
|
|
|
|
module.exports = {
|
|
formatTime,
|
|
formatDuration,
|
|
getDaysInMonth,
|
|
getMonthCalendar,
|
|
formatDate,
|
|
dateOnly: _dateOnly
|
|
}
|