Author: Dan Thanh
Posted on: 2015-08-31
Package: PHP Sweepstakes
In general, it is an easy problem to solve. However when the events span multiple days and must not occur in holidays, the problem becomes less trival to solve.
Read this article to learn how you can use the PHP Sweepstakes class to compute the days of regular event taking in account these nuances that may complicate the calculations.
Contents
Periodical Events
Events that Take Multiple Days
Time Wrap
Lazy Lists
Exception Dates
Conclusion
Introduction
There are many types of events that are repeated with regular intervals. That is the case of regular publications or contests like sweepstakes. That is why this class is called PHP Sweepstakes.
This article is about using this class to compute the dates of periodical events considering special conditions that make the computations more complicated.
Periodical Events
The package can display the next and previous editions of each of the listed events.
Events that Take Multiple Days
Time Wrap
Time specifications may exceed the 24 hours that each day take. For instance in Europe the time format uses 24:00 hours format. PHP treats 24:00 like I would expect. It should treat 37:00 by wrapping it into 13:00 tomorrow.
This kind of scheduling is seen frequently in radio and TV broadcast schedules, not only in Japan. But strtotime('24:00 today') is 0:00 whereas strtotime('24:00') and strtotime('today 24:00') are 0:00 tomorrow. PHP does not handle any time longer than 24:59:59.9 though.
Lazy Lists
Exception Dates
Conclusion
As you may have read an apparently simple problem of calculation the dates of periodical events may become much more complicated once you need to consider events details like multiple day spans or exception dates like holidays.
On the next part of this article we will see how to use the PHP Sweepstakes package to solve a real world problem.
If you liked this article or have a question about the problem of calculating periodical events, post a comment here.
You need to be a registered user or login to post a comment
1,344,754 PHP developers registered to the PHP Classes site.
Be One of Us!
Login Immediately with your account on:
Comments:
1. When is the next part?? - Paul Okeke (2015-08-31 04:00)
Sounds good ... When will we see an example?... - 1 reply
Read the whole comment and replies