Helper methods to generate locale sensitive output.

package XenForo_Core

 Methods

Formats the given timestamp as a date.

date(integer | \DateTime $timestamp, string $format, array $language, string | null $timeZoneString) : string
Static

Parameters

$timestamp

integer\DateTime

Unix timestamp or a DateTime object that's already configured

$format

string

Format that maps to a known type. Uses default if specified. (Currently ignored.)

$language

arraynull

Info about language to override default

$timeZoneString

stringnull

String time zone to override default

Returns

string

Formats the given timestamp as a date and a time.

dateTime(integer | \DateTime $timestamp, string $format, array $language, string | null $timeZoneString) : string | array
Static

Parameters

$timestamp

integer\DateTime

Unix timestamp or a DateTime object that's already configured

$format

string

Format that maps to a known type. Uses default if specified.

$language

arraynull

Info about language to override default

$timeZoneString

stringnull

String time zone to override default

Returns

stringarrayIf format 'separate' is specified, returns [dateString, date, time]

Fetches timestamps for the start of today, yesterday or a week ago

getDayStartTimestamps() : array
Static

Returns

array[now => long, today => long, todayDow => long, yesterday => long, week => long]

Gets the default time zone.

getDefaultTimeZone() : \DateTimeZone | null
Static

Returns

Gets a date formatted in the requested format.

getFormattedDate(integer | \DateTime $timestamp, string $format, array $language, string | null $timeZoneString) : string
Static

Parameters

$timestamp

integer\DateTime

Unix timestamp or a DateTime object that's already configured

$format

string

Format to display as; compatible with sub-set of date() options

$language

arraynull

Language (if overriding default)

$timeZoneString

stringnull

Time zone user is in (if overriding default)

Returns

string

Gets the formatted date/time using the given format.

getFormattedDateInternal(\DateTime $date, string $format, array $phrases) : string
Static

String-based identifiers (months, days of week) need to be passed in.

Parameters

$date

\DateTime

DateTime object, with correct time set

$format

string

Format to display as; supports a subset of the formats from the built-in date() function

$phrases

array

List of phrases that will be used to replace string-based identifiers

Returns

stringFormatted date

Returns a string representing the given date as today, yesterday, dayname (within this past week)

getRelativeDate(\DateTime $date, array $phrases) : string | false
Static

Parameters

$date

\DateTime

$phrases

array

Returns

stringfalse

Returns a string representing the given date and time as a relative period before now, in certain circumstances

getRelativeDateTime(\DateTime $date, string $timeFormat, array $phrases) : string | false
Static

Parameters

$date

\DateTime

$timeFormat

string

$phrases

array

Returns

stringfalse

Gets the current timezone offset from UTC in seconds

getTimeZoneOffset() : integer
Static

Returns

integer

Formats the given number for a language/locale.

numberFormat(float | integer $number, integer | string $precision, array $language) : string
Static

Also used for file size formatting.

Parameters

$number

floatinteger

Number to format

$precision

integerstring

Number of places to show after decimal point or word "size" for file size

$language

arraynull

Language to override default

Returns

stringFormatted number

Set the default language information and time zone (optionally).

setDefaultLanguage(array $language, string | null $timeZoneString) 
Static

Parameters

$language

array

$timeZoneString

stringnull

String time zone (eg, Europe/London)

Sets the default time zone.

setDefaultTimeZone(string $timeZoneString) 
Static

Parameters

$timeZoneString

string

String time zone (eg, Europe/London);

Formats the given timestamp as a time.

time(integer | \DateTime $timestamp, string $format, array $language, string | null $timeZoneString) : string
Static

Parameters

$timestamp

integer\DateTime

Unix timestamp or a DateTime object that's already configured

$format

string

Format that maps to a known type. Uses default if specified. (Currently ignored.)

$language

arraynull

Info about language to override default

$timeZoneString

stringnull

String time zone to override default

Returns

string

Gets a date object that fits the requirements (correct timestamp and time zone).

_getDateObject(integer | \DateTime | null $timestamp, string | null $timeZoneString) : \DateTime
Static

Parameters

$timestamp

integer\DateTimenull

Unix timestamp or a DateTime object that's already configured

$timeZoneString

stringnull

String time zone. If null, uses default (and can use date object optimization if available)

Returns

Private constructor.

__construct() 

Use this class statically.

 Properties

 

$_dateObj : \DateTime | null

This will be set only if setTimestamp exists on it (PHP 5.3 and newer). This serves as an optimization to avoid object creation and date parsing overhead.

 

$_dayStartTimestamps 
 

$_dowTranslation : array
 

$_language : array
 

$_timeZone : \DateTimeZone | null