Skip to content

Commit

Permalink
♻️ (category): 重构分类逻辑,并优化时间段判断
Browse files Browse the repository at this point in the history
- 使用 switch 语句来实现更简洁清晰的时间段判断逻辑
- 将原本分散在不同文件中的时间段判断逻辑整合到 getLevel2 函数中
- 优化代码结构,提高代码可读性和可维护性
  • Loading branch information
AnkioTomas committed Sep 30, 2024
1 parent bd7bb78 commit f8f0279
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/category/main.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
import { BillType, isTimeInRange } from 'common/index.js';

function getLevel2 (category) {
switch (category) {
case '三餐':
if (isTimeInRange('06:00', '09:30', time)) {
return '早餐';
}
if (isTimeInRange('9:30', '10:30', time)) {
return '早茶';
}
if (isTimeInRange('10:30', '14:30', time)) {
return '午餐';
}
if (isTimeInRange('14:30', '16:00', time)) {
return '下午茶';
}
if (isTimeInRange('16:00', '21:30', time)) {
return '晚餐';
}
if (isTimeInRange('21:30', '06:00', time)) {
return '夜宵';
}
}
return category;
}



export function get(money, type, shopName, shopItem, time) {
Expand Down Expand Up @@ -137,6 +114,30 @@ export function get(money, type, shopName, shopItem, time) {
});
}

function getLevel2 (category) {
switch (category) {
case '三餐':
if (isTimeInRange('06:00', '09:30', time)) {
return '早餐';
}
if (isTimeInRange('9:30', '10:30', time)) {
return '早茶';
}
if (isTimeInRange('10:30', '14:30', time)) {
return '午餐';
}
if (isTimeInRange('14:30', '16:00', time)) {
return '下午茶';
}
if (isTimeInRange('16:00', '21:30', time)) {
return '晚餐';
}
if (isTimeInRange('21:30', '06:00', time)) {
return '夜宵';
}
}
return category;
}
let category = '其他';
for (const key in rules) {
if (rules[key].test(string)) {
Expand Down

0 comments on commit f8f0279

Please sign in to comment.