diff options
author | raylu <raylu@mixpanel.com> | 2011-12-07 22:25:20 -0800 |
---|---|---|
committer | raylu <raylu@mixpanel.com> | 2011-12-07 22:25:43 -0800 |
commit | 3d6f2e46400379bc512c6fb7c7394fbee9e60d76 (patch) | |
tree | 63139252e2be169691b5714b5d79e021081b8558 | |
parent | d2e8d7999913cae4c62b471133a90cc166e3f679 (diff) | |
download | pathery-3d6f2e46400379bc512c6fb7c7394fbee9e60d76.tar.xz |
make countdown timer a little more accurate
-rw-r--r-- | app.php | 7 | ||||
-rw-r--r-- | pages/home.php | 59 |
2 files changed, 25 insertions, 41 deletions
@@ -215,10 +215,3 @@ function translatemap($mapMatrix, $mapID) { $r .= "\n</level>";
return $r;
}
-
-
-
-
-
-
-
diff --git a/pages/home.php b/pages/home.php index ef3438c..815f8fd 100644 --- a/pages/home.php +++ b/pages/home.php @@ -116,43 +116,34 @@ $mergesolution = $map; <div id="fb">
</div>
<?PHP
-$timediff = strtotime("tomorrow") - strtotime("now");
+$timerem = strtotime("tomorrow") - strtotime("now");
?>
-<script type="text/javascript">
-var countdownInt=self.setInterval("countdown()", 1000);
-var timerem = <? echo $timediff; ?>;
-
-function countdown() {
- var hours;
- var minutes;
- var seconds;
- var stamp;
- if (timerem < 1)
- window.clearInterval(countdownInt);
- hours = Math.floor(timerem / 3600);
- minutes = Math.floor((timerem - (hours * 3600)) / 60);
- seconds = timerem % 60;
-
- hours = addZero(hours);
- minutes = addZero(minutes);
- seconds = addZero(seconds);
-
- stamp = hours + ":" + minutes + ":" + seconds;
- document.getElementById("countdown").innerHTML = stamp;
-
- timerem--;
-}
-
-function addZero(num) {
- var numStr = num + '';
- if (numStr.length < 2)
- numStr = "0" + numStr;
- return numStr;
-}
-</script>
<div style='text-align: center; margin-top: 5px'>
- New maps in: <span id="countdown">00:00:00</span>
+ New maps in: <span id="countdown">00:00:00</span>
</div>
+ <script type="text/javascript">
+ var countdownInt = self.setInterval(countdown, 1000);
+ var tomorrow = new Date().getTime() + <? echo $timerem; ?> * 1000;
+
+ function countdown() {
+ var now = new Date();
+ var timerem = new Date(tomorrow - now + now.getTimezoneOffset() * 60 * 1000);
+ if (timerem < 1000)
+ window.clearInterval(countdownInt);
+ var hours = addZero(timerem.getHours());
+ var minutes = addZero(timerem.getMinutes());
+ var seconds = addZero(timerem.getSeconds());
+ var stamp = hours + ":" + minutes + ":" + seconds;
+ document.getElementById("countdown").innerHTML = stamp;
+ }
+
+ function addZero(num) {
+ var numStr = num + '';
+ if (numStr.length < 2)
+ numStr = "0" + numStr;
+ return numStr;
+ }
+ </script>
</div>
<div id="copy">
|