fTimeclassv1.0.0b8
Represents a time of day as a value object
| 1.0.0b8 | Added a call to fTimestamp::callUnformatCallback() in __construct() for localization support 6/1/09 |
|---|---|
| 1.0.0b7 | Backwards compatibility break - Removed getSecondsDifference(), added eq(), gt(), gte(), lt(), lte() 3/5/09 |
| 1.0.0b6 | Fixed an outdated fCore method call 2/23/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_TIME 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/12/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 time to represent, no timezone is allowed since times don't have timezones
Signature
fTime __construct( fTime|object|string|integer $time=NULL )
Parameters
| fTime|object|string|integer | $time | The time to represent, NULL is interpreted as now |
Throws
- fValidationException
- When $time is not a valid time
->__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 time in 'H:i:s' format
Signature
string __toString( )
Returns
The 'H:i:s' format of this time
->adjust() public
Changes the time by the adjustment specified, only adjustments of 'hours', 'minutes', and 'seconds' are allowed
Signature
fTime adjust( string $adjustment )
Parameters
| string | $adjustment | The adjustment to make |
Returns
The adjusted time
Throws
- fValidationException
- When $adjustment is not a valid relative time measurement
->eq() public
If this time is equal to the time passed
Signature
boolean eq( fTime|object|string|integer $other_time=NULL )
Parameters
| fTime|object|string|integer | $other_time | The time to compare with, NULL is interpreted as today |
Returns
If this time is equal to the one passed
->format() public
Formats the time
Signature
string format( string $format )
Parameters
| string | $format | The date() function compatible formatting string, or a format name from fTimestamp::defineFormat() |
Returns
The formatted time
Throws
- fValidationException
- When a non-time 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 time is {return value} the provided one" when a time it passed
- "This time is {return value}" when no time is passed and comparing with the current time
Examples of output for a time passed might be:
- '5 minutes after'
- '2 hours before'
- 'at the same time'
Examples of output for no time passed might be:
- '5 minutes ago'
- '2 hours ago'
- 'right now'
You would never get the following output since it includes more than one unit of time measurement:
- '5 minutes and 28 seconds'
- '1 hour, 15 minutes'
Values that are close to the next largest unit of measure will be rounded up:
- '55 minutes' would be represented as '1 hour', however '45 minutes' would not
Signature
string getFuzzyDifference( fTime|object|string|integer $other_time=NULL )
Parameters
| fTime|object|string|integer | $other_time | The time to create the difference with, NULL is interpreted as now |
Returns
The fuzzy difference in time between the this time and the one provided
->gt() public
If this time is greater than the time passed
Signature
boolean gt( fTime|object|string|integer $other_time=NULL )
Parameters
| fTime|object|string|integer | $other_time | The time to compare with, NULL is interpreted as now |
Returns
If this time is greater than the one passed
->gte() public
If this time is greater than or equal to the time passed
Signature
boolean gte( fTime|object|string|integer $other_time=NULL )
Parameters
| fTime|object|string|integer | $other_time | The time to compare with, NULL is interpreted as now |
Returns
If this time is greater than or equal to the one passed
->lt() public
If this time is less than the time passed
Signature
boolean lt( fTime|object|string|integer $other_time=NULL )
Parameters
| fTime|object|string|integer | $other_time | The time to compare with, NULL is interpreted as today |
Returns
If this time is less than the one passed
->lte() public
If this time is less than or equal to the time passed
Signature
boolean lte( fTime|object|string|integer $other_time=NULL )
Parameters
| fTime|object|string|integer | $other_time | The time to compare with, NULL is interpreted as today |
Returns
If this time is less than or equal to the one passed
->modify() public
Modifies the current time, creating a new fTime object
The purpose of this method is to allow for easy creation of a time based on this time. Below are some examples of formats to modify the current time:
- '17:i:s' to set the hour of the time to 5 PM
- 'H:00:00'` to set the time to the beginning of the current hour
Signature
fTime modify( string $format )
Parameters
| string | $format | The current time will be formatted with this string, and the output used to create a new object |
Returns
The new time
