Documentation

DateFormatter
in package

Table of Contents

Constants

DATE_FORMAT_REPLACEMENTS  = [ // first remove escapes related to non-format characters '\\' => '', // 12-hour suffix 'am/pm' => 'A', // 4-digit year 'e' => 'Y', 'yyyy' => 'Y', // 2-digit year 'yy' => 'y', // first letter of month - no php equivalent 'mmmmm' => 'M', // full month name 'mmmm' => 'F', // short month name 'mmm' => 'M', // mm is minutes if time, but can also be month w/leading zero // so we try to identify times be the inclusion of a : separator in the mask // It isn't perfect, but the best way I know how ':mm' => ':i', 'mm:' => 'i:', // full day of week name 'dddd' => 'l', // short day of week name 'ddd' => 'D', // days leading zero 'dd' => 'd', // days no leading zero 'd' => 'j', // fractional seconds - no php equivalent '.s' => '', ]
Search/replace values to convert Excel date/time format masks to PHP format masks.
DATE_FORMAT_REPLACEMENTS12  = [ 'hh' => 'h', 'h' => 'g', // month leading zero 'mm' => 'm', // month no leading zero 'm' => 'n', // seconds 'ss' => 's', ]
Search/replace values to convert Excel date/time format masks hours to PHP format masks (12 hr clock).
DATE_FORMAT_REPLACEMENTS24  = [ 'hh' => 'H', 'h' => 'G', // month leading zero 'mm' => 'm', // month no leading zero 'm' => 'n', // seconds 'ss' => 's', ]
Search/replace values to convert Excel date/time format masks hours to PHP format masks (24 hr clock).
HOURS_IN_DAY  = 24
INTERVAL_LEADING_ZERO  = ['[hh]', '[mm]', '[ss]']
INTERVAL_MULTIPLIER  = ['[h]' => self::HOURS_IN_DAY, '[hh]' => self::HOURS_IN_DAY, '[m]' => self::MINUTES_IN_DAY, '[mm]' => self::MINUTES_IN_DAY, '[s]' => self::SECONDS_IN_DAY, '[ss]' => self::SECONDS_IN_DAY]
INTERVAL_PRECISION  = 10
INTERVAL_ROUND_PRECISION  = [ // hours and minutes truncate '[h]' => self::INTERVAL_PRECISION, '[hh]' => self::INTERVAL_PRECISION, '[m]' => self::INTERVAL_PRECISION, '[mm]' => self::INTERVAL_PRECISION, // seconds round '[s]' => 0, '[ss]' => 0, ]
MINUTES_IN_DAY  = 60 * self::HOURS_IN_DAY
SECONDS_IN_DAY  = 60 * self::MINUTES_IN_DAY

Methods

format()  : string
escapeQuotesCallback()  : string
setLowercaseCallback()  : string
tryInterval()  : void

Constants

DATE_FORMAT_REPLACEMENTS

Search/replace values to convert Excel date/time format masks to PHP format masks.

private mixed DATE_FORMAT_REPLACEMENTS = [ // first remove escapes related to non-format characters '\\' => '', // 12-hour suffix 'am/pm' => 'A', // 4-digit year 'e' => 'Y', 'yyyy' => 'Y', // 2-digit year 'yy' => 'y', // first letter of month - no php equivalent 'mmmmm' => 'M', // full month name 'mmmm' => 'F', // short month name 'mmm' => 'M', // mm is minutes if time, but can also be month w/leading zero // so we try to identify times be the inclusion of a : separator in the mask // It isn't perfect, but the best way I know how ':mm' => ':i', 'mm:' => 'i:', // full day of week name 'dddd' => 'l', // short day of week name 'ddd' => 'D', // days leading zero 'dd' => 'd', // days no leading zero 'd' => 'j', // fractional seconds - no php equivalent '.s' => '', ]

DATE_FORMAT_REPLACEMENTS12

Search/replace values to convert Excel date/time format masks hours to PHP format masks (12 hr clock).

private mixed DATE_FORMAT_REPLACEMENTS12 = [ 'hh' => 'h', 'h' => 'g', // month leading zero 'mm' => 'm', // month no leading zero 'm' => 'n', // seconds 'ss' => 's', ]

DATE_FORMAT_REPLACEMENTS24

Search/replace values to convert Excel date/time format masks hours to PHP format masks (24 hr clock).

private mixed DATE_FORMAT_REPLACEMENTS24 = [ 'hh' => 'H', 'h' => 'G', // month leading zero 'mm' => 'm', // month no leading zero 'm' => 'n', // seconds 'ss' => 's', ]

INTERVAL_LEADING_ZERO

private mixed INTERVAL_LEADING_ZERO = ['[hh]', '[mm]', '[ss]']

INTERVAL_MULTIPLIER

private mixed INTERVAL_MULTIPLIER = ['[h]' => self::HOURS_IN_DAY, '[hh]' => self::HOURS_IN_DAY, '[m]' => self::MINUTES_IN_DAY, '[mm]' => self::MINUTES_IN_DAY, '[s]' => self::SECONDS_IN_DAY, '[ss]' => self::SECONDS_IN_DAY]

INTERVAL_ROUND_PRECISION

private mixed INTERVAL_ROUND_PRECISION = [ // hours and minutes truncate '[h]' => self::INTERVAL_PRECISION, '[hh]' => self::INTERVAL_PRECISION, '[m]' => self::INTERVAL_PRECISION, '[mm]' => self::INTERVAL_PRECISION, // seconds round '[s]' => 0, '[ss]' => 0, ]

MINUTES_IN_DAY

private mixed MINUTES_IN_DAY = 60 * self::HOURS_IN_DAY

SECONDS_IN_DAY

private mixed SECONDS_IN_DAY = 60 * self::MINUTES_IN_DAY

Methods

format()

public static format(float|int $value, string $format) : string
Parameters
$value : float|int

value to be formatted

$format : string
Return values
string

escapeQuotesCallback()

private static escapeQuotesCallback(array<string|int, mixed> $matches) : string
Parameters
$matches : array<string|int, mixed>
Return values
string

setLowercaseCallback()

private static setLowercaseCallback(array<string|int, mixed> $matches) : string
Parameters
$matches : array<string|int, mixed>
Return values
string

tryInterval()

private static tryInterval(bool &$seekingBracket, string &$block, mixed $value, string $format) : void
Parameters
$seekingBracket : bool
$block : string
$value : mixed
$format : string

        
On this page

Search results