Initial commit: gamer project
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// 日期范围辅助函数
|
||||
function getMonthRange(qYear, qMonth) {
|
||||
const now = new Date();
|
||||
const y = Number(qYear) || now.getFullYear();
|
||||
const m = Number(qMonth) || (now.getMonth() + 1);
|
||||
const startDate = `${y}-${String(m).padStart(2, '0')}-01`;
|
||||
const nm = m + 1 > 12 ? 1 : m + 1;
|
||||
const ny = m + 1 > 12 ? y + 1 : y;
|
||||
const endDate = `${ny}-${String(nm).padStart(2, '0')}-01`;
|
||||
return { startDate, endDate };
|
||||
}
|
||||
|
||||
// CSV行解析(处理引号内的逗号)
|
||||
function parseCSVLine(line) {
|
||||
const result = [];
|
||||
let current = '';
|
||||
let inQuotes = false;
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const ch = line[i];
|
||||
if (inQuotes) {
|
||||
if (ch === '"' && line[i + 1] === '"') { current += '"'; i++; }
|
||||
else if (ch === '"') { inQuotes = false; }
|
||||
else { current += ch; }
|
||||
} else {
|
||||
if (ch === '"') { inQuotes = true; }
|
||||
else if (ch === ',') { result.push(current); current = ''; }
|
||||
else { current += ch; }
|
||||
}
|
||||
}
|
||||
result.push(current);
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = { getMonthRange, parseCSVLine };
|
||||
Reference in New Issue
Block a user