Skip to content

Commit

Permalink
修改时间函数
Browse files Browse the repository at this point in the history
  • Loading branch information
SHL-COOL committed Aug 25, 2024
1 parent ed947ce commit 0b2e4c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resource/sites/star-space.net/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"#tm_td_uploader"
],
"filters": [
"new Date(Date.now() - (query.text().match(/\\d+[分时天月年]/g).reduce((acc, time) => {const [, number, unit] = time.match(/(\\d+)([分时天月年])/);return acc + (parseInt(number) * (unit === '分' ? 1 :unit === '时' ? 60 :unit === '天' ? 60 * 24 :unit === '月' ? 60 * 24 * 30 :unit === '年' ? 60 * 24 * 365 : 0));}, 0) * 60 * 1000)).toLocaleString('zh-CN', { hour12: false }).replace(/\\//g, '-')"
"query.text().parseTime()"
]
},
"size": {
Expand Down
31 changes: 31 additions & 0 deletions src/interface/types.expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,34 @@ String.prototype.timeToDays = function() {
})
return length;
};



String.prototype.parseTime = function() {
const timeMatch = this.match(/\d+[分时天月年]/g)
let length = 0
timeMatch.forEach(time => {
const timeMatch = time.match(/(\d+)([分时天月年])/)
const number = parseInt(timeMatch[1])
const unit = timeMatch[2]
switch (true) {
case unit === '分':
length += number
break
case unit === '时':
length += number * 60
break
case unit === '天':
length += number * 60 * 24
break
case unit === '月':
length += number * 60 * 24 * 30
break
case unit === '年':
length += number * 60 * 24 * 365
break
default:
}
})
return new Date(Date.now() - length * 60 * 1000).toLocaleString("zh-CN", { hour12: false }).replace(/\//g, '-')
}

0 comments on commit 0b2e4c2

Please sign in to comment.