sim.plified.com

Chris Pollock

Chris Pollock - web developer (PHP/mySQL & ASP.NET)
undivided… my thoughts on world, family, church, business, technology and Jesus Christ (all in all)

PHP Date Cueing Logic

For the next release of PatternTap, the images that are approved will be time released into the tap, this will allow for a more smooth delivery of content throughout the day, rather than bulk loading.

The function below take a datetime string (mysql formatted) and then returns the next delivery date.  The idea is that a whenever an item is submitted, it looks at the last item that was cued, get’s it’s time, and feeds it to this function to determine when the next item should be cued.  This function used the logic that items should be cued hourly between the hours of 10am and 5pm on Monday through Friday.  

This logic could easily be updated to accommodate your own needs, let me know if you find any problems or if it helps you solve a problem.

        /**
        *
        *    Description: returns the next time to cue up an item based on the logic:
        *       Every hour between 10am and 5pm, Monday - Friday
        *
        *    Example input value $latest_item = "2009-04-15 17:01:00";
        *
        *   @params $latest_item datetime string
        *
        **/

        function get_cue_time($latest_item)
        {

            $next_item = strtotime($latest_item . " + 1 hour"); 

            if ($next_item < time()) // compare to now
                $next_item = time(); // set to now

            // Before 10 am?
            if (date("H", $next_item) < 10)
            { // set to 10 am
                $next_item = mktime(10, 0, 0,
                                date("n", $next_item), date("j", $next_item), date("Y", $next_item));
            }                

            // After 5pm?
            if (date("H", $next_item) > 17)
            { // set to 10am the next day
                $next_item = mktime(10, 0, 0,
                                date("n", $next_item), date("j", $next_item) + 1, date("Y", $next_item));
            }

            // Saturday Check
            if (date("N", $next_item) == 6)
            { // set to 10am Monday
                $next_item = mktime(10, 0, 0,
                                date("n", $next_item), date("j", $next_item) + 2, date("Y", $next_item));

            }

            // Sunday Check
            if (date("N", $next_item) == 7)
            { // set to 10am Monday
                $next_item = mktime(10, 0, 0,
                                date("n", $next_item), date("j", $next_item) + 1, date("Y", $next_item));

            }

            return date('Y-m-d H:i:s', $next_item);
        }
        
 

No Comments, Comment or Ping

Reply to “PHP Date Cueing Logic”

Things I see

PVC TentPVC TentPVC TentSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland Park

Chris Pollock

Web Developer - proficient in both PHP and ASP.NET.
Rochester, New York

View my web developement site.

View Chris Pollock's LinkedIn profile

My Pictures

PVC TentPVC TentPVC TentSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland ParkSledding at Highland Park