PHP Class Scalr_Util_DateTime, scalr

Show file Open project: scalr/scalr Class Usage Examples

Public Methods

Method Description
convertDateTime ( DateTime | string | integer $value, string $timezone, string $format = 'M j, Y H:i:s' ) : string Converts Time according to timezone parameter.
convertTimeZone ( DateTime $dt, $remoteTz = NULL )
convertTz ( DateTime | string | integer $value, string $format = 'M j, Y H:i:s' ) : string Converts Time according to timezone settings of current user.
convertTzFromUTC ( DateTime | string | integer $value, string $format = 'M j, Y H:i:s' ) : string Converts Time according to timezone settings of current user from UTC date.
correctTime ( integer $time, float $tz_offset = null ) : integer Correct time with current timezone offset
findTimezoneByOffset ( $offset )
getDateTimeDiff ( $dateTime1, $dateTime2, boolean $humanReadable = true ) : string | integer Calculates difference in seconds between two dates.
getFuzzyTime ( integer | string $time, integer $tz_offset = null ) : string Gets a slightly more fuzzy time string. such as: yesterday at 3:51pm
getFuzzyTimeString ( $value )
getHumanReadableTimeout ( integer | string $time, boolean $show_secs = true ) : string Converts a Unix timestamp or date/time string to a human-readable format, such as '1 day, 2 hours, 42 mins, and 52 secs'
getIncrescentTimeInterval ( $value, $currentTime = null ) : string Formats a time interval depending on the size according to: - just now - interval < 1 min - 2 min ago - interval < 30 mins - 3:17 AM - today - Yesterday, 3:17 AM - yesterday - Jan. 10, 7:12 AM - current year - Jan. 10,2015, 7:12 AM - less than the current year
getTimezones ( boolean $returnOffset = false ) : array
yearweek ( string $date ) : number Gets the week of the year in the same way as MYSQL's YEARWEEK(date, 0) MODE 0

Method Details

convertDateTime() public static method

Converts Time according to timezone parameter.
public static convertDateTime ( DateTime | string | integer $value, string $timezone, string $format = 'M j, Y H:i:s' ) : string
$value DateTime | string | integer DateTime object or Unix Timestamp or string that represents time.
$timezone string TimeZone
$format string Format
return string Returns updated time in given format.

convertTimeZone() public static method

public static convertTimeZone ( DateTime $dt, $remoteTz = NULL )
$dt DateTime

convertTz() public static method

Converts Time according to timezone settings of current user.
public static convertTz ( DateTime | string | integer $value, string $format = 'M j, Y H:i:s' ) : string
$value DateTime | string | integer DateTime object or Unix Timestamp or string that represents time.
$format string Format
return string Returns updated time in given format.

convertTzFromUTC() public static method

Converts Time according to timezone settings of current user from UTC date.
public static convertTzFromUTC ( DateTime | string | integer $value, string $format = 'M j, Y H:i:s' ) : string
$value DateTime | string | integer DateTime object or Unix Timestamp or string that represents time.
$format string Format
return string Returns updated time in given format.

correctTime() public static method

Correct time with current timezone offset
public static correctTime ( integer $time, float $tz_offset = null ) : integer
$time integer Time to convert
$tz_offset float timezone offset in hours
return integer Returns unix timestamp

findTimezoneByOffset() public static method

public static findTimezoneByOffset ( $offset )

getDateTimeDiff() public static method

Calculates difference in seconds between two dates.
public static getDateTimeDiff ( $dateTime1, $dateTime2, boolean $humanReadable = true ) : string | integer
$humanReadable boolean Return number of seconds or human readable string
return string | integer Returns difference between dates.

getFuzzyTime() public static method

Gets a slightly more fuzzy time string. such as: yesterday at 3:51pm
public static getFuzzyTime ( integer | string $time, integer $tz_offset = null ) : string
$time integer | string Time
$tz_offset integer optional A timezone offset
return string

getFuzzyTimeString() public static method

public static getFuzzyTimeString ( $value )

getHumanReadableTimeout() public static method

Based on the word_time() function from PG+ (http://pgplus.ewtoo.org)
public static getHumanReadableTimeout ( integer | string $time, boolean $show_secs = true ) : string
$time integer | string Timeout
$show_secs boolean optional Should it show the seconds
return string Returns human readable timeout

getIncrescentTimeInterval() public static method

Formats a time interval depending on the size according to: - just now - interval < 1 min - 2 min ago - interval < 30 mins - 3:17 AM - today - Yesterday, 3:17 AM - yesterday - Jan. 10, 7:12 AM - current year - Jan. 10,2015, 7:12 AM - less than the current year
public static getIncrescentTimeInterval ( $value, $currentTime = null ) : string
return string

getTimezones() public static method

public static getTimezones ( boolean $returnOffset = false ) : array
$returnOffset boolean optional If true return object [timezone] = GMT offset, otherwise return array of timezones
return array

yearweek() public static method

Gets the week of the year in the same way as MYSQL's YEARWEEK(date, 0) MODE 0
public static yearweek ( string $date ) : number
$date string The date YYYY-MM-DD
return number Returns yearweek, for example: 201402