refactor: ES6+ modernization + 2 bugfixes
- var→const/let, function→arrow/class across all 13 JS files - Timer: prototype→class with ES6 getters - plan days: IIFE→Array.from declarative generation - storage/plan: unified formatDate via util.js - Bugfix: getPlanDay now filters by planId (plan switch accuracy) - Bugfix: getTodayRecord searches all months (cross-month boundary) - WXML/WXSS unchanged; public API unchanged
This commit is contained in:
+31
-26
@@ -1,31 +1,28 @@
|
||||
function formatTime(seconds) {
|
||||
var m = Math.floor(seconds / 60)
|
||||
var s = seconds % 60
|
||||
return (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s
|
||||
const formatTime = (seconds) => {
|
||||
const m = Math.floor(seconds / 60)
|
||||
const s = seconds % 60
|
||||
return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function formatDuration(seconds) {
|
||||
if (seconds < 60) return seconds + '秒'
|
||||
var m = Math.floor(seconds / 60)
|
||||
var s = seconds % 60
|
||||
return s > 0 ? m + '分' + s + '秒' : m + '分钟'
|
||||
const formatDuration = (seconds) => {
|
||||
if (seconds < 60) return `${seconds}秒`
|
||||
const m = Math.floor(seconds / 60)
|
||||
const s = seconds % 60
|
||||
return s > 0 ? `${m}分${s}秒` : `${m}分钟`
|
||||
}
|
||||
|
||||
function getDaysInMonth(year, month) {
|
||||
return new Date(year, month, 0).getDate()
|
||||
}
|
||||
const getDaysInMonth = (year, month) => new Date(year, month, 0).getDate()
|
||||
|
||||
function getMonthCalendar(year, month) {
|
||||
var firstDay = new Date(year, month - 1, 1)
|
||||
var lastDay = new Date(year, month, 0)
|
||||
var daysInMonth = lastDay.getDate()
|
||||
var startDayOfWeek = firstDay.getDay()
|
||||
const getMonthCalendar = (year, month) => {
|
||||
const firstDay = new Date(year, month - 1, 1)
|
||||
const daysInMonth = new Date(year, month, 0).getDate()
|
||||
const startDayOfWeek = firstDay.getDay()
|
||||
|
||||
var weeks = []
|
||||
var week = [null, null, null, null, null, null, null]
|
||||
const weeks = []
|
||||
let week = [null, null, null, null, null, null, null]
|
||||
|
||||
for (var d = 1; d <= daysInMonth; d++) {
|
||||
var dow = (startDayOfWeek + d - 1) % 7
|
||||
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())
|
||||
@@ -36,9 +33,17 @@ function getMonthCalendar(year, month) {
|
||||
return weeks
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime,
|
||||
formatDuration: formatDuration,
|
||||
getDaysInMonth: getDaysInMonth,
|
||||
getMonthCalendar: getMonthCalendar
|
||||
const formatDate = (date) => {
|
||||
const y = date.getFullYear()
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const d = String(date.getDate()).padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime,
|
||||
formatDuration,
|
||||
getDaysInMonth,
|
||||
getMonthCalendar,
|
||||
formatDate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user