\TriTan\CommonDate

Summary

Methods
Properties
Constants
__construct()
minuteInSeconds()
hourInSeconds()
dayInSeconds()
weekInSeconds()
monthInSeconds()
yearInSeconds()
format()
gmtdate()
locale()
laci2Date()
current()
timestampToDate()
timeAgo()
$time
$timezone
$locale
$date
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$time

$time : 

Type

$timezone

$timezone : 

Type

$locale

$locale : 

Type

$date

$date : 

Type

Methods

__construct()

__construct(string  $time = null, string|\TriTan\Common\DateTimeZone  $timezone = null, string  $locale = null) 

Returns new Datetime object.

Parameters

string $time
string|\TriTan\Common\DateTimeZone $timezone
string $locale

minuteInSeconds()

minuteInSeconds() : integer

Returns minute in seconds.

Returns

integer

hourInSeconds()

hourInSeconds() : integer

Returns hour in seconds.

Returns

integer

dayInSeconds()

dayInSeconds() : integer

Returns day in seconds.

Returns

integer

weekInSeconds()

weekInSeconds() : integer

Returns week in seconds.

Returns

integer

monthInSeconds()

monthInSeconds() : integer

Returns month in seconds.

Returns

integer

yearInSeconds()

yearInSeconds() : integer

Returns year in seconds.

Returns

integer

format()

format(string  $format = 'Y-m-d H:i:s', string  $date = 'now') : string

Formats date.

This function uses the set timezone from TriTan options.

Example Usage:

 $datetime = 'May 15, 2018 2:15 PM';
 $this->format('Y-m-d H:i:s', $datetime);

Parameters

string $format

Format of the date. Default is Y-m-d H:i:s.

string $date

Date to be formatted. Default is now.

Returns

string

gmtdate()

gmtdate(string  $date = 'now', string  $format = 'Y-m-d H:i:s') : string

Format a GMT/UTC date/time

Parameters

string $date

Date to be formatted. Default is now.

string $format

Format of the date. Default is Y-m-d H:i:s.

Returns

string —

Formatted date string.

locale()

locale() : object

Returns the date in localized format.

Returns

object —

Returns current localized datetime.

laci2Date()

laci2Date(string  $format, string  $date, boolean  $translate = true) : string|integer|boolean

Converts given date string into a different format.

$format should be either a PHP date format string, e.g. 'U' for a Unix timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.

If $translate is true, then the given date and format string will be passed to $this->locale() for translation.

Parameters

string $format

Format of the date to return.

string $date

Date string to convert.

boolean $translate

Whether the return date should be translated. Default true.

Returns

string|integer|boolean —

Formatted date string or Unix timestamp. False if $date is empty.

current()

current(string  $type, boolean  $gmt = false) : integer|string

Returns the current time based on specified type.

The 'laci' type will return the time in the format for LaciDb date field(s). The 'timestamp' type will return the current timestamp. Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d h:i:s').

If $gmt is set to either '1' or 'true', then both types will use GMT time. If $gmt is false, the output is adjusted with the GMT offset based on General Settings.

Parameters

string $type

Type of time to return. Accepts 'laci', 'timestamp', or PHP date format string (e.g. 'Y-m-d').

boolean $gmt

Optional. Whether to use GMT timezone. Default false.

Returns

integer|string —

Integer if $type is 'timestamp', string otherwise.

timestampToDate()

timestampToDate(string  $format, integer  $timestamp) : string

Converts timestamp to localized human readable date.

Parameters

string $format

PHP date format string (e.g. 'Y-m-d').

integer $timestamp

Timestamp to convert.

Returns

string —

Localized human readable date.

timeAgo()

timeAgo(  $original) 

Prints elapsed time based on datetime.

Parameters

$original