Building a recurring events generator
A very common need related to generating a calendar is the scheduling of events. Events can be in the form of one-off events, which take place on one day, or on a weekend. There is a much greater need, however, to track events that are recurring. We need to account for the start date, the recurring interval (daily, weekly, monthly), and the number of occurrences or a specific end date.
How to do it...
Before anything else, it would be an excellent idea to create a class that represents an event. Ultimately you'll probably end up storing the data in such a class in a database. For this illustration, however, we will simply define the class, and leave the database aspect to your imagination. You will notice that we will use a number of classes included in the
DateTime
extension admirably suited to event generation:namespace Application\I18n; use DateTime; use DatePeriod; use DateInterval; use InvalidArgumentException; class Event { // code }
Next, we...