Skip to content

Commit 4458bfe

Browse files
committed
[2.0.57] Countdown fixes + misc.
1 parent 463c748 commit 4458bfe

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

countdown.js

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
/*
2-
1000 days = 86,400,000,000 ms
3-
2 years (730.5 days) = 63,115,200,000 ms
4-
1 year (365.25 days) = 31,557,600,000 ms
5-
1 year (365 days) = 31,536,000,000 ms
6-
1 month = 365 / 12 = 30.417 days = 2,628,000,000 ms
7-
100 hours = 4d 4h = 360,000,000 ms
8-
1 day = 86,400,000 ms
9-
100 mins = 1h 40m = 6,000,000 ms
10-
1 hour = 3,600,000 ms
11-
1 minute = 60,000 ms
12-
1 second = 1,000 ms
13-
142
----- ENGLISH -----
153
Parameters:
164
goal parameter must be in YYYY-MM-DDTHH:ii:ssZ format (YYYY for year, MM for month, DD for day, HH for hours, ii for minutes and ss for seconds. "T" and "Z" must be left as is. Example: "2022-07-04T14:43:58Z" for July 4th, 2022 at 2:43:58 PM UTC)
@@ -36,38 +24,45 @@ Utilisation :
3624
Mettez l'identifiant de l'élément que vous souhaitez transformer en compte à rebours sur un identifiant relié à un compteur.
3725
*/
3826

27+
var year = 31556952000; //1 year = 365.2425 days = 31,556,952,000 ms
28+
var month = year/12; //1 month = 30.436875 days = 2,629,746,000 ms
29+
var day = 86400000; //1 day = 86,400,000 ms
30+
var hour = day/24; //1 hour = 3,600,000 ms
31+
var minute = hour/60; //1 minute = 60,000 ms
32+
var second = minute/60; //1 second = 1,000 ms
33+
3934
function countdownTo(goal, formatBefore = "%countdown", formatAfter = "", id = "countdown"){
4035
var nowDate = new Date();
4136
var goalDate = new Date(goal);
4237
var gap = Math.abs(goalDate - nowDate);
4338
//Formatting count
44-
if(gap>=63115200000){ //if more than 2 years
45-
var countString = Math.floor(gap/31557600000)+" ans";
39+
if(gap>=2*year){ //if more than 2 years
40+
var countString = Math.floor(gap/year)+" ans";
4641
}
47-
if(gap<63115200000 && gap>=31536000000){ //if between 1 and 2 years
48-
var countString = Math.floor(gap/31557600000)+" an";
42+
if(gap<2*year && gap>=year){ //if between 1 and 2 years
43+
var countString = Math.floor(gap/year)+" an";
4944
}
50-
if(gap<31536000000 && gap>=2628000000){ //if between 1 month and 1 year
51-
var countString = Math.floor(gap/2628000000)+" mois";
45+
if(gap<year && gap>=month){ //if between 1 month and 1 year
46+
var countString = Math.floor(gap/month)+" mois";
5247
}
53-
if(gap<2628000000 && gap>=360000000){ //if between 100 hours (4d 4h) and 1 month
54-
var countString = Math.floor(gap/86400000)+" jours";
48+
if(gap<month && gap>=100*hour){ //if between 100 hours (4d 4h) and 1 month
49+
var countString = Math.floor(gap/day)+" jours";
5550
}
56-
if(gap<360000000 && gap>=3600000){ //if between 1 hour and 100 hours (4d 4h)
57-
var countString = Math.floor(gap/3600000)+"h "+("0"+Math.floor(gap/60000)%60).slice(-2)+"m";
51+
if(gap<100*hour && gap>=hour){ //if between 1 hour and 100 hours (4d 4h)
52+
var countString = Math.floor(gap/hour)+"h "+("0"+Math.floor(gap/minute)%60).slice(-2)+"m";
5853
}
59-
if(gap<3600000 && gap>=60000){ //if between 1 min and 1 hour
60-
var countString = Math.floor(gap/60000)+"' "+("0"+Math.floor(gap/1000)%60).slice(-2)+"''";
54+
if(gap<hour && gap>=minute){ //if between 1 min and 1 hour
55+
var countString = Math.floor(gap/minute)+"' "+("0"+Math.floor(gap/second)%60).slice(-2)+"''";
6156
}
62-
if(gap<60000 && gap>=0){ //if less than 1 min
63-
var countString = Math.floor(gap/1000)+"''";
57+
if(gap<minute && gap>=0){ //if less than 1 min
58+
var countString = Math.floor(gap/second)+"''";
6459
}
6560
//Choosing the right format
6661
if(goalDate > nowDate){
6762
var finalString = formatBefore.replace('%countdown',countString);
6863
}else{
6964
var finalString = formatAfter.replace('%countup',countString);
7065
}
71-
setTimeout(countdownTo, 1000, goal, formatBefore, formatAfter, id);
66+
setTimeout(countdownTo, second, goal, formatBefore, formatAfter, id);
7267
document.getElementById(id).innerHTML = finalString;
7368
}

views/about.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,5 @@
118118
v1.0 (juin 2022) par <a href="https://www.marioswitch.fr/">MarioSwitch</a> et <a href="https://github.com/yoshakami">Yosh</a><br>
119119
v1.1 (mai 2023) par <a href="https://www.marioswitch.fr/">MarioSwitch</a><br>
120120
v2.0 (actuelle, juin 2023) par <a href="https://www.marioswitch.fr/">MarioSwitch</a><br><br>
121-
<i>Version 2.0.56 du 15 mai 2024</i>
121+
<i>Version 2.0.57 du 31 mai 2024</i>
122122
</p>

views/leaderboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$myPoints = intSQL("SELECT `points` FROM `users` WHERE `username` = ?;", [$_COOKIE["username"]]);
1818
$myRank = intSQL("SELECT COUNT(*) FROM `users` WHERE `points` > " . $myPoints . ";") + 1;
1919
$myTop = ($myRank / $accounts)*100;
20-
echo "<p>Vous êtes " . displayOrdinal($myRank) . " sur " . displayInt($accounts) . " (top " . displayFloat($myTop) . " %).</p>";
20+
echo "<p>Vous êtes " . displayOrdinal($myRank) . " sur " . displayInt($accounts) . " (top " . displayFloat($myTop) . " %).</p>";
2121
}else{
2222
echo "<p>Total : " . displayInt($accounts) . " utilisateurs</p>";
2323
}
@@ -30,7 +30,7 @@
3030
$user = $classement[$i]["username"];
3131
$points = $classement[$i]["points"];
3232
$rank = intSQL("SELECT COUNT(*) FROM `users` WHERE `points` > " . $points . ";") + 1;
33-
echo "<tr><td>" . displayInt($rank, false) . "</td><td><p><a href='?view=profile&user=" . $user . "'>" . displayUsername($user) . "</a></p></td><td>" . displayInt($points) . "</td></tr>";
33+
echo "<tr><td>" . displayOrdinal($rank) . "</td><td><p><a href='?view=profile&user=" . $user . "'>" . displayUsername($user) . "</a></p></td><td>" . displayInt($points) . "</td></tr>";
3434
}
3535
}
3636
echo "<tr><td colspan='3'>";

views/prediction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@
126126
<p>Fin des votes <abbr id='endedCountdown' title='" . $prediEnd . " UTC'>" . $prediEnd . " UTC</abbr></p>");
127127
if($prediAnswered != NULL){
128128
echo("<p>Réponse donnée <abbr id='answeredCountdown' title='" . $prediAnswered . " UTC'>" . $prediAnswered . " UTC</abbr></p>");
129-
}else if($mode == "waitingAnswer"){
130-
echo("<p>En attente de réponse...</p>");
129+
}else if($prediEnd < stringSQL("SELECT NOW();")){
130+
echo("<p>En attente de réponse</p>");
131131
}
132132
echo("
133133
<h2>" . $prediNumberOfAnswers . " réponses possibles</h2>

0 commit comments

Comments
 (0)