fDateclassv1.0.0b7
Represents a date as a value object
| 1.0.0b7 | Added a call to fTimestamp::callUnformatCallback() in __construct() for localization support 6/1/09 |
|---|---|
| 1.0.0b6 | Backwards compatibility break - Removed getSecondsDifference(), added eq(), gt(), gte(), lt(), lte() 3/5/09 |
| 1.0.0b5 | Updated for new fCore API 2/16/09 |
| 1.0.0b4 | Fixed __construct() to properly handle the 5.0 to 5.1 change in strtotime() 1/21/09 |
| 1.0.0b3 | Added support for CURRENT_TIMESTAMP and CURRENT_DATE SQL keywords 1/11/09 |
| 1.0.0b2 | Removed the adjustment amount check from adjust() 12/31/08 |
| 1.0.0b | The initial implementation 2/10/08 |
Static Methods
::compose() protected
Composes text using fText if loaded
Signature
string compose( string $message, mixed $component )
Parameters
| string | $message | The message to compose |
| mixed | $component [, ... ] | A string or number to insert into the message |
Returns
The composed and possible translated message
Methods
->__construct() public
Creates the date to represent, no timezone is allowed since dates don't have timezones
Signature
fDate __construct( fDate|object|string|integer $date=NULL )
Parameters
| fDate|object|string|integer | $date | The date to represent, NULL is interpreted as today |
Throws
- fValidationException
- When $date is not a valid date
->__get() internal public
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
Signature
callback __get( string $method )
Parameters
| string | $method | The method to create a callback for |
Returns
The callback for the method requested
->__toString() public
Returns this date in Y-m-d format
Signature
string __toString( )
Returns
The Y-m-d format of this date
->adjust() public
Changes the date by the adjustment specified, only adjustments of a day or more will be made
Signature
fDate adjust( string $adjustment )
Parameters
| string | $adjustment | The adjustment to make |
Returns
The adjusted date
Throws
- fValidationException
- When $adjustment is not a relative date measurement
->eq() public
If this date is equal to the date passed
Signature
boolean eq( fDate|object|string|integer $other_date=NULL )
Parameters
| fDate|object|string|integer | $other_date | The date to compare with, NULL is interpreted as today |
Returns
If this date is equal to the one passed
->format() public
Formats the date
Signature
string format( string $format )
Parameters
| string | $format | The date() function compatible formatting string, or a format name from fTimestamp::defineFormat() |
Returns
The formatted date
Throws
- fValidationException
- When a non-date formatting character is included in $format
->getFuzzyDifference() public
Returns the approximate difference in time, discarding any unit of measure but the least specific.
The output will read like:
- "This date is {return value} the provided one" when a date it passed
- "This date is {return value}" when no date is passed and comparing with today
Examples of output for a date passed might be:
- '2 days after'
- '1 year before'
- 'same day'
Examples of output for no date passed might be:
- '2 days from now'
- '1 year ago'
- 'today'
You would never get the following output since it includes more than one unit of time measurement:
- '3 weeks and 1 day'
- '1 year and 2 months'
Values that are close to the next largest unit of measure will be rounded up:
- 6 days would be represented as 1 week, however 5 days would not
- 29 days would be represented as 1 month, but 21 days would be shown as 3 weeks
Signature
string getFuzzyDifference( fDate|object|string|integer $other_date=NULL )
Parameters
| fDate|object|string|integer | $other_date | The date to create the difference with, NULL is interpreted as today |
Returns
The fuzzy difference in time between the this date and the one provided
->gt() public
If this date is greater than the date passed
Signature
boolean gt( fDate|object|string|integer $other_date=NULL )
Parameters
| fDate|object|string|integer | $other_date | The date to compare with, NULL is interpreted as today |
Returns
If this date is greater than the one passed
->gte() public
If this date is greater than or equal to the date passed
Signature
boolean gte( fDate|object|string|integer $other_date=NULL )
Parameters
| fDate|object|string|integer | $other_date | The date to compare with, NULL is interpreted as today |
Returns
If this date is greater than or equal to the one passed
->lt() public
If this date is less than the date passed
Signature
boolean lt( fDate|object|string|integer $other_date=NULL )
Parameters
| fDate|object|string|integer | $other_date | The date to compare with, NULL is interpreted as today |
Returns
If this date is less than the one passed
->lte() public
If this date is less than or equal to the date passed
Signature
boolean lte( fDate|object|string|integer $other_date=NULL )
Parameters
| fDate|object|string|integer | $other_date | The date to compare with, NULL is interpreted as today |
Returns
If this date is less than or equal to the one passed
->modify() public
Modifies the current date, creating a new fDate object
The purpose of this method is to allow for easy creation of a date based on this date. Below are some examples of formats to modify the current date:
- 'Y-m-01' to change the date to the first of the month
- 'Y-m-t' to change the date to the last of the month
- 'Y-\W5-N' to change the date to the 5th week of the year
Signature
fDate modify( string $format )
Parameters
| string | $format | The current date will be formatted with this string, and the output used to create a new object |
Returns
The new date
