-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
44 lines (34 loc) · 1.18 KB
/
main.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
// Add this script as a trigger in Google AppScript to send to yourself every day so that you stop wasting time on things that don't matter.
const myEmailAddress = "my-email@gmail.com";
const targetDate = new Date(2075, 0, 13); // Date in the future to target countdown from.
function sendSimpleEmail(recipient, subject, message) {
MailApp.sendEmail({
to: recipient,
subject: subject,
body: message
});
}
function getDaysDifference(otherDate) {
const today = new Date();
const compareDate = otherDate;
// Set both dates to midnight to ensure we only count full days
today.setHours(0, 0, 0, 0);
compareDate.setHours(0, 0, 0, 0);
// Calculate difference in milliseconds
const diffMillis = compareDate - today;
// Convert to days
const diffDays = Math.round(diffMillis / (1000 * 60 * 60 * 24));
return diffDays;
}
function addCommasSimple(number) {
return number.toLocaleString();
}
// Example usage:
function sendDaysLeftEmail() {
nDays = addCommasSimple(getDaysDifference(targetDate));
sendSimpleEmail(
myEmailAddress,
`You have ${nDays} sunsets left`,
`You have ${nDays} sunsets left if you live until 80. Don't waste them.`
);
}