Date Class
The Date class is a set of helper functions for working with dates.
factory($timestamp = null, $timezone = null)
The factory method returns a new date object.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$timestamp |
null
|
The timestamp to set the date object to |
$timezone |
null
|
The timezone in which the time is set |
|
Returns |
Fuel\Core\Date Object |
Example |
print_r( Date::factory( 1294176140 ) );
// Returns
Fuel\Core\Date Object
(
[timestamp:protected] => 1294176140
[timezone:protected] => UTC
)
|
time($timezone = null)
The time method returns the current time in the given timezone as a Date object.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$timezone |
null
|
The timezone in which the time is set |
|
Returns |
Fuel\Core\Date Object |
Example |
print_r( Date::time() );
|
create_from_string($input, $pattern_key = 'local')
The create_from_string creates a Date object from a named date string format
This function uses strptime() for internationalization purposes. That method
isn't available on Windows hosts however, on those strtotime() is used instead and the
pattern is ignored.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$input |
Required |
The date string to use |
$pattern_key |
"local" |
The pattern key to use (see config/date.php) |
|
Returns |
Fuel\Core\Date Object |
Example |
print_r( Date::create_from_string( "01/04/2011" , "us" ) );
// Returns
Fuel\Core\Date Object
(
[timestamp:protected] => 1322956800
[timezone:protected] => UTC
)
|
range_to_array($start, $end, $interval = '+1 Day')
The range_to_array converts a range of dates into an array of date objects
Static |
Yes |
Parameters |
Param |
Default |
Description |
$start |
Required |
The start date either as a Date object or a timestamp |
$end |
Required |
The end date either as a Date object or a timestamp |
$interval |
"+1 Day" |
The interval at which to create a Date object |
|
Returns |
array |
Example |
$start = time();
$end = $start + 604800; // Plus 1 week
print_r( Date::range_to_array($start, $end, "+2 days") );
// Returns
Array
(
[0] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294181818
[timezone:protected] => UTC
)
[1] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294354618
[timezone:protected] => UTC
)
[2] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294527418
[timezone:protected] => UTC
)
[3] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294700218
[timezone:protected] => UTC
)
)
|
days_in_month($month, $year = null)
The days_in_month returns the number of days in any given month, in the year specified
Static |
Yes |
Parameters |
Param |
Default |
Description |
$month |
Required |
The month to use |
$year |
null
|
The year to use (defaults to current year) |
|
Returns |
int |
Example |
echo Date::days_in_month(2); // 28
echo Date::days_in_month(2,2000); // 29
|
time_ago($timestamp)
The time_ago method returns a formatted time difference.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$timestamp |
Required |
The UNIX timestamp |
|
Returns |
string |
Example |
echo Date::time_ago( 1294176140 ); // 3 months ago
|
format($pattern_key = 'local')
The formatted method returns a formatted date as specified by the pattern key
Static |
No |
Parameters |
Param |
Default |
Description |
$pattern_key |
"local" |
The pattern key to use (see config/date.php) |
|
Returns |
string |
Example |
echo Date::factory( 1294176140 )->format("%m/%d/%Y"); // 01/04/2011
|
get_timestamp()
The get_timestamp method returns the Date object's timestamp
Static |
No |
Returns |
int |
Example |
echo Date::factory( 1294176140 )->get_timestamp(); // 1294176140
|
get_timezone()
The get_timezone method returns the Date object's timezone
Static |
No |
Returns |
string |
Example |
echo Date::factory( 1294176140, "Europe/London" )->get_timezone(); // Europe/London
|
set_timezone($timezone)
The set_timezone method sets the Date object's timezone
Static |
No |
Parameters |
Param |
Default |
Description |
$timezone |
required |
The timezone to set the Date object to |
|
Returns |
string |
Example |
echo Date::factory( 1294176140 )->set_timezone("America/Chicago")->get_timezone(); // America/Chicago
|