ICanBoogie/CLDR v1.5.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • CLDR

Classes

  • Calendar
  • CalendarCollection
  • Currency
  • CurrencyCollection
  • CurrencyFormatter
  • DateFormatter
  • DateTimeFormatter
  • FileProvider
  • ListFormatter
  • Locale
  • LocaleCollection
  • LocalizedCurrency
  • LocalizedDateTime
  • LocalizedListFormatter
  • LocalizedLocale
  • LocalizedNumberFormatter
  • LocalizedObject
  • LocalizedObjectWithFormatter
  • LocalizedTerritory
  • NumberFormatter
  • NumberPattern
  • NumberPatternParser
  • Numbers
  • ProviderCollection
  • RedisProvider
  • Repository
  • RunTimeProvider
  • Supplemental
  • Territory
  • TerritoryCollection
  • TimeFormatter
  • WebProvider

Interfaces

  • Exception
  • Formatter
  • LocalizeAwareInterface
  • Provider

Traits

  • CodePropertyTrait
  • CollectionTrait
  • LocalePropertyTrait
  • ProviderStorageBinding
  • RepositoryPropertyTrait

Exceptions

  • ResourceNotFound
  • TerritoryNotDefined

Class DateTimeFormatter

Provides date and time localization.

The class allows you to format dates and times in a locale-sensitive manner using Unicode format patterns.

ICanBoogie\CLDR\DateTimeFormatter implements ICanBoogie\CLDR\Formatter uses ICanBoogie\Accessor\AccessorTrait (not available)

Direct known subclasses

ICanBoogie\CLDR\DateFormatter, ICanBoogie\CLDR\TimeFormatter

Namespace: ICanBoogie\CLDR
Located at DateTimeFormatter.php

Methods summary

protected static array
# tokenize( string $pattern )

Parses the datetime format pattern.

Parses the datetime format pattern.

Parameters

$pattern
The pattern to be parsed.

Returns

array
Tokenized parsing result.
protected ICanBoogie\CLDR\Calendar
# get_calendar( )

Returns

ICanBoogie\CLDR\Calendar
public
# __construct( ICanBoogie\CLDR\Calendar $calendar )

Initializes the ICanBoogie\CLDR\DateTimeFormatter::$calendar property.

Initializes the ICanBoogie\CLDR\DateTimeFormatter::$calendar property.

Parameters

$calendar
public string
# __invoke( mixed $datetime, string $pattern_or_width_or_skeleton )

Alias to the ICanBoogie\CLDR\DateTimeFormatter::format() method.

Alias to the ICanBoogie\CLDR\DateTimeFormatter::format() method.

Parameters

$datetime
$pattern_or_width_or_skeleton

Returns

string
public string
# format( DateTimeInterface|string|integer $datetime, string $pattern_or_width_or_skeleton )

Formats a date according to a pattern.

Formats a date according to a pattern.

<?php

$datetime_formatter = $repository->locales['en']->calendar->datetime_formatter;
$datetime = '2013-11-02 22:23:45';

echo $datetime_formatter($datetime, "MMM d, y");                 // November 2, 2013 at 10:23:45 PM
echo $datetime_formatter($datetime, "MMM d, y 'at' hh:mm:ss a"); // November 2, 2013 at 10:23:45 PM
echo $datetime_formatter($datetime, 'full');                     // Saturday, November 2, 2013 at 10:23:45 PM CET
echo $datetime_formatter($datetime, 'long');                     // November 2, 2013 at 10:23:45 PM CET
echo $datetime_formatter($datetime, 'medium');                   // Nov 2, 2013, 10:23:45 PM
echo $datetime_formatter($datetime, 'short');                    // 11/2/13, 10:23 PM
echo $datetime_formatter($datetime, ':Ehm');                     // Sat 10:23 PM

Parameters

$datetime
The datetime to format.
$pattern_or_width_or_skeleton

The datetime can be formatted using a pattern, a width or a skeleton. The following width are defined: "full", "long", "medium" and "short". To format the datetime using a so-called "skeleton", the skeleton identifier must be prefixed with the colon sign ":" e.g. ":Ehm". The skeleton identifies the patterns defined under availableFormats.

Returns

string
The formatted date time.

See

http://www.unicode.org/reports/tr35/#Date_Format_Patterns
protected string
# resolve_pattern( string $pattern_or_width_or_skeleton )

Resolves the specified pattern, which can be a width, a skeleton or an actual pattern.

Resolves the specified pattern, which can be a width, a skeleton or an actual pattern.

Parameters

$pattern_or_width_or_skeleton

Returns

string
protected string
# resolve_width( string $pattern_or_width_or_skeleton, string $from )

Resolves widths (full, long, medium, short) into a pattern.

Resolves widths (full, long, medium, short) into a pattern.

Parameters

$pattern_or_width_or_skeleton
$from
Width Source e.g. "timeFormats".

Returns

string
protected string
# format_era( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Era - Replaced with the Era string for the current date. One to three letters for the abbreviated form, four letters for the long form, five for the narrow form. [1..3,4,5]

Era - Replaced with the Era string for the current date. One to three letters for the abbreviated form, four letters for the long form, five for the narrow form. [1..3,4,5]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
era
protected string
# format_year( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Year. Normally the length specifies the padding, but for two letters it also specifies the maximum length. [1..n]

Year. Normally the length specifies the padding, but for two letters it also specifies the maximum length. [1..n]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
formatted year
protected string
# format_quarter( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Quarter - Use one or two "Q" for the numerical quarter, three for the abbreviation, or four for the full (wide) name. [1..2,3,4]

Quarter - Use one or two "Q" for the numerical quarter, three for the abbreviation, or four for the full (wide) name. [1..2,3,4]

Parameters

$datetime
Datetime.
$pattern
Pattern.
$length
Number of repetition.

Returns

string
protected string
# format_standalone_quarter( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Stand-Alone Quarter - Use one or two "q" for the numerical quarter, three for the abbreviation, or four for the full (wide) name. [1..2,3,4]

Stand-Alone Quarter - Use one or two "q" for the numerical quarter, three for the abbreviation, or four for the full (wide) name. [1..2,3,4]

Parameters

$datetime
Datetime.
$pattern
a pattern.
$length
Number of repetition.

Returns

string
protected string
# format_month( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Month - Use one or two "M" for the numerical month, three for the abbreviation, four for the full name, or five for the narrow name. [1..2,3,4,5]

Month - Use one or two "M" for the numerical month, three for the abbreviation, four for the full name, or five for the narrow name. [1..2,3,4,5]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
protected string
# format_standalone_month( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Stand-Alone Month - Use one or two "L" for the numerical month, three for the abbreviation, or four for the full (wide) name, or 5 for the narrow name. [1..2,3,4,5]

Stand-Alone Month - Use one or two "L" for the numerical month, three for the abbreviation, or four for the full (wide) name, or 5 for the narrow name. [1..2,3,4,5]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
formatted month.
protected integer
# format_week_of_year( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Week of Year. [1..2]

Week of Year. [1..2]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

integer
protected integer|false
# format_week_of_month( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Week of Month. [1]

Week of Month. [1]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

integer|false
Week of month, of false if $length is greater than 1.
protected string
# format_day_of_month( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Date - Day of the month. [1..2]

Date - Day of the month. [1..2]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
day of the month
protected string
# format_day_of_year( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Day of year. [1..3]

Day of year. [1..3]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
protected integer|false
# format_day_of_week_in_month( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Day of Week in Month. The example is for the 2nd Wed in July. [1]

Day of Week in Month. The example is for the 2nd Wed in July. [1]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

integer|false
Day of week in month, or false if $length is greater than 1.
protected string
# format_day_in_week( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern )

Day of week - Use one through three letters for the short day, or four for the full name, five for the narrow name, or six for the short name. [1..3,4,5,6]

Day of week - Use one through three letters for the short day, or four for the full name, five for the narrow name, or six for the short name. [1..3,4,5,6]

Parameters

$datetime
$pattern
a pattern.

Returns

string
protected string
# format_period( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

AM or PM. [1]

AM or PM. [1]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
AM or PM designator
protected string
# format_hour12( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match a 24-hour-cycle format (H or k). Use hh for zero padding. [1..2]

Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match a 24-hour-cycle format (H or k). Use hh for zero padding. [1..2]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
protected string
# format_hour24( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a 12-hour-cycle format (h or K). Use HH for zero padding. [1..2]

Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a 12-hour-cycle format (h or K). Use HH for zero padding. [1..2]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
protected integer
# format_hour_in_period( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding. [1..2]

Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding. [1..2]

Parameters

$datetime
$pattern
A pattern.
$length
Number of repetition.

Returns

integer
hours in AM/PM format.
protected integer
# format_hour_in_day( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding. [1..2]

Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding. [1..2]

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

integer
protected string
# format_minutes( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Minute. Use one or two "m" for zero padding.

Minute. Use one or two "m" for zero padding.

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition

Returns

string
minutes.
protected string
# format_seconds( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Second. Use one or two "s" for zero padding.

Second. Use one or two "s" for zero padding.

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
seconds
protected string
# format_timezone( ICanBoogie\CLDR\DateTimeAccessor $datetime, string $pattern, integer $length )

Time Zone.

Time Zone.

Parameters

$datetime
$pattern
a pattern.
$length
Number of repetition.

Returns

string
time zone

Properties summary

protected static array $formatters

Pattern characters mapping to the corresponding translator methods.

Pattern characters mapping to the corresponding translator methods.

# [ 'G' => 'format_era', 'y' => 'format_year', // 'Y' => Year (in "Week of Year" based calendars). // 'u' => Extended year. 'Q' => 'format_quarter', 'q' => 'format_standalone_quarter', 'M' => 'format_month', 'L' => 'format_standalone_month', // 'l' => Special symbol for Chinese leap month, used in combination with M. Only used with the Chinese calendar. 'w' => 'format_week_of_year', 'W' => 'format_week_of_month', 'd' => 'format_day_of_month', 'D' => 'format_day_of_year', 'F' => 'format_day_of_week_in_month', 'h' => 'format_hour12', 'H' => 'format_hour24', 'm' => 'format_minutes', 's' => 'format_seconds', 'E' => 'format_day_in_week', 'c' => 'format_day_in_week', 'e' => 'format_day_in_week', 'a' => 'format_period', 'k' => 'format_hour_in_day', 'K' => 'format_hour_in_period', 'z' => 'format_timezone', 'Z' => 'format_timezone', 'v' => 'format_timezone' ]
protected ICanBoogie\CLDR\Calendar $calendar

The calendar used to format the datetime.

The calendar used to format the datetime.

#

Magic properties

public read-only ICanBoogie\CLDR\Calendar $calendar

The calendar used by the formatter.

ICanBoogie/CLDR v1.5.0 API documentation generated by ApiGen