PHP Class Contao\Date

The class converts arbitrary date strings to Unix timestamps and provides extended information like the begin or end of the day, week, month or year. Usage: $date = new Date(); echo $date->datim; $date = new Date('2011-09-18', 'Y-m-d'); echo $date->monthBegin; Date::formatToJs('m/d/Y H:i');
显示文件 Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrRange array Date range
$strDate integer Date string
$strFormat string Format string

Public Methods

Method Description
__construct ( integer $strDate = null, string $strFormat = null ) Set the object properties
__get ( string $strKey ) : mixed | null Return an object property
floorToMinute ( integer $intTime = null ) : integer Round a UNIX timestamp to the full minute
formatToJs ( string $strFormat ) : mixed Convert a PHP format string into a JavaScript format string
getFormatFromRgxp ( string $strRgxp ) : string Return a numeric format string depending on the regular expression name
getInputFormat ( string $strFormat = null ) : string Return an input format string for a particular date (e.g. YYYY-MM-DD)
getNumericDateFormat ( ) : string Return the numeric date format string
getNumericDatimFormat ( ) : string Return the numeric datim format string
getNumericTimeFormat ( ) : string Return the numeric time format string
getRegexp ( string $strFormat = null ) : string Return a regular expression to check a date
getWeekBegin ( integer $intStartDay ) : integer Return the begin of the week as timestamp
getWeekEnd ( integer $intStartDay ) : integer Return the end of the week as timestamp
isNumericFormat ( string $strFormat ) : boolean Check for a numeric date format
parse ( string $strFormat, integer $intTstamp = null ) : string Parse a date format string and translate textual representations

Protected Methods

Method Description
createDateRanges ( ) Create the date ranges
dateToUnix ( ) Convert a date string into a Unix timestamp using the format string
resolveCustomModifiers ( string $strDate ) : string Resolve the custom modifiers

Method Details

__construct() public method

Set the object properties
public __construct ( integer $strDate = null, string $strFormat = null )
$strDate integer An optional date string
$strFormat string An optional format string

__get() public method

Return an object property
public __get ( string $strKey ) : mixed | null
$strKey string The property name
return mixed | null The property value

createDateRanges() protected method

Create the date ranges
protected createDateRanges ( )

dateToUnix() protected method

Convert a date string into a Unix timestamp using the format string
protected dateToUnix ( )

floorToMinute() public static method

Round a UNIX timestamp to the full minute
public static floorToMinute ( integer $intTime = null ) : integer
$intTime integer The timestamp
return integer The rounded timestamp

formatToJs() public static method

Convert a PHP format string into a JavaScript format string
public static formatToJs ( string $strFormat ) : mixed
$strFormat string The PHP format string
return mixed The JavaScript format string

getFormatFromRgxp() public static method

Return a numeric format string depending on the regular expression name
public static getFormatFromRgxp ( string $strRgxp ) : string
$strRgxp string The regular expression name
return string The numeric format string

getInputFormat() public static method

Return an input format string for a particular date (e.g. YYYY-MM-DD)
public static getInputFormat ( string $strFormat = null ) : string
$strFormat string An optional format string
return string The input format string

getNumericDateFormat() public static method

Return the numeric date format string
public static getNumericDateFormat ( ) : string
return string The numeric date format string

getNumericDatimFormat() public static method

Return the numeric datim format string
public static getNumericDatimFormat ( ) : string
return string The numeric datim format string

getNumericTimeFormat() public static method

Return the numeric time format string
public static getNumericTimeFormat ( ) : string
return string The numeric time format string

getRegexp() public static method

Return a regular expression to check a date
public static getRegexp ( string $strFormat = null ) : string
$strFormat string An optional format string
return string The regular expression string

getWeekBegin() public method

Return the begin of the week as timestamp
public getWeekBegin ( integer $intStartDay ) : integer
$intStartDay integer The week start day
return integer The Unix timestamp

getWeekEnd() public method

Return the end of the week as timestamp
public getWeekEnd ( integer $intStartDay ) : integer
$intStartDay integer The week start day
return integer The Unix timestamp

isNumericFormat() public static method

Check for a numeric date format
public static isNumericFormat ( string $strFormat ) : boolean
$strFormat string The PHP format string
return boolean True if the date format is numeric

parse() public static method

Parse a date format string and translate textual representations
public static parse ( string $strFormat, integer $intTstamp = null ) : string
$strFormat string The date format string
$intTstamp integer An optional timestamp
return string The textual representation of the date

resolveCustomModifiers() protected static method

Resolve the custom modifiers
protected static resolveCustomModifiers ( string $strDate ) : string
$strDate string The date string
return string The resolved date string

Property Details

$arrRange protected_oe property

Date range
protected array $arrRange
return array

$strDate protected_oe property

Date string
protected int $strDate
return integer

$strFormat protected_oe property

Format string
protected string $strFormat
return string