Logo         Community
The Company
Your Account
Contact Us
Creating Web Calendars With The PEAR Calendar Class
Need a quick-and-dirty Web calendar? Look no further!

| Building Blocks |

The Calendar class is a PEAR package which provides an API for PHP developers to build date-based applications. It's currently maintained by Harry Fuecks, Lorenzo Alberton  and Greg Beaver, and is freely available from http://pear.php.net/package/Calendar.

The Calendar class works by building object representations of various temporal units. For example, a year is represented by a Year object, which may internally create Month objects. Month objects may themselves spawn Day objects or Week objects. Each of these objects publishes certain methods and properties, which come in handy when developing the user interface - for example, a Month may publish the number of Days it has, while a Day may publish its day number in a Month or position in a Week.

To better understand how this works, consider the following example, which creates a Year and populates it with Months:

// include class

// create and build year data structure
// for 2006
$year = new Calendar_Year(2006);

// display months
while ($month = $year->fetch()) {
    echo $month->thisMonth() .  " ";

This script first creates a Year() object for 2006. It then populates the Year with 12 Month() objects, by calling the Year() object's build() method. Each individual Month can then be retrieved with a call to the Year() object's fetch() method.

The procedure described above holds good for other temporal data structures as well. To create Hours, for example, initialize a Day and then build Hours from it:

// include class

// create and build day data structure
// for 01-Jan-2006
$day = new Calendar_Day(2006, 1, 1);

// display hours of day
while ($hour = $day->fetch()) {
    echo $hour->thisHour() .  ":00 ";

To create Seconds, initialize a Minute and then build Seconds from it:

// include class

// create and build minute data structure
// for 01-Jan-2006 12:41
$minute = new Calendar_Minute(2006, 1, 1, 12, 41);

// display seconds of minute
while ($sec = $minute->fetch()) {
    echo $sec->thisSecond() .  " ";

If you've understood how this works, flip the page, and let's start doing more complicated stuff.

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Caching Web Sites With PEAR Cache
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback