new posts

This commit is contained in:
stjet
2024-09-01 01:31:36 +00:00
parent 3ce4de70a2
commit 06e4c0ecfe
7 changed files with 93 additions and 7 deletions

View File

@@ -5,7 +5,7 @@ The beginning of the month would depend on your timezone, but we want the faucet
Now, for writing the code for the countdown, I could just use Javascript's built in `Date` class. This is a slightly modified version of the code I came up with:
```js
function get_next_month_unix() {
function get_next_month_diff() {
let current_date = new Date();
//get Date object set to the beginning of the next month
//if current month is january, next month will technically give the date of december 31st midnight but that's fine since that's the same time as january 1st 00:00:00
@@ -13,8 +13,9 @@ function get_next_month_unix() {
//get difference in seconds between current time and the start of the next month
return (next_month.getTime() - current_date.getTime()) / 1000;
}
setInterval(function() {
let seconds_until = get_next_month_unix();
let seconds_until = get_next_month_diff();
//... rest of the code omitted
}, 1000);
```
@@ -47,6 +48,10 @@ function get_next_month_unix() {
unix_timestamp += next_month*(60*60*24*30);
return unix_timestamp;
}
function get_next_month_diff() {
return get_next_month_unix() - (Date.now() / 1000);
}
```
But wait! Months don't always have 30 days. Oops.
@@ -90,6 +95,10 @@ function get_next_month_unix() {
}
return unix_timestamp;
}
function get_next_month_diff() {
return get_next_month_unix() - (Date.now() / 1000);
}
```
And don't forget leap days...
@@ -145,6 +154,10 @@ function get_next_month_unix() {
}
return unix_timestamp;
}
function get_next_month_diff() {
return get_next_month_unix() - (Date.now() / 1000);
}
```
At this point, while thinking about leap days, I realized one huge problem: [leap seconds](https://en.wikipedia.org/wiki/Leap_second). It's a pretty bizzare concept.