Flourish PHP Unframework

fTime

class, v1.0.0b12

Represents a time of day as a value object

Changes:
1.0.0b12Fixed a method signature 8/24/11
1.0.0b11Fixed a bug with the constructor not properly handling unix timestamps that are negative integers 6/2/11
1.0.0b10Changed the $time attribute to be protected 3/20/11
1.0.0b9Added the $simple parameter to getFuzzyDifference() 3/15/10
1.0.0b8Added a call to fTimestamp::callUnformatCallback() in __construct() for localization support 6/1/09
1.0.0b7Backwards compatibility break - Removed getSecondsDifference(), added eq(), gt(), gte(), lt(), lte() 3/5/09
1.0.0b6Fixed an outdated fCore method call 2/23/09
1.0.0b5Updated for new fCore API 2/16/09
1.0.0b4Fixed __construct() to properly handle the 5.0 to 5.1 change in strtotime() 1/21/09
1.0.0b3Added support for CURRENT_TIMESTAMP and CURRENT_TIME SQL keywords 1/11/09
1.0.0b2Removed the adjustment amount check from adjust() 12/31/08
1.0.0bThe initial implementation 2/12/08

Variables

->time protected

A timestamp of the time

Type

integer

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

Signatures

string getFuzzyDifference( fTime|object|string|integer $other_time=NULL, boolean $simple=FALSE )

string getFuzzyDifference( boolean $simple=FALSE )

Parameters

fTime|object|string|integer $other_time The time 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 times, but not from now, ago, after or before

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