Home » Date and Time » Calendar » Manual
Calendar Data Structures This chapter describes how to use PEAR::Calendar
Introduction
Introduction – What Calendar can do
Introduction
Some classes in PEAR::Calendar require PEAR::Date be installed. The PEAR::Date 1.3.1beta is missing a file and will not work. Make sure you have PEAR::Date version 1.4 or newer installed.
PEAR::Calendar is a package for generating Calendars as data structures. It does not render content or rely on any underlying data store, allowing it to be applied to many problem domains. At the same time it provides an easy to use API that makes rendering, for example, an HTML calendar very easy, while making it possible to "connect" the calendar with your data store.
PEAR::Calendar was developed as a result of finding no alternatives out there in PHP. There are numerous public domain calendar utilities / classes out there but all are tied to a specific output format (typically HTML with limited ability to customize without re-writing code) and often dependent on pre-built data structures stored in a database (read MySQL). This poses significant restrictions on the problem domains they can be applied to. By contrast PEAR::Calendar focuses on eliminating the math from the task of generating a calendar, allowing the end user to simply iterate over a prepared data structure.
Some of the benefits / features of PEAR::Calendar include:
- You can render whatever output you like (e.g. (X)HTML, WML, SOAP, XML-RPC, command line ASCII or whatever).
- Generating a calendar is much like looping through the results of a database query.
- Representations of all "date objects" from a Year down to a Second (e.g. you can equally render a complete yearly calendar with months and days or a "Weekly / Daily Diary")
- Allows "tabular" calendars to be generated easily.
- Any date can be easily validated (is 29th Feb 2003 valid?).
- Performs well despite number crunching and object oriented API.
- Calendars can be easily navigated (e.g. providing a link from 1st Jan 2004 to 31st Dec 2003 is no problem).
- It returns numeric values for all operations, meaning you are not tied to using, say, English names for months. Typically you would generate these yourself with PHP functions like strftime() and setlocale().
- Representations of a date can be obtained as a human readable number or in the form of a timestamp (e.g. Unix Timestamp), depending on the calendar engine you are using.
- You can attach your own functionality to the calendar by creating Decorators.
- Allows you to write layered, N-Tier applications.
- The calendar "calculation engine" is abstracted meaning you are not tied to a Gregorian calendar - you could write a Tolkien calendar should you wish. Currently "engines" based on Unixtimestamps (the default) and PEAR::Date have been implemented.
A Simple Example
<?php
require_once 'Calendar/Month.php';
$Month = new Calendar_Month(2003, 10); // October 2003
$Month->build(); // Build the days in the month
// Loop through the days...
while ($Day = $Month->fetch()) {
echo $Day->thisDay().'<br />';
}
?>
Note: there are numerous and extensive examples provided with the PEAR::Calendar package file.
Installing
Installing – How to install PEAR::Calendar
Installing
- If not already installed, setup the PEAR package manager.
- Type pear install Calendar-beta (using the command line manager)
- PEAR::Calendar is now installed.
In A Hurry
In A Hurry – Just add hot water...
In A Hurry
<?php
require_once 'Calendar/Month/Weekdays.php';
$Month = new Calendar_Month_Weekdays(date('Y'), date('n'));
$Month->build();
echo "<table>\n";
while ($Day = $Month->fetch()) {
if ($Day->isFirst()) {
echo "<tr>\n";
}
if ($Day->isEmpty()) {
echo "<td> </td>\n";
} else {
echo '<td>'.$Day->thisDay()."</td>\n";
}
if ($Day->isLast()) {
echo "</tr>\n";
}
}
echo "</table>\n";
?>
Package Overview
Package Overview – Summary of Calendar Classes
Package Overview
When working with PEAR::Calendar, there are a total of 12 (public) classes available for you to use, depending on the particular problem you are trying to solve. They can be grouped in date classes, tabular date classes, validation classes and decorators.
Date Classes
Providing representations of all basic human date units. All are subclasses of Calendar so provide the methods defined there.
-
Calendar_Year - represents a year and can build Calendar_Month, Calendar_Month_Weekdays and Calendar_Month_Weeks objects.
Include with
.<?php require_once 'Calendar/Year.php'; ?> -
Calendar_Month - represents a month and can build Calendar_Day objects.
Include with
.<?php require_once 'Calendar/Month.php'; ?> -
Calendar_Day - represents a day and can build Calendar_Hour objects.
Include with
.<?php require_once 'Calendar/Day.php'; ?> -
Calendar_Hour - represents a hour and can build Calendar_Minute objects.
Include with
.<?php require_once 'Calendar/Hour.php'; ?> -
Calendar_Minute - represents a minute and can build Calendar_Second objects.
Include with
.<?php require_once 'Calendar/Minute.php'; ?> -
Calendar_Second - represents a second but cannot build anything.
Include with
.<?php require_once 'Calendar/Second.php'; ?>
Tabular Date Classes
Designed for building calendars in tabular format. All are subclasses of Calendar so provide the methods defined there.
-
Calendar_Month_Weekdays - builds Calendar_Day objects setting the isFirst(), isLast() and isEmpty() states, to display a month in tabular form.
Include with
.<?php require_once 'Calendar/Month/Weekdays.php'; ?> -
Calendar_Month_Weeks - builds Calendar_Week objects, representing a month in terms of the tabular weeks it contains (see FAQ for what a week represents).
Include with
.<?php require_once 'Calendar/Month/Weeks.php'; ?> -
Calendar_Week - builds a collection of seven Calendar_Day objects. If extended by a Calendar_Month_Weeks object, it represents a tabular week in a month and it sets the isEmpty() state for the appropriate days, if necessary.
Include with
.<?php require_once 'Calendar/Week.php'; ?>
Validation Classes
Used to validate dates. Calendar provides the methods isValid() to perform a simple check on any date and getValidator() to return an instance of Calendar_Validator for fine grained validation.
- Calendar_Validator - is not instantiated by your code directly (you need need specifically include / create it) but instead returned from the Calendar::getValidator() method you can call on any subclass of Calendar. It is used to provide fine grained validation of a date to find out exactly what's wrong with it (for simple validation just call isValid() on any Date object or Tabular Date object, to know if it was created with valid values.
- Calendar_Validation_Error - represents a validation error, providing methods to determine what went wrong. Available methods are getUnit() (e.g. returns Year or Month), getValue() (the value it failed with), getMessage() (the validation error message) and toString() which returns a combination of all the three preceding methods. The default validation error messages are in English but stored in the constants CALENDAR_VALUE_TOOSMALL and CALENDAR_VALUE_TOOLARGE which you can redefine in your code.
Decorators
Provide a mechanism to add functionality to the main calendar objects (the subclasses of Calendar) without needing to directly extend them (and risk overwriting fields accidentally). When you create a decorator, you pass its constructor an instance of an existing calendar object. You can then make calls to the decorator in exactly the same way as you make calls to the original calendar object. This allows you to "overwrite" calendar methods, add new methods or even apply multiple decorators to the same calendar object. Decorators a typically either "injected" (via selection or the Calendar_Decorator_Wrapper decorator) into the loop where the calendar is rendered and / or to alter the output content (e.g. convert a numeric month into a textual month: 1 => January).
PEAR::Calendar provides some decorator implementations for you, to help with common tasks. These are not designed to suit everyone and hence are provided as optional code for you to use as needed (avoiding the performance cost associated with parsing code you're not using).
-
Calendar_Decorator - this is the base decorator class which you should extend with your own. It provides the same API as the calendar object it is decorating, and simply routes calls through to it. Example;
<?php require_once 'Calendar/Decorator.php'; class ChristmasDecorator extends Calendar_Decorator { function ChristmasDecorator(&$Calendar) { parent::Calendar_Decorator($Calendar); } // Some method I've added function getDaysToChristmas() { $today = parent::thisDay(true); $Christmas = new Calendar_Day(date('Y'), 12, 25); $xmasday = $Christmas->thisDay(TRUE); $diff = $xmasday - $today; if ($diff < 0) { $NextChristmas = new Calendar_Day($Christmas->nextYear(), 12, 25); $nextxmasday = $NextChristmas->thisDay(true); $diff = $today - $nextxmasday; } return ($diff / 86400); } } ?> -
Calendar_Decorator_Uri - provides a decorator to help with generating URLs (for example next / prev URLs).
Include with
.<?php require_once 'Calendar/Decorator/Uri.php'; ?> -
Calendar_Decorator_Textual - helps with obtaining textual month names and weekday names from a calendar object.
Include with
.<?php require_once 'Calendar/Decorator/Textual.php'; ?> -
Calendar_Decorator_Wrapper - is intended to help you add decorators to the children of the calendar object you are working with. It will wrap the children in the decorator you specify at the point fetch() or fetchAll() is called, after a build build() call.
Include with
.<?php require_once 'Calendar/Decorator/Wrapper.php'; ?>
Method Overview
Method Overview – Summary of Calendar API
Method Overview
For the main Calendar classes (the subclasses of Calendar) all share a common API (a common set of class methods). Although there are some minor variations in specific cases, you should find it intuitive and easy to remember, once you are familiar with what's available. This section summarizes the common methods and highlights the variations. For further information, consult the API documentation.
Constructors
The constructors of the Date classes accept integer date values as their arguments, beginning with the year (on the left) across to the second (on the right), depending on what class you're using, for example;
<?php
// Natural Calendar Classes
$Year = new Calendar_Year(2003); // 2003
$Month = new Calendar_Month(2003, 10); // October 2003
$Day = new Calendar_Day(2003, 10, 25); // 25th October 2003
$Hour = new Calendar_Hour(2003, 10, 25, 13); // 25th October 2003 13:00:00
$Minute = new Calendar_Minute(2003, 10, 25, 13, 31); // 25th October 2003 13:31:00
$Second = new Calendar_Second(2003, 10, 25, 13, 31, 45); // 25th October 2003 13:31:45
// Tabular Calendar Classes
$Month = new Calendar_Month_Weekdays(2003, 10); // October 2003
$Month = new Calendar_Month_Weeks(2003, 10); // October 2003
$Week = new Calendar_Week(2003, 10, 25); // week containing 25th October 2003
?>Note that the tabular classes, Calendar_Month_Weekdays and Calendar_Month_Weeks both take an optional third argument (integer) which specifies the first day of the week and adjust tabular display (normally it defaults to Monday (1) - pass the integer value 0 to switch to Sunday as the first day, for example). Calendar_Week accepts the first day argument as the fourth to its constructor.
Location Methods
All date and tabular date classes share the methods defined in the abstract base class Calendar. Among these are methods for an object of any of these classes to identify itself (what's its date is) and the previous and next dates. For example;
<?php
// Create a day
$Day = new Calendar_Day(2003, 10, 1); // 1st October 2003
echo $Day->thisDay(); // Displays 1
echo $Day->prevDay(); // Displays 30 (the 30th of September)
echo $Day->nextDay(); // Displays 2
echo $Day->thisMonth(); // Displays 10
echo $Day->prevMonth(); // Displays 9
echo $Day->nextMonth(); // Displays 11
?>Notice that from the $Day I can find out not just about the day itself but also the month (or year/hour/minute/second). Notice also how prevDay() returned 30, taking care of working out that the previous day is in September for you. There are this***(), prev***() and next***() methods for years, months, days, hours, minutes and seconds.
Calling any of these methods and passing the value TRUE will result in a timestamp being returned (the type of timestamp depends on the Calendar Engine you are using - see the FAQ), for example;
<?php
// Create a second
$Second = new Calendar_Second(2003, 10, 25, 13, 32, 44);
echo $Second->thisYear(TRUE); // Displays 1041375600
echo $Second->thisMonth(TRUE); // Displays 1064959200
echo $Second->thisDay(TRUE); // Displays 1067032800
echo $Second->thisHour(TRUE); // Displays 1067079600
echo $Second->thisMinute(TRUE); // Displays 1067081520
echo $Second->thisSecond(TRUE); // Displays 1067081564
?>Notice how the timestamp return increases, depending on the method that was called to obtain it. The first, obtained from thisYear(TRUE)() is a timestamp for the beginning of the year 2003 (1st January 2003 in fact) while the third from thisDay(TRUE)() is a timestamp for 25th October 2003.
The prev***() and next***() methods return values calculated relative to the current Calendar object you are working with. In the above example, if you wanted the day and month of the next day (which should be 2nd October 2003), calling nextDay() then nextMonth() would give you the 2nd of November not October. Instead you should call nextDay() passing it the argument TRUE, to get back a timestamp from which the next day can be obtained. Be aware of the Calendar_Decorator_Uri which is designed to help build URLs for next / prev links.
There are also the methods thisWeek(), prevWeek() and nextWeek() which only become available if you're using an instance of Calendar_Week. The returned value format can be chosen among 'timestamp', 'n_in_month', 'n_in_year' or 'array'. Be careful - if you select 'n_in_month', it will return NULL if it reaches the beginning or end of a month.
Finally all Calendar objects provide the methods getTimeStamp() and setTimeStamp(). The former returns a timestamp in the format used by the calendar engine you are working with (i.e. Unix Timestamp if it's the default UnixTs engine or of format YYYY-MM-DD HH:MM:SS). The later excepts a timestamp which is used to replace the values the Calendar object was constructed with.
Building and Fetching
Every date and tabular date class has a build() method which is used to generate the children of that date object. For example Calendar_Month builds Calendar_Day objects, the days being "children" of the month.
Once build() is called, the children can be fetched from the date object using the simple fetch() iterator, for example;
<?php
$Month = new Calendar_Month(2003, 10);
$Month->build();
while ($Day = $Month->fetch()) {
echo $Day->thisDay()."<br />\n";
}
?>The fetch() method returns one child at a time, in ascending date order, and returns FALSE when there are no more children. It also automatically resets the internal collection of children, meaning you can loop over them as many times as you like.
If you don't like the iterator, and wish to use your own, you can simply extract the children with the fetchAll() method (returns an indexed array of child date objects) and check the number you got back with size(). Be careful the index of the array you get back from fetchAll(). For Calendar_Year, Calendar_Month, Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week, the first index of the array is 1 while for Calendar_Day, Calendar_Hour, Calendar_Minute and Calendar_Second the index begins with 0. Why? Consider 2003-1-1 00:00:00 ...
Note: Calendar_Second::build() doesn't do anything - it has no children.
Selecting Children
To help with rendering the calendar, the build() methods accept an index array of date objects which is compares with the children it is building. If it finds that an object that was passed to it matches a child, it set's the childs state to selected, meaning the isSelected() method (available on any date or tabular date objects) returns TRUE. For example;
<?php
$Month = new Calendar_Month(2003, 10);
$DayX = new Calendar_Day(2003, 10, 15);
$DayY = new Calendar_Day(2003, 10, 23);
$selection = array($DayX, $DayY);
$Month->build($selection);
while ($Day = $Month->fetch()) {
if ($Day->isSelected()) {
echo $Day->thisDay()."<br />\n"; // Displays 15 or 23
}
}
?>In the above example, only 15th October 2003 and 23rd October 2003 are displayed.
The objects you pass to build() which match children that are being built replace the child (i.e. if there was a match, you get your object back). This allows you to "inject" your own objects into the loop, best accomplished by extending Calendar_Decorator.
Note: the Calendar_Year::build() method takes a second argument to specify the first day of the week (see above discussion on Constructors).
Tabular Days
The Calendar_Day class has three unique methods, which don't appear elsewhere, and are used purely for building tabular calendars. The isEmpty() is used to determine whether the day is an empty day or not (see FAQ for explaination of empty days). The methods isFirst() and isLast() are used to mark the beginning and and of a week.
Whether you need to use these methods depends on which class was used to build the day objects. If the day was built with Calendar_Month_Weekdays, all three of these methods are applicable (you may have empty days and Calendar_Month_Weekdays builts a complete month but delimits the beginning and end of each week so you can find it with isFirst() and isLast()). If the day was built with Calendar_Week, only the isEmpty() method is applicable (the first or last week in a month may contain empty days). For day objects built in any other manner, isEmpty(), isFirst() and isLast() are meaningless.
Validation
All date objects and tabular objects (except weeks) are capable of validating themselves. By default they accept whatever arguments they are given on construction but you can validate the date with the isValid() method, for example;
<?php
$Day = new Calendar_Day(2003, 10, 32);
if (!$Day->isValid()) {
die ('Invalid date');
}
?>For more fine grained validation, you can first call the getValidator() method, to return an instance of Calendar_Validator then list the validation errors;
<?php
$Day = new Calendar_Day(2003, 10, 32);
if (!$Day->isValid()) {
$Validator = & $Day->getValidator();
while ($Error = $Validator->fetch()) {
echo $Error->getUnit().' is invalid<br>';
}
}
?>or...
<?php
$Day = new Calendar_Day(2003, 10, 32);
$Validator = & $Day->getValidator();
if (!$Validator->isValid()) {
while ($Error = $Validator->fetch()) {
echo $Error->toString().'<br>';
}
}
?>
Note that rather than validating dates, you may prefer to automatically adjust them with the adjust() method, for example;
<?php
$Day = new Calendar_Day(2003, 10, 32);
$Day->adjust();
echo $Day->thisYear(); // 2003
echo $Day->thisMonth(); // 11 (moved forward a month)
echo $Day->thisDay(); // 1 (the first of the month)
?>
That summarizes all the methods available within PEAR::Calendar, apart from the those provided in the Decorator classes.
Calendar Decorators
Calendar Decorators – What Calendar_Decorator is for
Calendar Decorators
The Calendar_Decorator is provided to allow you to attach functionality to existing Calendar objects without needing to subclass them. This helps in a number of situations, such as allowing results from, say, a database query to be rendered in the calendar or to modify the values returned from Calendar methods (perhaps converting a numeric month into its textual name).
Some concrete decorators are provided with PEAR::Calendar, to address what may be common problems you encounter in using the library. These are not designed to suit everyone but instead focus on solving a more narrow problem domain. They will only be parsed by the PHP engine should you explicitly include them in your code. An example of why decorators can be useful:
<?php
require_once 'Calendar/Day.php';
require_once 'Calendar/Decorator.php';
class WorkingDay extends Calendar_Decorator {
function WorkingDay(& $Calendar) {
parent::Calendar_Decorator($Calendar);
}
// Overides the default fetch method of the calendar object
function fetch() {
if ($Hour = parent::fetch()) {
// Recursive fetch, return only hours between 8am and 6pm
if ($Hour->thisHour() < 8 || $Hour->thisHour() > 18) {
return $this->fetch();
} else {
return $Hour;
}
} else {
// Make sure to return FALSE when the real fetch returned nothing
// or you will get an infinite loop
return FALSE;
}
}
}
// Create a normal day and build the hours
$Day = new Calendar_Day(date('Y'), date('n'), date('d'));
$Day->build();
// Create the decorator, passing it the normal day
$WorkingDay = new WorkingDay($Day);
// Only hours in a working day are displayed...
while ($Hour = $WorkingDay->fetch()) {
echo $Hour->thisHour().'<br />';
}
?>
The base Calendar_Decorator
The base class Calendar_Decorator "mirrors" the combined API of all the subclasses of Calendar. It accepts a Calendar object to its constructor then "takes over" the API allowing you to make calls through it rather than directly to the original calendar object. The Calendar_Decorator simply routes calls through to the calendar object it is decorating and returns values where appropriate.
Decorators and Date Selection
One important use of decorators is to help "inject" data into the loop which renders the calendar. This helps with fetching data from some sort of "event" table in a database. When passing a selection array to any build() method, the selected date objects will replace the default built objects, allowing you to get them back as inside the fetch() loop, using the isSelected() method. You'll find an example of this in the PEAR::Calendar download. It should always be possible to fetch the event data you need with a single database query...
The bundled Decorators
PEAR::Calendar already provides a few decorators:
- Calendar_Decorator_Textual Decorator to help with fetching textual representations of months and days of the week. It has
- Calendar_Decorator_Uri Decorator to help with building HTML links for navigating the calendar.
- Calendar_Decorator_Weekday Decorator for fetching the day of the week.
- Calendar_Decorator_Wrapper Decorator to help with wrapping built children in another decorator.
Calendar_Decorator_Textual example
This decorator defines a few methods that can be useful to handle month and day names:
-
monthNames(
$format='long') Returns an array with month names; the format of returned months depends on theformatparameter (one, two, short or long) -
weekdayNames(
$format='long') Returns an array with day names; the format of returned days depends on theformatparameter (one, two, short or long) -
prevMonthName(
$format='long') Returns textual representation of the previous month of the decorated calendar object -
thisMonthName(
$format='long') Returns textual representation of the month of the decorated calendar object -
nextMonthName(
$format='long') Returns textual representation of the next month of the decorated calendar object -
prevDayName(
$format='long') Returns textual representation of the previous day of the decorated calendar object -
thisDayName(
$format='long') Returns textual representation of the day of the decorated calendar object -
nextDayName(
$format='long') Returns textual representation of the next day of the decorated calendar object -
orderedWeekdays(
$format='long') Returns the days of the week using the order defined in the decorated calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week. Otherwise the returned array will begin on Sunday.
Calendar_Decorator_Uri example
Methods defined by this decorator:
- setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) Set the names of the URI vars for each date element
-
setSeparator(
$separator) Set the fragments separator, for instance '/' (default: &). -
setScalar(boolean
$state=TRUE) Puts Uri decorator into "scalar mode" - URI variable names are not returned -
prev(
$method) Gets the URI string for the previous calendar unit (year, month, week or day etc) -
this(
$method) Gets the URI string for the current calendar unit (year, month, week or day etc) -
next(
$method) Gets the URI string for the next calendar unit (year, month, week or day etc)
A simple usage example:
<?php
$Day = new Calendar_Day(2003, 10, 23);
$Uri = & new Calendar_Decorator_Uri($Day);
$Uri->setFragments('year', 'month', 'day');
echo $Uri->prev('day');
// Displays year=2003&month=10&day=22
?>
Calendar_Decorator_Weekday example
Methods defined by this decorator:
- setFirstDay($firstDay) Sets the first day of the week (0 = Sunday, 1 = Monday [default] etc)
-
prevWeekDay($format='int')
Returns the previous weekday, formatted according the
$formatparameter (int, array, object, timestamp) -
thisWeekDay($format='int')
Returns the current weekday, formatted according the
$formatparameter (int, array, object, timestamp) -
nextWeekDay($format='int')
Returns the next weekday, formatted according the
$formatparameter (int, array, object, timestamp)
Example:
<?php
$Day = new Calendar_Day(2003, 10, 23);
$Weekday = & new Calendar_Decorator_Weekday($Day);
$Weekday->setFirstDay(0); // Set first day of week to Sunday (default Mon)
echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun
?>
Calendar_Decorator_Wrapper example
<?php
require_once 'Calendar/Month.php';
require_once 'Calendar/Decorator.php'; // Not really needed but added to help this make sense
require_once 'Calendar/Decorator/Wrapper.php';
class MyBoldDecorator extends Calendar_Decorator
{
function MyBoldDecorator(&$Calendar)
{
parent::Calendar_Decorator($Calendar);
}
function thisDay()
{
return '<b>'.parent::thisDay().'</b>';
}
}
$Month = new Calendar_Month(date('Y'), date('n'));
$Wrapper = & new Calendar_Decorator_Wrapper($Month);
$Wrapper->build();
echo '<h2>The Wrapper decorator</h2>';
echo '<i>Day numbers are rendered in bold</i><br /> <br />';
while ($DecoratedDay = $Wrapper->fetch('MyBoldDecorator')) {
echo $DecoratedDay->thisDay().'<br />';
}
?>
FAQ
FAQ – Frequently Asked Questions
Why doesn't it generate HTML?
What if you want WML, SOAP, PDF, GIF, command line, etc. etc.? PEAR::Calendar can be used to generate any output format you like (see the examples for SOAP and WML). Tying it to a particular output content type will limit its use (a problem that every public domain PHP Calendar library I've looked at suffers from). A PEAR::HTML_Calendar is likely to be developed using PEAR::Calendar.
There are too many objects, classes and files. It's bloated!
Running the examples on Sourceforge's servers (which are always overloaded), example 3.php renders in under 0.1 seconds (usually half that). The code is highly optimized and every "trick in the book" has been applied to make sure PHP only parses / executes the subset of logic you need for your specific problem. If in doubt, use Cache_Lite to cache the output HTML.
You use Unix timestamps to calculate the Calendar, which limits the range of years it can generate. Can this be changed?
All calculations are handled by a class implementing the Calendar_Engine interface. The default implemention is based on PHP's date() and mktime() functions (so Unix timestamps are required for that engine). A second engine exists which uses PEAR::Date. It's a bit slower but overcomes the limit on the range of Unixstamps. To switch between engines use the constant CALENDAR_ENGINE e.g.
<?php
// The default Unix timestamp engine (this definition is not required)
// define('CALENDAR_ENGINE', 'UnixTs');
// Switch to PEAR::Date engine
define('CALENDAR_ENGINE', 'PearDate');
?>Note that the PearDate engine is based on PEAR::Date version 1.4 or newer.
This examples use the English language for days and months. Can this be changed?
PEAR::Calendar only uses base 10 numbers for calculations - the names of months and days of the week and generated as the calendar is being rendered (by you). You should only need to change PHP's locale with setlocale() and use the strftime() function e.g.:
<?php
$Day = & new Calendar_Day(2003, 10, 23);
setlocale (LC_TIME, 'de_DE'); // German
echo strftime('%A %d %B %Y', $Day->getTimeStamp());
?>Note that Calendar_Decorator_Textual provides help in generating month and day of week names in a manner which is independent of the Calendar Engine you are using and can be modified with setlocale().
What are empty days?
PEAR::Calendar makes it easy to render calendars in tabular format (like humans are used to) such as:
October 2003
M T W T F S S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Notice the top left and botton right of this example - these are "empty days". Empty days are generated only by two calendar classes: Calendar_Month_Weekdays and Calendar_Week. For example using Calendar_Month_Weekdays;
<?php
require_once 'Calendar/Month/Weekdays.php';
$Month = & new Calendar_Month_Weekdays(2003, 10);
$Month->build();
while ($Day = & $Month->fetch()) {
if ($Day->isFirst()) // Check for the start of a week
echo "\n";
if ($Day->isEmpty()) // Check to see if day is empty
echo "\t";
else
echo $Day->thisDay()."\t";
if ($Day->isLast()) // Check for the end of a week
echo "\n";
}
?>An empty day can still return values, the date it represents being from the previous or next month in the calendar. You may get empty days for Calendar_Month_Weekdays and Calendar_Week. Using Calendar_Week, you will only build 7 days (use Calendar_Month_Weeks to build Calendar_Week objects), so the isFirst() and isLast() methods are not applicable.
How do I select some dates?
All calendar objects (except Calendar_Second, which has no "children") have the method build() to build the "children" of that object. For example Calendar_Year::build() builds Calendar_Month objects while Calendar_Hour::build() builds Calendar_Minute objects. You have the option of passing this method an indexed array of Calendar objects which will be used to "select" the matching built children. For example:
<?php
$Month = & new Calendar_Month(2003, 10); // Oct 2003
$SelectedDay1 = & new Calendar_Day(2003, 10, 5); // Oct 5th 2003
$SelectedDay2 = & new Calendar_Day(2003, 10, 21); // Oct 21st 2003
// Place in an array...
$selection = array($SelectedDay1, $SelectedDay2);
$Month->build($selection);
while ($Day = & $Month->fetch()) {
if ($Day->isSelected())
echo $Day->thisYear().' '.$Day->thisMonth().' '.$Day->thisDay().' is selected'."\n";
}
?>
Note: the date objects you pass to a build() method replace the corresponding built date objects, allowing you to do things like attach your own subclass of Calendar_Decorator to them, then access the decorating functionality inside the loop which renders the calendar. You might display the contents from an "events database table" using this approach.
Why do I have to call build() explicitly. Why can't children be built automatically?
First and foremost, for performance. Building the children has a performance cost and you won't always need to have the children, so it should be called explicitly, otherwise you might have $Year->build(), expecting to get just months but behind the scenes, months built days, which built hours, which build minutes etc. Also calling build() yourself give you a chance to "select" some of the children.
How do I validate a date?
Validity is determined by the Calendar_Engine being used as well as the time the date object you're working with represents (e.g. $Month = & new Month(2003, 2, 29); is invalid, because Feb 2003 was not a leap year). For quick validation, you can call the method isValid() on any date object, which will return FALSE if there's a problem. For more information of more detailed validation, you can call the method getValidator() on any date object, which returns an instance of the class Calendar_Validator. For example;
<?php
$Month = & new Month(2003, 2, 29); // 29th Feb 2003 (?!?)
if (!$Month->isValid()) {
$Validator = & $Month->getValidator();
while ($Error = $Validator->fetch()) {
echo $Error->toString();
}
}
?>You can also begin validation by calling getValidator() then either isValidYear(), isValidMonth(), isValidDay(), isValidHour(), isValidMinute() and isValidSecond() (or just isValid() which calls all of the isValidxxx methods).
Can I adjust invalid dates?
If you're allowing end users to navigate your calendar via the URL, were they to modify the URL to something like calendar.php?year=2003&month=13, instead of throwing a validation error at them, you could call the Calendar::adjust() method on the calendar object you create with that URL. You should then end up with January 2004 (in this example). This behaviour is possible thanks to mktime() for the Unix Timestamp engine, while being built into the PearDate engine for you.
After calling build(), I just want to get a single child date object without looping through the lot. How?
The method fetchAll() can be called on any date object to get an indexed array of all the children which have been built, allowing you to reference them directly. Be careful with the first index of this array - in some cases it will be [1] not [0], depending on the type of date object built. For example;
<?php
$Month = & new Calendar_Month(2003, 10);
$Month->build();
$days = & $Month->fetchAll(); // Now all in array
echo $days[1]->thisDay(); // The first day has index 1
$Hour = & new Calendar_Hour(2003, 10, 25, 15); // Oct 25th 2003, 3pm
$Hour->build();
$hours = & $Hour->fetchAll(); // Now all in array
echo $hours[0]->thisHour(); // The first hour has index 0
?>The following classes are always built to have the first index as 1: Calendar_Month, Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week and Calendar_Day The following classes are always built to have the first index as 0: Calendar_Hour, Calendar_Minute and Calendar_Second Note also the method size() can be called on any date object, after build() has been called, to get the number of children.
What does a week actually represent in PEAR::Calendar?
Weeks are "pseudo" dates. They're useful for formatting the user interface for end users. Weeks are instantiated with a year, a month and a day of the month. You can then have the week tell you its timestamp (which will be the same as the timestamp for the first day in the week), its numeric position within the tabular month (see empty days above), its numeric position within the year (this is an ISO-8601 week number of year, weeks starting on Monday) or an array containing the numeric year, month and the first day of the week (as a number within the month). For example:
<?php
$Week = & new Calendar_Week(2003, 10, 15);
$Week = new Calendar_Week(2003, 10, 15);
echo $Week->thisWeek(); // Displays 2 (week num in month)
echo $Week->thisWeek('n_in_month'); // Display 2 - same as above
echo $Week->thisWeek('n_in_year'); // Displays 41 (week in year)
echo $Week->thisWeek('timestamp'); // Displays unix timestamp or an ISO-8601 datetime
// (YYYY-MM-DD HH:MM:SS), depending on the engine.
print_r $Week->thisWeek('array'); // [year] => 2003 [month] => 10 [day] => 12
?>
How do I get a Calendar_Year to build Calendar_Month_Weekdays or Calendar_Month_Weeks, instead of the default Calendar_Month objects?
When working with a Calendar_Year, the constants CALENDAR_MONTH_STATE controls what type of month object is built. You can define CALENDAR_MONTH_STATE to CALENDAR_USE_MONTH_WEEKDAYS or CALENDAR_USE_MONTH_WEEKS for the Calendar_Month_Weekdays and Calendar_Month_Week classes, respectively.
You use Monday as the start of the week. Can I change that?
Yes. For the classes which are concerned with the notion of a "week", you can can pass a value which defines the first day of the week. For the default timestamp based Calendar engine, this is a number from 0 to 6, 0 being Sunday through to 6 being Saturday. This value can be passed to the following:
<?php
$Year = new Calendar_Year(2003);
$selection = array();
$Year->build($selection, 0); // the second argument is the first day of the week (Sunday)
$MonthWeekdays = new Calendar_Month_Weekdays(2003, 10, 6); // Third argument - Saturday
$MonthWeeks = new Calendar_Month_Weekdays(2003, 10, 2); // Third argument - Tuesday
$Week = new Calendar_Week(2003, 10, 15, 5) // Fourth argument - Friday
?>
Calendar
Calendar – Calendar base class
Description
Calendar API.
constructor Calendar::Calendar
constructor Calendar::Calendar() – Constructs the Calendar
Synopsis
require_once 'Calendar.php';
void constructor Calendar::Calendar (
int $y = 2000
, int $m = 1
, int $d = 1
, int $h = 0
, int $i = 0
, int $s = 0
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year
-
integer
$m -
month
-
integer
$d -
day
-
integer
$h -
hour
-
integer
$i -
minute
-
integer
$s -
second
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::adjust
Calendar::adjust() – Adjusts the date (helper method)
Synopsis
require_once 'Calendar.php';
void Calendar::adjust (
)
Description
Helper method. You can adjust calling object's date just like mktime does. For instance, (2003, 11, -1) will be translated to (2003, 10, 31). This method allows math operations on dates.
Note
This function can not be called statically.
Calendar::build
Calendar::build() – Abstract method for building the children of a calendar object.
Synopsis
require_once 'Calendar.php';
boolean Calendar::build (
array $sDates = array()
)
Description
Implemented by Calendar subclasses
Parameter
-
array
$sDates -
containing Calendar objects to select (optional)
abstract
Note
This function can not be called statically.
Calendar::fetch
Calendar::fetch() – Iterator method for fetching child Calendar subclass objects (e.g. a minute from an hour object). On reaching the end of the collection, returns false and resets the collection for further iteratations.
Synopsis
require_once 'Calendar.php';
mixed Calendar::fetch (
)
Description
This package is not documented yet.
Return value
returns either an object subclass of Calendar or false
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::fetchAll
Calendar::fetchAll() – Fetches all child from the current collection of children
Synopsis
require_once 'Calendar.php';
array Calendar::fetchAll (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::getTimestamp
Calendar::getTimestamp() – Returns a timestamp from the current date / time values
Synopsis
require_once 'Calendar.php';
int Calendar::getTimestamp (
)
Description
Format of timestamp depends on Calendar_Engine implementation being used
Return value
returns timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::getValidator
Calendar::getValidator() – Returns an instance of Calendar_Validator
Synopsis
require_once 'Calendar.php';
Calendar_Validator& Calendar::getValidator (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::isSelected
Calendar::isSelected() – True if the calendar subclass object is selected (e.g. today)
Synopsis
require_once 'Calendar.php';
boolean Calendar::isSelected (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::isValid
Calendar::isValid() – Determine whether this date is valid
Synopsis
require_once 'Calendar.php';
boolean Calendar::isValid (
)
Description
Determine whether this date is valid with the bounds determined by the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::nextDay
Calendar::nextDay() – Returns the value for the next day
Synopsis
require_once 'Calendar.php';
int Calendar::nextDay (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 12 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::nextHour
Calendar::nextHour() – Returns the value for the next hour
Synopsis
require_once 'Calendar.php';
int Calendar::nextHour (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 14 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::nextMinute
Calendar::nextMinute() – Returns the value for the next minute
Synopsis
require_once 'Calendar.php';
int Calendar::nextMinute (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 25 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::nextMonth
Calendar::nextMonth() – Returns the value for next month
Synopsis
require_once 'Calendar.php';
int Calendar::nextMonth (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 6 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::nextSecond
Calendar::nextSecond() – Returns the value for the next second
Synopsis
require_once 'Calendar.php';
int Calendar::nextSecond (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 45 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::nextYear
Calendar::nextYear() – Returns the value for next year
Synopsis
require_once 'Calendar.php';
int Calendar::nextYear (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 2004 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::prevDay
Calendar::prevDay() – Returns the value for the previous day
Synopsis
require_once 'Calendar.php';
int Calendar::prevDay (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 10 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::prevHour
Calendar::prevHour() – Returns the value for the previous hour
Synopsis
require_once 'Calendar.php';
int Calendar::prevHour (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 13 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::prevMinute
Calendar::prevMinute() – Returns the value for the previous minute
Synopsis
require_once 'Calendar.php';
int Calendar::prevMinute (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 23 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::prevMonth
Calendar::prevMonth() – Returns the value for the previous month
Synopsis
require_once 'Calendar.php';
int Calendar::prevMonth (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 4 or Unix timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::prevSecond
Calendar::prevSecond() – Returns the value for the previous second
Synopsis
require_once 'Calendar.php';
int Calendar::prevSecond (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 43 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::prevYear
Calendar::prevYear() – Returns the value for the previous year
Synopsis
require_once 'Calendar.php';
int Calendar::prevYear (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 2002 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::setSelected
Calendar::setSelected() – Defines calendar object as selected (e.g. for today)
Synopsis
require_once 'Calendar.php';
void Calendar::setSelected (
boolean $state
= true
)
Description
This package is not documented yet.
Parameter
-
boolean
$state -
state whether Calendar subclass
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::setSelection
Calendar::setSelection() – Abstract method for selected data objects called from build
Synopsis
require_once 'Calendar.php';
boolean Calendar::setSelection (
array $sDates
)
Description
This package is not documented yet.
Parameter
-
array
$sDates
abstract
Note
This function can not be called statically.
Calendar::setTimestamp
Calendar::setTimestamp() – Defines the calendar by a Unix timestamp
Synopsis
require_once 'Calendar.php';
void Calendar::setTimestamp (
int $ts
)
Description
Defines the calendar by a Unix timestamp, replacing values passed to the constructor
Parameter
-
integer
$ts -
Unix timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::size
Calendar::size() – Get the number Calendar subclass objects stored in the internal collection.
Synopsis
require_once 'Calendar.php';
int Calendar::size (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::thisDay
Calendar::thisDay() – Returns the value for this day
Synopsis
require_once 'Calendar.php';
int Calendar::thisDay (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 11 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::thisHour
Calendar::thisHour() – Returns the value for this hour
Synopsis
require_once 'Calendar.php';
int Calendar::thisHour (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 14 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::thisMinute
Calendar::thisMinute() – Returns the value for this minute
Synopsis
require_once 'Calendar.php';
int Calendar::thisMinute (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 24 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::thisMonth
Calendar::thisMonth() – Returns the value for this month
Synopsis
require_once 'Calendar.php';
int Calendar::thisMonth (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 5 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::thisSecond
Calendar::thisSecond() – Returns the value for this second
Synopsis
require_once 'Calendar.php';
int Calendar::thisSecond (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 44 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar::thisYear
Calendar::thisYear() – Returns the value for this year
Synopsis
require_once 'Calendar.php';
int Calendar::thisYear (
string $format = 'int'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
'int', 'timestamp' , 'array' or 'object'
Return value
returns e.g. 2003 or timestamp
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Year
Calendar_Year – Calendar_Year API
Description
Calendar_Year API.
constructor Calendar_Year::Calendar_Year
constructor Calendar_Year::Calendar_Year() – Constructs Calendar_Year
Synopsis
require_once 'Year.php';
void constructor Calendar_Year::Calendar_Year (
int $y
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Year::build
Calendar_Year::build() – Builds the Months of the Year.
Synopsis
require_once 'Year.php';
boolean Calendar_Year::build (
array$sDates = array()
, int$firstDay
= null
)
Description
Note: by defining the constant CALENDAR_MONTH_STATE you can control what class of Calendar_Month is built e.g.;
1 require_once 'Calendar/Calendar_Year.php';
2
define('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
3 // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
4
It defaults to building Calendar_Month objects.
Parameter
- array
$sDates -
(optional) array of Calendar_Month objects representing selected months
- integer
$firstDay -
(optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Month
Calendar_Month – Calendar_Month API
Description
Calendar_Month API.
constructor Calendar_Month::Calendar_Month
constructor Calendar_Month::Calendar_Month() – Constructs Calendar_Month
Synopsis
require_once 'Month.php';
void constructor Calendar_Month::Calendar_Month (
int $y
, int $m
, int $firstDay
= null
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$firstDay -
(optional) unused in this class
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Month::build
Calendar_Month::build() – Builds Day objects for this Month. Creates as many Calendar_Day objects
Synopsis
require_once 'Month.php';
boolean Calendar_Month::build (
array $sDates = array()
)
Description
as there are days in the month
Parameter
-
array
$sDates -
(optional) Calendar_Day objects representing selected dates
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Month_Weekdays
Calendar_Month_Weekdays – Calendar_Month_Weekdays API
Description
Calendar_Month_Weekdays API.
constructor Calendar_Month_Weekdays::Calendar_Month_Weekdays
constructor Calendar_Month_Weekdays::Calendar_Month_Weekdays() – Constructs Calendar_Month_Weekdays
Synopsis
require_once 'MonthWeekdays.php';
void constructor Calendar_Month_Weekdays::Calendar_Month_Weekdays (
int $y
, int $m
, int $firstDay
= false
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$firstDay -
(optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Month_Weekdays::build
Calendar_Month_Weekdays::build() – Builds Day objects in tabular form, to allow display of calendar month with empty cells if the first day of the week does not fall on the first day of the month.
Synopsis
require_once 'MonthWeekdays.php';
boolean Calendar_Month_Weekdays::build (
array $sDates = array()
)
Description
This package is not documented yet.
Parameter
-
array
$sDates -
(optional) Calendar_Day objects representing selected dates
Throws
throws no exceptions thrown
See
see Calendar_Day_Base::isLast()
see Calendar_Day_Base::isFirst()
Note
This function can not be called statically.
Calendar_Month_Weeks
Calendar_Month_Weeks – Calendar_Month_Weeks API
Description
Calendar API.
constructor Calendar_Month_Weeks::Calendar_Month_Weeks
constructor Calendar_Month_Weeks::Calendar_Month_Weeks() – Constructs Calendar_Month_Weeks
Synopsis
require_once 'MonthWeeks.php';
void constructor Calendar_Month_Weeks::Calendar_Month_Weeks (
int $y
, int $m
, int $firstDay
= false
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$firstDay -
(optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Month_Weeks::build
Calendar_Month_Weeks::build() – Builds Calendar_Week objects for the Month. Note that Calendar_Week
Synopsis
require_once 'MonthWeeks.php';
boolean Calendar_Month_Weeks::build (
array $sDates = array()
)
Description
builds Calendar_Day object in tabular form (with Calendar_Day->empty)
Parameter
-
array
$sDates -
(optional) Calendar_Week objects representing selected dates
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Week
Calendar_Week – Calendar_Week API
Description
Calendar_Week API.
constructor Calendar_Week::Calendar_Week
constructor Calendar_Week::Calendar_Week() – Constructs Week
Synopsis
require_once 'Week.php';
void constructor Calendar_Week::Calendar_Week (
int $y
, int $m
, int $d
, int $firstDay
= false
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$d -
a day of the desired week
-
integer
$firstDay -
(optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Week::build
Calendar_Week::build() – Builds Calendar_Day objects for this Week
Synopsis
require_once 'Week.php';
boolean Calendar_Week::build (
array $sDates = array()
)
Description
This package is not documented yet.
Parameter
-
array
$sDates -
(optional) Calendar_Day objects representing selected dates
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Week::nextWeek
Calendar_Week::nextWeek() – Gets the value of the following week, according to the requested format
Synopsis
require_once 'Week.php';
mixed Calendar_Week::nextWeek (
string $format
)
Description
This package is not documented yet.
Parameter
-
string
$format -
['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Week::prevWeek
Calendar_Week::prevWeek() – Gets the value of the previous week, according to the requested format
Synopsis
require_once 'Week.php';
mixed Calendar_Week::prevWeek (
string $format
)
Description
This package is not documented yet.
Parameter
-
string
$format -
['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Week::thisWeek
Calendar_Week::thisWeek() – Gets the value of the current week, according to the requested format
Synopsis
require_once 'Week.php';
mixed Calendar_Week::thisWeek (
string $format = 'n_in_month'
)
Description
This package is not documented yet.
Parameter
-
string
$format -
['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Day
Calendar_Day – Calendar_Day API
Description
Calendar_Day API.
constructor Calendar_Day::Calendar_Day
constructor Calendar_Day::Calendar_Day() – Constructs Calendar_Day
Synopsis
require_once 'Day.php';
void constructor Calendar_Day::Calendar_Day (
int $y
, int $m
, int $d
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 8
-
integer
$d -
day e.g. 15
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Day::build
Calendar_Day::build() – Builds the Hours of the Day
Synopsis
require_once 'Day.php';
boolean Calendar_Day::build (
array $sDates = array()
)
Description
This package is not documented yet.
Parameter
-
array
$sDates -
(optional) Calendar_Hour objects representing selected dates
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Day::isEmpty
Calendar_Day::isEmpty() – Synopsis require_once 'Day.php'; boolean Calendar_Day::isEmpty ( ) Description This package is not documented yet. Throws throws no exceptions thrown Note This function can not be called statically.
Calendar_Day::isFirst
Calendar_Day::isFirst() – Returns true if Day object is first in a Week
Synopsis
require_once 'Day.php';
boolean Calendar_Day::isFirst (
)
Description
Only relevant when Day is created by Calendar_Month_Weekdays::build()
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Day::isLast
Calendar_Day::isLast() – Returns true if Day object is last in a Week
Synopsis
require_once 'Day.php';
boolean Calendar_Day::isLast (
)
Description
Only relevant when Day is created by Calendar_Month_Weekdays::build()
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Hour
Calendar_Hour – Calendar_Hour API
Description
Calendar_Hour API.
constructor Calendar_Hour::Calendar_Hour
constructor Calendar_Hour::Calendar_Hour() – Constructs Calendar_Hour
Synopsis
require_once 'Hour.php';
void constructor Calendar_Hour::Calendar_Hour (
int $y
, int $m
, int $d
, int $h
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$d -
day e.g. 11
-
integer
$h -
hour e.g. 13
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Hour::build
Calendar_Hour::build() – Builds the Minutes in the Hour
Synopsis
require_once 'Hour.php';
boolean Calendar_Hour::build (
array $sDates = array()
)
Description
This package is not documented yet.
Parameter
-
array
$sDates -
(optional) Calendar_Minute objects representing selected minutes
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Minute
Calendar_Minute – Calendar_Minute API
Description
Calendar_Minute API.
constructor Calendar_Minute::Calendar_Minute
constructor Calendar_Minute::Calendar_Minute() – Constructs Minute
Synopsis
require_once 'Minute.php';
void constructor Calendar_Minute::Calendar_Minute (
int $y
, int $m
, int $d
, int $h
, int $i
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$d -
day e.g. 11
-
integer
$h -
hour e.g. 13
-
integer
$i -
minute e.g. 31
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Minute::build
Calendar_Minute::build() – Builds the Calendar_Second objects
Synopsis
require_once 'Minute.php';
boolean Calendar_Minute::build (
array $sDates = array()
)
Description
This package is not documented yet.
Parameter
-
array
$sDates -
(optional) Calendar_Second objects representing selected seconds
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Second
Calendar_Second – Calendar_Second API
Description
Calendar_Second API.
constructor Calendar_Second::Calendar_Second
constructor Calendar_Second::Calendar_Second() – Constructs Second
Synopsis
require_once 'Second.php';
void constructor Calendar_Second::Calendar_Second (
int $y
, int $m
, int $d
, int $h
, int $i
, int $s
)
Description
This package is not documented yet.
Parameter
-
integer
$y -
year e.g. 2003
-
integer
$m -
month e.g. 5
-
integer
$d -
day e.g. 11
-
integer
$h -
hour e.g. 13
-
integer
$i -
minute e.g. 31
-
integer
$s -
second e.g. 45
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Second::build
Calendar_Second::build() – Overwrite build
Synopsis
require_once 'Second.php';
NULL Calendar_Second::build (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Second::fetch
Calendar_Second::fetch() – Overwrite fetch
Synopsis
require_once 'Second.php';
NULL Calendar_Second::fetch (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Second::fetchAll
Calendar_Second::fetchAll() – Overwrite fetchAll
Synopsis
require_once 'Second.php';
NULL Calendar_Second::fetchAll (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Second::size
Calendar_Second::size() – Overwrite size
Synopsis
require_once 'Second.php';
NULL Calendar_Second::size (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validation_Error
Calendar_Validation_Error – Calendar_Validation_Error API
Description
Calendar_Validation_Error API.
constructor Calendar_Validation_Error::Calendar_Validation_Error
constructor Calendar_Validation_Error::Calendar_Validation_Error() – Constructs Calendar_Validation_Error
Synopsis
require_once 'Validator.php';
void constructor Calendar_Validation_Error::Calendar_Validation_Error (
string $unit
, int $value
, string $message
)
Description
This package is not documented yet.
Parameter
-
string
$unit -
Date unit (e.g. month,hour,second)
-
integer
$value -
Value of unit which failed test
-
string
$message -
Validation error message
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validation_Error::getMessage
Calendar_Validation_Error::getMessage() – Returns the validation error message
Synopsis
require_once 'Validator.php';
string Calendar_Validation_Error::getMessage (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validation_Error::getUnit
Calendar_Validation_Error::getUnit() – Returns the Date unit
Synopsis
require_once 'Validator.php';
string Calendar_Validation_Error::getUnit (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validation_Error::getValue
Calendar_Validation_Error::getValue() – Returns the value of the unit
Synopsis
require_once 'Validator.php';
int Calendar_Validation_Error::getValue (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validation_Error::toString
Calendar_Validation_Error::toString() – Returns a string containing the unit, value and error message
Synopsis
require_once 'Validator.php';
string Calendar_Validation_Error::toString (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator
Calendar_Validator – Calendar_Validator API
Description
Calendar_Validator API.
constructor Calendar_Validator::Calendar_Validator
constructor Calendar_Validator::Calendar_Validator() – Constructs Calendar_Validator
Synopsis
require_once 'Validator.php';
void constructor Calendar_Validator::Calendar_Validator (
object subclass &$calendar
)
Description
This package is not documented yet.
Parameter
-
object subclass;
&$calendar -
of Calendar
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::fetch
Calendar_Validator::fetch() – Iterates over any validation errors
Synopsis
require_once 'Validator.php';
mixed Calendar_Validator::fetch (
)
Description
This package is not documented yet.
Return value
returns either Calendar_Validation_Error or false
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValid
Calendar_Validator::isValid() – Calls all the other isValidXXX() methods in the validator
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValid (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValidDay
Calendar_Validator::isValidDay() – Check whether this is a valid day
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValidDay (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValidHour
Calendar_Validator::isValidHour() – Check whether this is a valid hour
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValidHour (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValidMinute
Calendar_Validator::isValidMinute() – Check whether this is a valid minute
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValidMinute (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValidMonth
Calendar_Validator::isValidMonth() – Check whether this is a valid month
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValidMonth (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValidSecond
Calendar_Validator::isValidSecond() – Check whether this is a valid second
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValidSecond (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Calendar_Validator::isValidYear
Calendar_Validator::isValidYear() – Check whether this is a valid year
Synopsis
require_once 'Validator.php';
boolean Calendar_Validator::isValidYear (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Package Calendar Constants
Package Calendar Constants – Constants defined in and used by Calendar
All Constants
Constants defined in Calendar.php
| Name | Value | Line Number |
|---|---|---|
| CALENDAR_ENGINE | 'UnixTS' | 39 |
| CALENDAR_ROOT | 'Calendar'.DIRECTORY_SEPARATOR | 32 |
Constants defined in Validator.php
| Name | Value | Line Number |
|---|---|---|
| CALENDAR_VALUE_TOOLARGE | 'Too large: max = ' | 34 |
| CALENDAR_VALUE_TOOSMALL | 'Too small: min = ' | 31 |
Constants defined in Year.php
| Name | Value | Line Number |
|---|---|---|
| CALENDAR_USE_MONTH | 1 | 43 |
| CALENDAR_USE_MONTH_WEEKDAYS | 2 | 44 |
| CALENDAR_USE_MONTH_WEEKS | 3 | 45 |