-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaysmatter.js
72 lines (64 loc) · 1.88 KB
/
daysmatter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
倒数日
使用:
#每天 8点通知, 也可以自定义其他时间, 详情:https://community.nssurge.com/d/33-scripting
[Script]
cron "0 8 * * *" script-path=https://github.com/congcong0806/surge-list/raw/master/Script/daysmatter.js
*/
Date.prototype.format = function(fmt) {
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/i.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return fmt;
};
//倒数日计算
function dateDiff(startDate, endDate) {
//2002-12-18格式
var sdate, edate, days
sdate = new Date(startDate)
edate = new Date(endDate)
//把相差的毫秒数转换为天数
days = parseInt((sdate - edate) / 1000 / 60 / 60 / 24)
return days;
}
const dayarr = [
[ "在一起", "2023-07-24" ]
]
day();
function day() {
var now = new Date()
var nowStr = now.format("yyyy-MM-dd")
var content = "Good Day,就是今天\n";
for ( var i in dayarr) {
var d = dateDiff(dayarr[i][1], nowStr)
if(isNaN(d))
continue
var u = valcal(d)
content += dayarr[i][0] + "," + u + "\n"
}
console.log(content);
$notification.post('倒数日', "", content)
$done()
}
function valcal(days) {
if (days == 0)
return "就是今天"
else if (days > 0)
return "剩余:" + days + "天"
else
return "已过:" + Math.abs(days) + "天"
}