<<css mode="next" class="sidebar"></css>> (((
- '''<a href="/docs/fTime">Class Documentation</a>''' - <a href="/api/fTime">API Reference</a> - <a href="https://github.com/flourishlib/flourish-classes/blob/master/fTime.php" target="_blank">Source Code</a>
<<toc></toc>>
- fDate - '''fTime''' - fTimestamp
- fDate - fMoney - fNumber - '''fTime''' - fTimestamp
)))
The fTime class is a value object representation of a time. One of the primary attributes of the object is that its value can not be changed, but instead a new object is created.
The fTime constructor takes a single argument, a string, object or integer representing a time of day. For strings and objects (with `__toString()` methods), any format accepted by `strtotime()` will work. If the parameter is an integer, it will be interpreted as a unix timestamp and the date portion will be discarded.
Rather than allowing an fTime object value to be modified, which can create issues since objects are passed by reference, all changes to a time create a new object.
Usually when modifying a time, only one or two components (such as hour or minute) of the time will change. The ::modify() method leverages the formatting codes from the `date()` function to keep parts of the existing time while replacing others.
Here are some examples of `modify()`:
Occasionally you may have the need to adjust a time. The ::adjust() method takes a single parameter which can contain any relative time measurement that `strtotime()` accepts. Since fTime is a value object, a new object is returned with the adjusted time. Here are some examples:
To format the time, simply call the ::format() method with any valid time formatting string from `date()`. Here are some examples:
There are five different methods available to compare times, ::eq(), ::gt(), ::gte(), ::lt() and ::lte(). Each method optionally accepts a parameter `$other_time`. If no `$other_time` is specified, the time is compared to the current time. If `$other_time` is specified, the two are compared. `$other_time` accepts any valid date string that works with ::__construct().
Here are some examples:
If you are looking to get a fuzzy difference between two times for display, you’ll want to use the ::getFuzzyDifference() method. The first parameter, `$other_time`, optionally accepts a valid time descriptor that can be passed to ::__construct(). If a valid time descriptor is passed, the difference will be between the two times, if nothing is passed, the difference will be between the fTime and the current time.
The value returned by `getFuzzyDifference()` will be a string representing the most broad time measurement between the two times. In addition, if the difference is just shy of the next largest time measurement, it will be rounded up. Thus 52 minutes would become 1 hour.
Here are some examples to clarify. The following examples are comparing two times:
These examples show output when comparing an fTime object with the current time:
An optional boolean parameter, `$simple`, can also be passed to `getFuzzyDifference()`. When `TRUE`, this parameter causes the method to return the difference in time, but not the direction.