class DatesReader (View source)

A reader for data placed in "dates" tag in CLDR.

This is not full implementation of features from CLDR. These are missing:

  • support for other calendars than Gregorian
  • some data from "dates" tag is not used (fields, timeZoneNames)

Constants

FORMAT_TYPE_DATE

Constant for date-only format

FORMAT_TYPE_TIME

Constant for time-only format

FORMAT_TYPE_DATETIME

Constant for date and time format

FORMAT_LENGTH_DEFAULT

Constant for default length

FORMAT_LENGTH_FULL

Constant for full length

FORMAT_LENGTH_LONG

Constant for long length

FORMAT_LENGTH_MEDIUM

Constant for medium length

FORMAT_LENGTH_SHORT

Constant for short length

Properties

protected CldrRepository $cldrRepository
protected VariableFrontend $cache
static protected array $maxLengthOfSubformats

Static array of date / time formatters supported by this class, and maximal lengths particular formats can get.

protected array $parsedFormats

An array of parsed formats, indexed by format strings.

protected array $parsedFormatsIndices

An array which stores references to formats used by particular locales.

protected array $localizedLiterals

Associative array of literals used in particular locales.

Methods

void
injectCldrRepository(CldrRepository $repository)

No description

void
injectCache(VariableFrontend $cache)

Injects the Flow_I18n_Cldr_Reader_DatesReader cache

void
initializeObject()

Constructs the reader, loading parsed data from cache if available.

void
shutdownObject()

Shutdowns the object, saving parsed format strings to the cache.

array
parseFormatFromCldr(Locale $locale, string $formatType, string $formatLength)

Returns parsed date or time format basing on locale and desired format length.

array
parseCustomFormat(string $format)

Returns parsed date or time format string provided as parameter.

array
getLocalizedLiteralsForLocale(Locale $locale)

Returns literals array for locale provided.

static void
validateFormatType(string $formatType)

Validates provided format type and throws exception if value is not allowed.

static void
validateFormatLength(string $formatLength)

Validates provided format length and throws exception if value is not allowed.

array
parseFormat(string $format)

Parses a date / time format (with syntax defined in CLDR).

array
parseLocalizedLiterals(CldrModel $model, string $literalType)

Parses one CLDR child of "dates" node and returns it's array representation.

array
parseLocalizedEras(CldrModel $model)

Parses "eras" child of "dates" node and returns it's array representation.

array
prepareDateAndTimeFormat(string $format, Locale $locale, string $formatLength)

Creates one parsed datetime format from date and time formats merged together.

Details

void injectCldrRepository(CldrRepository $repository)

No description

Parameters

CldrRepository $repository

Return Value

void

void injectCache(VariableFrontend $cache)

Injects the Flow_I18n_Cldr_Reader_DatesReader cache

Parameters

VariableFrontend $cache

Return Value

void

void initializeObject()

Constructs the reader, loading parsed data from cache if available.

Return Value

void

void shutdownObject()

Shutdowns the object, saving parsed format strings to the cache.

Return Value

void

Exceptions

Exception

array parseFormatFromCldr(Locale $locale, string $formatType, string $formatLength)

Returns parsed date or time format basing on locale and desired format length.

When third parameter ($formatLength) equals 'default', default format for a locale will be used.

make default format reading nicer

Parameters

Locale $locale
string $formatType

A type of format (one of constant values)

string $formatLength

A length of format (one of constant values)

Return Value

array

An array representing parsed format

Exceptions

InvalidDateTimeFormatException
InvalidFormatLengthException
InvalidFormatTypeException
UnableToFindFormatException

array parseCustomFormat(string $format)

Returns parsed date or time format string provided as parameter.

Parameters

string $format

Format string to parse

Return Value

array

An array representing parsed format

Exceptions

InvalidDateTimeFormatException

array getLocalizedLiteralsForLocale(Locale $locale)

Returns literals array for locale provided.

If array was not generated earlier, it will be generated and cached.

Parameters

Locale $locale

Return Value

array

An array with localized literals

static void validateFormatType(string $formatType)

Validates provided format type and throws exception if value is not allowed.

Parameters

string $formatType

Return Value

void

Exceptions

InvalidFormatTypeException

static void validateFormatLength(string $formatLength)

Validates provided format length and throws exception if value is not allowed.

Parameters

string $formatLength

Return Value

void

Exceptions

InvalidFormatLengthException

protected array parseFormat(string $format)

Parses a date / time format (with syntax defined in CLDR).

Not all features from CLDR specification are implemented. Please see the documentation for this class for details what is missing.

Parameters

string $format

Return Value

array

Parsed format

Exceptions

InvalidDateTimeFormatException

See also

DatesReader::$parsedFormats

protected array parseLocalizedLiterals(CldrModel $model, string $literalType)

Parses one CLDR child of "dates" node and returns it's array representation.

Many children of "dates" node have common structure, so one method can be used to parse them all.

the two array checks should go away - but that needs clean input data

Parameters

CldrModel $model

CldrModel to read data from

string $literalType

One of: month, day, quarter, dayPeriod

Return Value

array

An array with localized literals for given type

protected array parseLocalizedEras(CldrModel $model)

Parses "eras" child of "dates" node and returns it's array representation.

Parameters

CldrModel $model

CldrModel to read data from

Return Value

array

An array with localized literals for "eras" node

protected array prepareDateAndTimeFormat(string $format, Locale $locale, string $formatLength)

Creates one parsed datetime format from date and time formats merged together.

The dateTime format from CLDR looks like "{0} {1}" and denotes where to place time and date, and what literals should be placed before, between and / or after them.

Parameters

string $format

DateTime format

Locale $locale

Locale to use

string $formatLength

A length of format (full, long, medium, short) or 'default' to use default one from CLDR

Return Value

array

Merged formats of date and time

Exceptions

InvalidDateTimeFormatException
InvalidFormatLengthException
InvalidFormatTypeException
UnableToFindFormatException