PHP Class Prado\I18N\core\DateFormat

The DateFormat class allows you to format dates and times with predefined styles in a locale-sensitive manner. Formatting times with the DateFormat class is similar to formatting dates. Formatting dates with the DateFormat class is a two-step process. First, you create a formatter with the getDateInstance method. Second, you invoke the format method, which returns a string containing the formatted date. DateTime values are formatted using standard or custom patterns stored in the properties of a DateTimeFormatInfo.
Show file Open project: pradosoft/prado Class Usage Examples

Protected Properties

Property Type Description
$formatInfo DateTimeFormatInfo The DateTimeFormatInfo, containing culture specific patterns and names.
$methods array A list of methods, to be used by the token function calls.
$tokens array A list of tokens and their function call.

Public Methods

Method Description
__construct ( $formatInfo = null ) : DateFormat Initialize a new DateFormat.
format ( $time, $pattern = 'F', $charset = 'UTF-8' ) : string Format a date according to the pattern.

Protected Methods

Method Description
getAMPM ( $date, $pattern = 'a' ) : string Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.
getDay ( $date, $pattern = 'd' ) : string Get the day of the month.
getDayInMonth ( $date, $pattern = 'FF' ) : integer Get day in the month.
getDayInWeek ( $date, $pattern = 'EEEE' ) : string Get the day of the week.
getDayInYear ( $date, $pattern = 'D' ) : integer Get the day in the year, e.g. [1-366]
getEra ( $date, $pattern = 'G' ) : string Get the era. i.e. in gregorian, year > 0 is AD, else BC.
getFunctionName ( $token ) : mixed For a particular token, get the corresponding function to call.
getHour12 ( $date, $pattern = 'h' ) : string Get the hours in 12 hour format.
getHour24 ( $date, $pattern = 'H' ) : string Get the hours in 24 hour format, i.e. [0-23].
getHourInAMPM ( $date, $pattern = 'K' ) : integer Get the hours in AM/PM format, e.g [1-12]
getHourInDay ( $date, $pattern = 'k' ) : integer Get the hours [1-24].
getMinutes ( $date, $pattern = 'm' ) : string Get the minutes.
getMonth ( $date, $pattern = 'M' ) : string Get the month.
getPattern ( $pattern ) : string Get the pattern from DateTimeFormatInfo or some predefined patterns.
getSeconds ( $date, $pattern = 's' ) : string Get the seconds.
getTimeZone ( $date, $pattern = 'z' ) : string Get the timezone from the server machine.
getTokens ( $pattern ) : array Tokenize the pattern. The tokens are delimited by group of similar characters, e.g. 'aabb' will form 2 tokens of 'aa' and 'bb'.
getWeekInMonth ( $date, $pattern = 'W' ) : integer Get week in the month.
getWeekInYear ( $date, $pattern = 'w' ) : integer Get the week in the year.
getYear ( $date, $pattern = 'yyyy' ) : string Get the year.

Method Details

__construct() public method

Initialize a new DateFormat.
public __construct ( $formatInfo = null ) : DateFormat
return DateFormat instance

format() public method

Format a date according to the pattern.
public format ( $time, $pattern = 'F', $charset = 'UTF-8' ) : string
return string formatted date time.

getAMPM() protected method

Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.
protected getAMPM ( $date, $pattern = 'a' ) : string
return string AM or PM designator

getDay() protected method

"d" for non-padding, "dd" will always return 2 characters.
protected getDay ( $date, $pattern = 'd' ) : string
return string day of the month

getDayInMonth() protected method

Get day in the month.
protected getDayInMonth ( $date, $pattern = 'FF' ) : integer
return integer day in month

getDayInWeek() protected method

"E" will return integer 0 (for Sunday) through 6 (for Saturday). "EE" will return the narrow day of the week, e.g. "M" "EEE" will return the abrreviated day of the week, e.g. "Mon" "EEEE" will return the day of the week, e.g. "Monday"
protected getDayInWeek ( $date, $pattern = 'EEEE' ) : string
return string day of the week.

getDayInYear() protected method

Get the day in the year, e.g. [1-366]
protected getDayInYear ( $date, $pattern = 'D' ) : integer
return integer hours in AM/PM format.

getEra() protected method

Get the era. i.e. in gregorian, year > 0 is AD, else BC.
protected getEra ( $date, $pattern = 'G' ) : string
return string era

getFunctionName() protected method

For a particular token, get the corresponding function to call.
protected getFunctionName ( $token ) : mixed
return mixed the function if good token, null otherwise.

getHour12() protected method

"h" for non-padding, "hh" will always return 2 characters.
protected getHour12 ( $date, $pattern = 'h' ) : string
return string hours in 12 hour format.

getHour24() protected method

"H" for non-padding, "HH" will always return 2 characters.
protected getHour24 ( $date, $pattern = 'H' ) : string
return string hours in 24 hour format.

getHourInAMPM() protected method

Get the hours in AM/PM format, e.g [1-12]
protected getHourInAMPM ( $date, $pattern = 'K' ) : integer
return integer hours in AM/PM format.

getHourInDay() protected method

Get the hours [1-24].
protected getHourInDay ( $date, $pattern = 'k' ) : integer
return integer hours [1-24]

getMinutes() protected method

"m" for non-padding, "mm" will always return 2 characters.
protected getMinutes ( $date, $pattern = 'm' ) : string
return string minutes.

getMonth() protected method

"M" will return integer 1 through 12 "MM" will return the narrow month name, e.g. "J" "MMM" will return the abrreviated month name, e.g. "Jan" "MMMM" will return the month name, e.g. "January"
protected getMonth ( $date, $pattern = 'M' ) : string
return string month name

getPattern() protected method

If the $pattern parameter is an array of 2 element, it will assume that the first element is the date, and second the time and try to find an appropriate pattern and apply DateTimeFormatInfo::formatDateTime See the tutorial documentation for futher details on the patterns.
See also: DateTimeFormatInfo::formatDateTime()
protected getPattern ( $pattern ) : string
return string a pattern.

getSeconds() protected method

"s" for non-padding, "ss" will always return 2 characters.
protected getSeconds ( $date, $pattern = 's' ) : string
return string seconds

getTimeZone() protected method

Get the timezone from the server machine.
protected getTimeZone ( $date, $pattern = 'z' ) : string
return string time zone

getTokens() protected method

Any substrings, starting and ending with a single quote (') will be treated as a single token.
protected getTokens ( $pattern ) : array
return array string tokens in an array.

getWeekInMonth() protected method

Get week in the month.
protected getWeekInMonth ( $date, $pattern = 'W' ) : integer
return integer week in month

getWeekInYear() protected method

Get the week in the year.
protected getWeekInYear ( $date, $pattern = 'w' ) : integer
return integer week in year

getYear() protected method

"yy" will return the last two digits of year. "yyyy" will return the full integer year.
protected getYear ( $date, $pattern = 'yyyy' ) : string
return string year

Property Details

$formatInfo protected property

The DateTimeFormatInfo, containing culture specific patterns and names.
protected DateTimeFormatInfo,Prado\I18N\core $formatInfo
return DateTimeFormatInfo

$methods protected property

A list of methods, to be used by the token function calls.
protected array $methods
return array

$tokens protected property

A list of tokens and their function call.
protected array $tokens
return array