
Represents a date and time as a value object
1.0.0b13 | Fixed a method signature 8/24/11 |
---|---|
1.0.0b12 | Fixed a bug with the constructor not properly handling unix timestamps that are negative integers 6/2/11 |
1.0.0b11 | Changed the $timestamp and $timezone attributes to be protected 3/20/11 |
1.0.0b10 | Fixed a bug in __construct() with specifying a timezone other than the default for a relative time string such as "now" or "+2 hours" 7/5/10 |
1.0.0b9 | Added the $simple parameter to getFuzzyDifference() 3/15/10 |
1.0.0b8 | Fixed a bug with fixISOWeek() not properly parsing some ISO week dates 10/6/09 |
1.0.0b7 | Fixed a translation bug with getFuzzyDifference() 7/11/09 |
1.0.0b6 | Added registerUnformatCallback() and callUnformatCallback() to allow for localization of date/time parsing 6/1/09 |
1.0.0b5 | Backwards compatibility break - Removed getSecondsDifference() and getSeconds(), added eq(), gt(), gte(), lt(), lte() 3/5/09 |
1.0.0b4 | Updated for new fCore API 2/16/09 |
1.0.0b3 | Removed a useless double check of the strtotime() return value in __construct() 1/21/09 |
1.0.0b2 | Added support for CURRENT_TIMESTAMP, CURRENT_DATE and CURRENT_TIME SQL keywords 1/11/09 |
1.0.0b | The initial implementation 2/12/08 |
The date/time
integer
The timezone for this date/time
string
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
If a format callback is defined, call it
string callFormatCallback( string $formatted_string )
string | $formatted_string | The formatted date/time/timestamp string to be (possibly) modified |
The (possibly) modified formatted string
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
If an unformat callback is defined, call it
string callUnformatCallback( string $date_time_string )
string | $date_time_string | A raw date/time/timestamp string to be (possibly) parsed/modified |
The (possibly) parsed or modified date/time/timestamp
Composes text using fText if loaded
string compose( string $message, mixed $component [, ... ] )
string | $message | The message to compose |
mixed | $component [, ... ] | A string or number to insert into the message |
The composed and possible translated message
Creates a reusable format for formatting fDate, fTime, and fTimestamp objects
void defineFormat( string $name, string $formatting_string )
string | $name | The name of the format |
string | $formatting_string | The format string compatible with the date() function |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Fixes an ISO week format into 'Y-m-d' so strtotime() will accept it
string fixISOWeek( string $date )
string | $date | The date to fix |
The fixed date
Provides a consistent interface to getting the default timezone. Wraps the date_default_timezone_get() function.
string getDefaultTimezone( )
The default timezone used for all date/time calculations
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Checks to see if a timezone is valid
boolean isValidTimezone( string $timezone )
string | $timezone | The timezone to check |
If the timezone is valid
Allows setting a callback to translate or modify any return values from format(), fDateformat() and fTime::format()
void registerFormatCallback( callback $callback )
callback | $callback | The callback to pass all formatted dates/times/timestamps through. Should accept a single string and return a single string. |
Allows setting a callback to parse any date strings passed into __construct(), fDate__construct() and fTime::__construct()
void registerUnformatCallback( callback $callback )
callback | $callback | The callback to pass all date/time/timestamp strings through. Should accept a single string and return a single string that is parsable by strtotime(). |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Provides a consistent interface to setting the default timezone. Wraps the date_default_timezone_set() function.
void setDefaultTimezone( string $timezone )
string | $timezone | The default timezone to use for all date/time calculations |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Takes a format name set via defineFormat() and returns the date() function formatting string
string translateFormat( string $format )
string | $format | The format to translate |
The formatting string. If no matching format was found, this will be the same as the $format parameter.
Creates the date/time to represent
fTimestamp __construct( fTimestamp|object|string|integer $datetime=NULL, string $timezone=NULL )
fTimestamp|object|string|integer | $datetime | The date/time to represent, NULL is interpreted as now |
string | $timezone | The timezone for the date/time. This causes the date/time to be interpretted as being in the specified timezone. If not specified, will default to timezone set by setDefaultTimezone(). |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
All requests that hit this method should be requests for callbacks
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
Returns this date/time
string __toString( )
The 'Y-m-d H:i:s' format of this date/time
Changes the date/time by the adjustment specified
fTimestamp adjust( string $adjustment )
string | $adjustment | The adjustment to make - may be a relative adjustment or a different timezone |
The adjusted date/time
If this timestamp is equal to the timestamp passed
boolean eq( fTimestamp|object|string|integer $other_timestamp=NULL )
fTimestamp|object|string|integer | $other_timestamp | The timestamp to compare with, NULL is interpreted as today |
If this timestamp is equal to the one passed
Formats the date/time
string format( string $format )
string | $format | The date() function compatible formatting string, or a format name from defineFormat() |
The formatted date/time
Returns the approximate difference in time, discarding any unit of measure but the least specific.
The output will read like:
Examples of output for a timestamp passed might be:
Examples of output for no timestamp passed might be:
You would never get the following output since it includes more than one unit of time measurement:
Values that are close to the next largest unit of measure will be rounded up:
string getFuzzyDifference( fTimestamp|object|string|integer $other_timestamp=NULL, boolean $simple=FALSE )
string getFuzzyDifference( boolean $simple=FALSE )
fTimestamp|object|string|integer | $other_timestamp | The timestamp to create the difference with, NULL is interpreted as now |
boolean | $simple | When TRUE, the returned value will only include the difference in the two timestamps, but not from now, ago, after or before |
The fuzzy difference in time between the this timestamp and the one provided
If this timestamp is greater than the timestamp passed
boolean gt( fTimestamp|object|string|integer $other_timestamp=NULL )
fTimestamp|object|string|integer | $other_timestamp | The timestamp to compare with, NULL is interpreted as now |
If this timestamp is greater than the one passed
If this timestamp is greater than or equal to the timestamp passed
boolean gte( fTimestamp|object|string|integer $other_timestamp=NULL )
fTimestamp|object|string|integer | $other_timestamp | The timestamp to compare with, NULL is interpreted as now |
If this timestamp is greater than or equal to the one passed
If this timestamp is less than the timestamp passed
boolean lt( fTimestamp|object|string|integer $other_timestamp=NULL )
fTimestamp|object|string|integer | $other_timestamp | The timestamp to compare with, NULL is interpreted as today |
If this timestamp is less than the one passed
If this timestamp is less than or equal to the timestamp passed
boolean lte( fTimestamp|object|string|integer $other_timestamp=NULL )
fTimestamp|object|string|integer | $other_timestamp | The timestamp to compare with, NULL is interpreted as today |
If this timestamp is less than or equal to the one passed
Modifies the current timestamp, creating a new fTimestamp object
The purpose of this method is to allow for easy creation of a timestamp based on this timestamp. Below are some examples of formats to modify the current timestamp:
fTimestamp modify( string $format, string $timezone=NULL )
string | $format | The current timestamp will be formatted with this string, and the output used to create a new object. The format should not include the timezone (character e). |
string | $timezone | The timezone for the new object if different from the current timezone |
The new timestamp