TimeHelper Class Reference

Public Member Functions | |
| dayAsSql ($date_string, $field_name, $return=false) | |
| daysAsSql ($begin, $end, $field_name, $return=false) | |
| fromString ($date_string) | |
| isThisYear ($date_string, $return=false) | |
| isToday ($date_string, $return=false) | |
| isTomorrow ($date_string, $return=false) | |
| nice ($date_string=null, $return=false) | |
| niceShort ($date_string=null, $return=false) | |
| relativeTime ($datetime_string, $format= 'j/n/y', $return=false) | |
| timeAgoInWords ($datetime_string, $format= 'j/n/y', $backwards=false, $return=false) | |
| toAtom ($date_string, $return=false) | |
| toRSS ($date_string, $return=false) | |
| toUnix ($date_string, $return=false) | |
| trim ($string, $length, $ending= '..') | |
| wasWithinLast ($timeInterval, $date_string, $return=false) | |
| wasYesterday ($date_string, $return=false) | |
Detailed Description
Definition at line 35 of file time.php.
Member Function Documentation
| TimeHelper::dayAsSql | ( | $ | date_string, | |
| $ | field_name, | |||
| $ | return = false | |||
| ) |
Returns a partial SQL string to search for all records between two times occurring on the same day.
- Parameters:
-
string $date_string Datetime string or Unix timestamp string $field_name Name of database field to compare with boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Partial SQL string. public
Definition at line 148 of file time.php.
References daysAsSql(), fromString(), and Helper::output().
| TimeHelper::daysAsSql | ( | $ | begin, | |
| $ | end, | |||
| $ | field_name, | |||
| $ | return = false | |||
| ) |
Returns a partial SQL string to search for all records between two dates.
- Parameters:
-
string $date_string Datetime string or Unix timestamp string $end Datetime string or Unix timestamp string $field_name Name of database field to compare with boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Partial SQL string. public
Definition at line 130 of file time.php.
References fromString(), and Helper::output().
Referenced by dayAsSql().
| TimeHelper::fromString | ( | $ | date_string | ) |
Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
- Parameters:
-
string $date_string Datetime string
- Returns:
- string Formatted date string public
Definition at line 55 of file time.php.
Referenced by dayAsSql(), daysAsSql(), isThisYear(), isToday(), isTomorrow(), nice(), niceShort(), timeAgoInWords(), toAtom(), toRSS(), wasWithinLast(), and wasYesterday().
| TimeHelper::isThisYear | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Returns true if given datetime string is within current year.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- boolean True if datetime string is within current year public
Definition at line 161 of file time.php.
References fromString(), and Helper::output().
Referenced by niceShort().
| TimeHelper::isToday | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Returns true if given datetime string is today.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- boolean True if datetime string is today public
Definition at line 115 of file time.php.
References fromString(), and Helper::output().
Referenced by niceShort().
| TimeHelper::isTomorrow | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Returns true if given datetime string is tomorrow.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- boolean True if datetime string was yesterday public
Definition at line 187 of file time.php.
References fromString(), and Helper::output().
| TimeHelper::nice | ( | $ | date_string = null, |
|
| $ | return = false | |||
| ) |
Returns a nicely formatted date string for given Datetime string.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Formatted date string public
Definition at line 70 of file time.php.
References fromString(), and Helper::output().
| TimeHelper::niceShort | ( | $ | date_string = null, |
|
| $ | return = false | |||
| ) |
Returns a formatted descriptive date string for given datetime string.
If the given date is today, the returned string could be "Today, 16:54". If the given date was yesterday, the returned string could be "Yesterday, 16:54". If $date_string's year is the current year, the returned string does not include mention of the year.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Described, relative date string public
Definition at line 93 of file time.php.
References fromString(), isThisYear(), isToday(), Helper::output(), and wasYesterday().
| TimeHelper::relativeTime | ( | $ | datetime_string, | |
| $ | format = 'j/n/y', |
|||
| $ | return = false | |||
| ) |
Alias for timeAgoInWords
- Parameters:
-
string $date_string Datetime string or Unix timestamp string $format Default format if timestamp is used in $date_string boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Relative time string.
- See also:
- Time::timeAgoInWords() public
Definition at line 320 of file time.php.
References Helper::output(), and timeAgoInWords().
| TimeHelper::timeAgoInWords | ( | $ | datetime_string, | |
| $ | format = 'j/n/y', |
|||
| $ | backwards = false, |
|||
| $ | return = false | |||
| ) |
Returns either a relative date or a formatted date depending on the difference between the current time and given datetime. $datetime should be in a strtotime-parsable format, like MySQL's datetime datatype.
Relative dates look something like this: 3 weeks, 4 days ago 15 seconds ago Formatted dates look like this: on 02/18/2004
The returned string includes 'ago' or 'on' and assumes you'll properly add a word like 'Posted ' before the function output.
- Parameters:
-
string $date_string Datetime string or Unix timestamp string $format Default format if timestamp is used in $date_string string $backwards False if $date_string is in the past, true if in the future boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Relative time string. public
Definition at line 251 of file time.php.
References fromString(), and Helper::output().
Referenced by relativeTime().
| TimeHelper::toAtom | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Returns a date formatted for Atom RSS feeds.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Formatted date string public
Definition at line 212 of file time.php.
References fromString(), and Helper::output().
| TimeHelper::toRSS | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Formats date for RSS feeds
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- string Formatted date string public
Definition at line 225 of file time.php.
References fromString(), and Helper::output().
| TimeHelper::toUnix | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
- Parameters:
-
string $date_string Datetime string to be represented as a Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- int Unix timestamp public
Definition at line 200 of file time.php.
References Helper::output().
| TimeHelper::trim | ( | $ | string, | |
| $ | length, | |||
| $ | ending = '..' | |||
| ) |
Returns given string trimmed to given length, adding an ending (default: "..") if necessary.
- Parameters:
-
string $string String to trim integer $length Length of returned string, excluding ellipsis string $ending Ending to be appended after trimmed string
- Returns:
- string Trimmed string public
| TimeHelper::wasWithinLast | ( | $ | timeInterval, | |
| $ | date_string, | |||
| $ | return = false | |||
| ) |
Returns true if specified datetime was within the interval specified, else false.
- Parameters:
-
mixed $timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute. mixed $date_string the datestring or unix timestamp to compare boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- boolean public
Definition at line 340 of file time.php.
References fromString(), and Helper::output().
| TimeHelper::wasYesterday | ( | $ | date_string, | |
| $ | return = false | |||
| ) |
Returns true if given datetime string was yesterday.
- Parameters:
-
string $date_string Datetime string or Unix timestamp boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT.
- Returns:
- boolean True if datetime string was yesterday public
Definition at line 174 of file time.php.
References fromString(), and Helper::output().
Referenced by niceShort().
The documentation for this class was generated from the following file:
- 1.1.x.x/cake/libs/view/helpers/time.php