Class: Date
- Package: saf.Date
- Author: John Luxford <lux@simian.ca>
- Copyright: Copyright (C) 2001-2003, Simian Systems Inc.
- License: http://www.sitellite.org/index/license Simian Open Software License
- Version: 2.2, 2003-05-23, $Id: Date.php,v 1.4 2007/10/06 00:06:30 lux Exp $
- Access: public
A class used to format dates, as well as generate them.
New in 1.4:
- format(), time(), and timestamp() methods don't error on 00000... date values.
New in 1.6:
- Added add(), subtract(), and roundTime() methods.
New in 1.8:
- You can now pass an associative array of formats to the format() and
timestamp() methods. The keys may be 'today', 'yesterda', 'tomorrow',
'this week', and 'other'. The appropriate format will then be used.
New in 2.0:
- Added a toUnix() method, a compare() method, and improved the flexibility
of the basic format() method to support the formats of timestamp() as well.
- This package now defines four constants, which contain the following
values:
- YEAR_IN_SECONDS, 31536000
- WEEK_IN_SECONDS, 604800
- DAY_IN_SECONDS, 86400
- HOUR_IN_SECONDS, 3600
New in 2.2:
- Removed the EasyText() and EasyTextInit() methods.
Usage Example
<?php
// print the current date
echo Date::format ();
?>
Return to Top
Properties
$dayLinks = false
Link pattern for days.
$showPeriod
Tells the calendar what to display on a single screen. May be
'day', 'week', or 'month'.
$beginWeekOn
Tells the calendar what day of the week to start the calendar
on. Value may be one of 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri',
and 'Sat'.
$firstDay
Contains the date (Y-m-d format) of the first day to include
in the current calendar view.
$currentDay
Contains the current date (Y-m-d format).
$lastDay
Contains the date (Y-m-d format) of the last day to include
in the current calendar view.
$showFromHour = 0
Tells Calendar to limit the hours displayed in 'day' view.
Must be an integer from 0 to 23.
$showToHour = 23
Tells Calendar to limit the hours displayed in 'day' view.
Must be an integer from 0 to 23.
$activeCells = array ()
Contains a list of the active cells in the Calendar
matrix. Active cells are the days that are in use.
$cellTemplate
Contains a default template for use in each cell. The
cell template is not to be confused with the item template,
which displays an individual item on any given day.
$topBlock
Reference to the cell that contains the space before
the first day of the month in the 'month' $showPeriod.
$bottomBlock
Reference to the cell that contains the space after
the last day of the month in the 'month' $showPeriod.
$error
If an error has occured within this class, you'll
find it in $error.
Return to Top
Methods
toUnix ($date = '')
- Access: public
- Return: integer
Accepts a date ('Y-m-d' format), full date/time ('YmdHis' or 'Y-m-d H:i:s'
formats), or unix timestamp, and returns a unix timestamp equivalent (or the value
passed if passed a timestamp already). Returns a timestamp of the current
date/time if passed no date at all.
compare ($date1, $date2, $equality_range = 0, $range_forward = false)
- Access: public
- Return: integer
Compares two dates, full date/time ('YmdHis' or 'Y-m-d H:i:s' formats),
or unix timestamps, and returns -1 if the first is greater, 0 if they are equal,
and 1 if the second is greater. Optional third and fourth parameters,
$equality_range, and $range_forward, allow you to specify a range of time
in seconds that qualifies as the equality range. If $range_forward is set,
then $equality_range acts as a "past range" and $range_forward acts as a
"future" range, allowing you to compare a date to say the following 24 hours.
If $range_forward is not set, then $equality_range acts as both the past and
future range. Note: The range is always surrounding $date2, so for logic that
requires the range to be around $date1, reverse the dates.
local ($date = '', $offset = 0, $format = 'F j, Y h:i:s a')
- Access: public
- Return: string
Returns the specified time (or the current time, if unspecified) with
an offset in hours from GMT to the local timezone. $date is a Unix timestamp
in this method.
format ($date = '', $format = 'F j, Y')
- Access: public
- Return: string
Formats a date provided in ISO format (YYYY-MM-DD) in the new
format specified.
time ($time = '', $format = 'g:ia')
- Access: public
- Return: string
Formats a time provided in ISO format (HH:MM:SS) in the new
format specified.
timestamp ($timestamp = '', $format = 'M j, Y h:i:s a')
- Access: public
- Return: string
Formats a timestamp provided in ISO format (YYYY-MM-DD HH:MM:SS) in
the new format specified.
add ($date, $amount)
- Access: public
- Return: string
Adds to the specified date and returns the finished calculation.
$date is in the format Y-m-d, and $amount can be either '# year',
'# month', '# week', or '# day', where # is any number.
subtract ($date, $amount)
- Access: public
- Return: string
Subtracts from the specified date and returns the finished
calculation. $date is in the format Y-m-d, and $amount can be either
'# year', '# month', '# week', or '# day', where # is any number.
roundTime ($time, $interval = 15)
- Access: public
- Return: string
Parses a time string (format: HH:MM:SS) and rounds it to
the nearest 15 minutes, 1/2 hour, or hour, depending on the interval
value set. $interval may be 15, 30, or 60. Returns the time as
a string in the same format as it accepts.
convert ($frmt)
Return to Top