HumHub Documentation (unofficial)

DateHelper
in package

Utility class for date issues

Tags
see
DateValidator
author

buddha

Table of Contents

Constants

DB_DATE_FORMAT  = 'Y-m-d H:i:s'
DB_DATE_FORMAT_PHP  = 'php:Y-m-d H:i:s'
REGEX_DBFORMAT_DATE  = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/'
REGEX_DBFORMAT_DATETIME  = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (\d{2}):(\d{2}):(\d{2})$/'

Methods

getSystemTimeZone()  : DateTimeZone|string
getUserTimeZone()  : DateTimeZone|string
Returns the user timeZone or app timezone as fallback.
isInDbFormat()  : bool
Checks whether the given value is a db date format or not.
parseDateTime()  : int|false
Parses a date and optionally a time if timeAttribute is specified to an given pattern or the default pattern 'Y-m-d' if no pattern is provided.
parseDateTimeToTimestamp()  : int|false
Parses a date and optionally a time if timeAttribute is specified.

Constants

DB_DATE_FORMAT

public mixed DB_DATE_FORMAT = 'Y-m-d H:i:s'

DB_DATE_FORMAT_PHP

public mixed DB_DATE_FORMAT_PHP = 'php:Y-m-d H:i:s'

REGEX_DBFORMAT_DATE

public mixed REGEX_DBFORMAT_DATE = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/'

REGEX_DBFORMAT_DATETIME

public mixed REGEX_DBFORMAT_DATETIME = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (\d{2}):(\d{2}):(\d{2})$/'

Methods

getSystemTimeZone()

public static getSystemTimeZone([bool $asString = false ]) : DateTimeZone|string
Parameters
$asString : bool = false
Tags
since

v1.4

Return values
DateTimeZone|string

getUserTimeZone()

Returns the user timeZone or app timezone as fallback.

public static getUserTimeZone([mixed $asString = false ]) : DateTimeZone|string
Parameters
$asString : mixed = false
Tags
since

v1.4

Return values
DateTimeZone|string

isInDbFormat()

Checks whether the given value is a db date format or not.

public static isInDbFormat(string $value[, bool $dateOnly = false ]) : bool

If $dateOnly flag is set to true this method tests against date format without time, otherwise it will test against the db datetime format.

Parameters
$value : string

the date value

$dateOnly : bool = false
Tags
since

v1.4

Return values
bool

parseDateTime()

Parses a date and optionally a time if timeAttribute is specified to an given pattern or the default pattern 'Y-m-d' if no pattern is provided.

public static parseDateTime(string $value[, string $pattern = 'Y-m-d' ][, string $timeValue = null ]) : int|false
Parameters
$value : string

date value

$pattern : string = 'Y-m-d'

pattern

$timeValue : string = null

optional time value

Tags
throws
Exception
Return values
int|false

timestamp in utc or false in case value was could not be parsed

parseDateTimeToTimestamp()

Parses a date and optionally a time if timeAttribute is specified.

public static parseDateTimeToTimestamp(string $value[, string $timeValue = null ]) : int|false
Parameters
$value : string
$timeValue : string = null

optional time value

Tags
throws
Exception
Return values
int|false

timestamp in utc


        
On this page

Search results