[ create a new paste ] login | about

Link: http://codepad.org/BzvBTrOl    [ raw code | output | fork ]

PHP, pasted on May 25:
<?php

#### This bit of code generates the next page update based on the current time() and the fact BCB updates at 1PM, Monday, Wednesday and Friday, New York time.
#### It ultimately formats it as $nextupdate, a unix timestamp of the next page update time, which is always sometime in the future.
#### It then feeds this to a Javascript countdown thing, http://countdownjs.org.

#### Ever since I implemented it, occasionally people remark that the countdown says "44234523 hours until next update!" or similar. Some wrong, absurdly high number. It appears to happen for an hour or less every update cycle.
#### I updated countdown.js to a newer version, but it's hard to test if that fixed it. Is there any problem with my next page date predicting code below? If it, at any point generated a weirdly long-in-the-future timestamp, then it's my code at fault and not the external javascript.

#### HERE GOES:


## Generate next page date text.
# Set the prefix text
if($pagecount == $realpagecount) {
    $staytuned = "The first page of the next chapter debuts in ";
} else {
    $staytuned = "The next page debuts in ";
}
# Set the timezone to EST
date_default_timezone_set('America/New_York');
$day = date("D");
# If it's a weekday where we update..
if($day == "Mon" || $day == "Wed" || $day == "Fri") {
    # If it's before 1pm
    if(time() < strtotime("midnight today + 13 hours")) {
        # The answer is today at 1pm.
        $nextupdate = strtotime("midnight today + 13 hours");
    } else {
    # So it's after 1pm on a weekday where we update...
        # If it's Friday
        if($day == "Fri") {
            # The answer is next Monday at 1pm.
            $nextupdate = strtotime("midnight next Monday + 13 hours");
        } else {
            # The answer is two days from today at 1pm
            $nextupdate = strtotime("midnight today +2 day + 13 hours");
        }
    }
} elseif($day == "Tue" || $day == "Thu") {
    # The answer is tomorrow at 1pm
    $nextupdate = strtotime("midnight today +1 day + 13 hours");
} elseif($day == "Sat" || $day == "Sun") {
    # It's the weekend, so the answer is Monday.
    $nextupdate = strtotime("midnight next Monday + 13 hours");
}


// normally here we * 1000 before feeding it to the js because it expects milliseconds, but for testing purposes we will spit out a human-readable date
$readablenextpagedate = date('l jS \of F Y h:i:s A',$nextupdate);

print($readablenextpagedate);

?>


Output:
1
Monday 25th of May 2015 01:00:00 PM


Create a new paste based on this one


Comments: