Punic APIs
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • Punic
    • Exception

Classes

  • Calendar
  • Comparer
  • Currency
  • Data
  • Language
  • Misc
  • Number
  • Phone
  • Plural
  • Territory
  • Unit

Exceptions

  • Exception

Class Calendar

Date and time related functions.

Namespace: Punic
Located at Calendar.php

Methods summary

public static DateTime|null
# toDateTime( number|DateTime|DateTimeInterface|string $value, string|DateTimeZone $toTimezone = '', string|DateTimeZone $fromTimezone = '' )

Convert a date/time representation to a \DateTime instance.

Convert a date/time representation to a \DateTime instance.

Parameters

$value
A Unix timestamp, a \DateTimeInterface instance or a string accepted by strtotime.
$toTimezone
the timezone to set; leave empty to use the value of $fromTimezone (if it's empty we'll use the default timezone or the timezone associated to $value if it's already a \DateTimeInterface)
$fromTimezone
the original timezone of $value; leave empty to use the default timezone (or the timezone associated to $value if it's already a \DateTimeInterface)

Returns

DateTime|null
returns null if $value is empty, a \DateTime instance otherwise

Throws

Punic\Exception\BadArgumentType
throws an exception if $value is not empty and can't be converted to a \DateTime instance or if $toTimezone is not empty and is not valid

Example

Convert a Unix timestamp to a \DateTime instance with the current time zone:

\Punic\Calendar::toDateTime(1409648286);

Convert a Unix timestamp to a \DateTime instance with a specific time zone:

\Punic\Calendar::toDateTime(1409648286, 'Europe/Rome');
\Punic\Calendar::toDateTime(1409648286, new \DateTimeZone('Europe/Rome'));

Convert a string to a \DateTime instance with the current time zone:

\Punic\Calendar::toDateTime('2014-03-07 13:30');

Convert a string to a \DateTime instance with a specific time zone:

\Punic\Calendar::toDateTime('2014-03-07 13:30', 'Europe/Rome');

Please remark that in this case '2014-03-07 13:30' is converted to a \DateTime instance with the current timezone, and after we change the timezone. So, if your system default timezone is 'America/Los_Angeles' (GMT -8), the resulting date/time will be '2014-03-07 22:30 GMT+1' since it'll be converted to 'Europe/Rome' (GMT +1)


public static string
# convertPhpToIsoFormat( string $format )

Converts a format string from PHP's date format to ISO format. The following extra format chunks are introduced: - 'P': ISO-8601 numeric representation of the day of the week (same as 'e' but not locale dependent) - 'PP': Numeric representation of the day of the week, from 0 (for Sunday) to 6 (for Saturday) - 'PPP': English ordinal suffix for the day of the month - 'PPPP': The day of the year (starting from 0) - 'PPPPP': Number of days in the given month - 'PPPPPP': Whether it's a leap year: 1 if it is a leap year, 0 otherwise. - 'PPPPPPP': Lowercase Ante meridiem and Post meridiem (English only, for other locales it's the same as 'a') - 'PPPPPPPP': Swatch Internet time - 'PPPPPPPPP': Microseconds - 'PPPPPPPPPP': Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. - 'PPPPPPPPPPP': Timezone offset in seconds - 'PPPPPPPPPPPP': RFC 2822 formatted date (Example: 'Thu, 21 Dec 2000 16:01:07 +0200') - 'PPPPPPPPPPPPP': Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Converts a format string from PHP's date format to ISO format. The following extra format chunks are introduced: - 'P': ISO-8601 numeric representation of the day of the week (same as 'e' but not locale dependent) - 'PP': Numeric representation of the day of the week, from 0 (for Sunday) to 6 (for Saturday) - 'PPP': English ordinal suffix for the day of the month - 'PPPP': The day of the year (starting from 0) - 'PPPPP': Number of days in the given month - 'PPPPPP': Whether it's a leap year: 1 if it is a leap year, 0 otherwise. - 'PPPPPPP': Lowercase Ante meridiem and Post meridiem (English only, for other locales it's the same as 'a') - 'PPPPPPPP': Swatch Internet time - 'PPPPPPPPP': Microseconds - 'PPPPPPPPPP': Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. - 'PPPPPPPPPPP': Timezone offset in seconds - 'PPPPPPPPPPPP': RFC 2822 formatted date (Example: 'Thu, 21 Dec 2000 16:01:07 +0200') - 'PPPPPPPPPPPPP': Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Parameters

$format
the PHP date/time format string to convert

Returns

string
returns the ISO date/time format corresponding to the specified PHP date/time format
public static string|null
# tryConvertIsoToPhpFormat( string $isoDateTimeFormat )

Try to convert a date, time or date/time ISO format string to a PHP date/time format.

Try to convert a date, time or date/time ISO format string to a PHP date/time format.

Parameters

$isoDateTimeFormat
The PHP date/time format

Returns

string|null
if the format is not possible (the ISO placeholders are much more than the PHP ones), null will be returned
public static string
# getEraName( number|DateTime|DateTimeInterface $value, string $width = 'abbreviated', string $locale = '' )

Get the name of an era.

Get the name of an era.

Parameters

$value
the year number or the \DateTimeInterface instance for which you want the name of the era
$width
the format name; it can be 'wide' (eg 'Before Christ'), 'abbreviated' (eg 'BC') or 'narrow' (eg 'B')
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().

Returns

string
returns an empty string if $value is empty, the name of the era otherwise

Throws

Punic\Exception\BadArgumentType
throws a BadArgumentType exception if $value is not valid
Punic\Exception\ValueNotInList
throws a ValueNotInList exception if $width is not valid
Punic\Exception
throws a generic exception in case of other problems (for instance if you specify an invalid locale)
public static string
# getMonthName( number|DateTime|DateTimeInterface $value, string $width = 'wide', string $locale = '', boolean $standAlone = false )

Get the name of a month.

Get the name of a month.

Parameters

$value
the month number (1-12) or a \DateTimeInterface instance for which you want the name of the month
$width
the format name; it can be 'wide' (eg 'January'), 'abbreviated' (eg 'Jan') or 'narrow' (eg 'J')
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().
$standAlone
set to true to return the form used independently (such as in calendar header), set to false if the month name will be part of a date

Returns

string
returns an empty string if $value is empty, the name of the month otherwise

Throws

Punic\Exception\BadArgumentType
throws a BadArgumentType exception if $value is not valid
Punic\Exception\ValueNotInList
throws a ValueNotInList exception if $width is not valid
Punic\Exception
throws a generic exception in case of other problems (for instance if you specify an invalid locale)
public static string
# getWeekdayName( number|DateTime|DateTimeInterface $value, string $width = 'wide', string $locale = '', boolean $standAlone = false )

Get the name of a week day.

Get the name of a week day.

Parameters

$value
a week day number (from 0-Sunday to 6-Saturnday) or a \DateTimeInterface instance for which you want the name of the day of the week
$width
the format name; it can be 'wide' (eg 'Sunday'), 'abbreviated' (eg 'Sun'), 'short' (eg 'Su') or 'narrow' (eg 'S')
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().
$standAlone
set to true to return the form used independently (such as in calendar header), set to false if the week day name will be part of a date

Returns

string
returns an empty string if $value is empty, the name of the week day name otherwise

Throws

Punic\Exception\BadArgumentType
throws a BadArgumentType exception if $value is not valid
Punic\Exception\ValueNotInList
throws a ValueNotInList exception if $width is not valid
Punic\Exception
throws a generic exception in case of other problems (for instance if you specify an invalid locale)
public static string
# getQuarterName( number|DateTime|DateTimeInterface $value, string $width = 'wide', string $locale = '', boolean $standAlone = false )

Get the name of a quarter.

Get the name of a quarter.

Parameters

$value
a quarter number (from 1 to 4) or a \DateTimeInterface instance for which you want the name of the day of the quarter
$width
the format name; it can be 'wide' (eg '1st quarter'), 'abbreviated' (eg 'Q1') or 'narrow' (eg '1')
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().
$standAlone
set to true to return the form used independently (such as in calendar header), set to false if the quarter name will be part of a date

Returns

string
returns an empty string if $value is empty, the name of the quarter name otherwise

Throws

Punic\Exception\BadArgumentType
throws a BadArgumentType exception if $value is not valid
Punic\Exception\ValueNotInList
throws a ValueNotInList exception if $width is not valid
Punic\Exception
throws a generic exception in case of other problems (for instance if you specify an invalid locale)
public static string
# getDayperiodName( number|string|DateTime|DateTimeInterface $value, string $width = 'wide', string $locale = '', boolean $standAlone = false )

Get the name of a day period (AM/PM).

Get the name of a day period (AM/PM).

Parameters

$value
an hour (from 0 to 23), a standard period name ('am' or 'pm', lower or upper case) a \DateTimeInterface instance for which you want the name of the day period
$width
the format name; it can be 'wide' (eg 'AM'), 'abbreviated' (eg 'AM') or 'narrow' (eg 'a')
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().
$standAlone
set to true to return the form used independently (such as in calendar header), set to false if the day period name will be part of a date

Returns

string
returns an empty string if $value is empty, the name of the day period name otherwise

Throws

Punic\Exception\BadArgumentType
throws a BadArgumentType exception if $value is not valid
Punic\Exception\ValueNotInList
throws a ValueNotInList exception if $width is not valid
Punic\Exception
throws a generic exception in case of other problems (for instance if you specify an invalid locale)
public static string
# getVariableDayperiodName( number|string|DateTime|DateTimeInterface $value, string $width = 'wide', string $locale = '', boolean $standAlone = false )

Get the name of a variable day period ("morning", "afternoon", etc.).

Get the name of a variable day period ("morning", "afternoon", etc.).

The available periods, their start/end time and their names are locale-specific.

Parameters

$value
an hour (from 0 to 23), a \DateTimeInterface instance for which you want the name of the day period
$width
the format name; it can be 'wide', 'abbreviated' or 'narrow'
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().
$standAlone
set to true to return the form used independently (e.g. "morning"), set to false if the day period name will be part of a date (e.g. "in the morning")

Returns

string
returns an empty string if $value is empty, the name of the day period name otherwise

Throws

Punic\Exception\BadArgumentType
throws a BadArgumentType exception if $value is not valid
Punic\Exception\ValueNotInList
throws a ValueNotInList exception if $width is not valid
Punic\Exception
throws a generic exception in case of other problems (for instance if you specify an invalid locale)

See

http://www.unicode.org/reports/tr35/tr35-dates.html#Variable_periods
public static string
# getTimezoneNameNoLocationSpecific( string|DateTime|DateTimeInterface|DateTimeZone $value, string $width = 'long', string $kind = '', string $locale = '' )

Returns the localized name of a timezone, no location-specific.

Returns the localized name of a timezone, no location-specific.

Parameters

$value
the PHP name of a timezone, a \DateTimeInterface instance or a \DateTimeZone instance for which you want the localized timezone name
$width
the format name; it can be 'long' (eg 'Greenwich Mean Time') or 'short' (eg 'GMT')
$kind
set to 'daylight' to retrieve the daylight saving time name, set to 'standard' to retrieve the standard time, set to 'generic' to retrieve the generic name, set to '' to determine automatically the dst (if $value is \DateTime) or the generic (otherwise)
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().

Returns

string
returns an empty string if the timezone has not been found (maybe we don't have the data in the specified $width), the timezone name otherwise

Throws

Punic\Exception
throws a generic exception in case of problems (for instance if you specify an invalid locale)
public static string
# getTimezoneNameLocationSpecific( string|DateTime|DateTimeInterface|DateTimeZone $value, string $locale = '' )

Returns the localized name of a timezone, location-specific.

Returns the localized name of a timezone, location-specific.

Parameters

$value
the php name of a timezone, or a \DateTime instance or a \DateTimeZone instance for which you want the localized timezone name
$locale
The locale to use. If empty we'll use the default locale set with \Punic\Data::setDefaultLocale().

Returns

string
returns an empty string if the timezone has not been found, the timezone name otherwise

See

http://www.unicode.org/reports/tr35/tr35-dates.html#Time_Zone_Goals
public static string
# getTimezoneExemplarCity( string|DateTime|DateTimeInterface|DateTimeZone $value, boolean $returnUnknownIfNotFound = true, string $locale = '' )

Returns the localized name of an exemplar city for a specific timezone.

Returns the localized name of an exemplar city for a specific timezone.

Parameters

$value
The PHP name of a timezone, a \DateTimeInterface instance or a \DateTimeZone instance
$returnUnknownIfNotFound
true If the exemplar city is not found, shall we return the translation of 'Unknown City'?
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if the exemplar city hasn't been found and $returnUnknownIfNotFound is false
public static boolean
# has12HoursClock( string $locale = '' )

Returns true if a locale has a 12-hour clock, false if 24-hour clock.

Returns true if a locale has a 12-hour clock, false if 24-hour clock.

Parameters

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

boolean

Throws

Punic\Exception
Throws an exception in case of problems
public static integer
# getFirstWeekday( string $locale = '' )

Retrieve the first weekday for a specific locale (from 0-Sunday to 6-Saturnday).

Retrieve the first weekday for a specific locale (from 0-Sunday to 6-Saturnday).

Parameters

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

integer
Returns a number from 0 (Sunday) to 7 (Saturnday)
public static array
# getSortedWeekdays( string|false $namesWidth = false, string $locale = '' )

Returns the sorted list of weekdays, starting from Punic\Calendar::getFirstWeekday().

Returns the sorted list of weekdays, starting from Punic\Calendar::getFirstWeekday().

Parameters

$namesWidth

If false you'll get only the list of weekday identifiers (for instance: [0, 1, 2, 3, 4, 5, 6]), If it's a string it must be one accepted by Punic\Calendar::getWeekdayName(), and you'll get an array like this: [{id: 0, name: 'Monday', ..., {id: 6, name: 'Sunday'}]

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

array
public static string
# getDateFormat( string $width, string $locale = '' )

Get the ISO format for a date.

Get the ISO format for a date.

Parameters

$width

The format name; it can be 'full' (eg 'EEEE, MMMM d, y' - 'Wednesday, August 20, 2014'), 'long' (eg 'MMMM d, y' - 'August 20, 2014'), 'medium' (eg 'MMM d, y' - 'August 20, 2014') or 'short' (eg 'M/d/yy' - '8/20/14'), or a skeleton pattern prefixed by '~', e.g. '~yMd'.

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns the requested ISO format

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# getTimeFormat( string $width, string $locale = '' )

Get the ISO format for a time.

Get the ISO format for a time.

Parameters

$width

The format name; it can be 'full' (eg 'h:mm:ss a zzzz' - '11:42:13 AM GMT+2:00'), 'long' (eg 'h:mm:ss a z' - '11:42:13 AM GMT+2:00'), 'medium' (eg 'h:mm:ss a' - '11:42:13 AM') or 'short' (eg 'h:mm a' - '11:42 AM'), or a skeleton pattern prefixed by '~', e.g. '~Hm'.

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns the requested ISO format

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# getDatetimeFormat( string $width, string $locale = '' )

Get the ISO format for a date/time.

Get the ISO format for a date/time.

Parameters

$width

The format name; it can be 'full', 'long', 'medium', 'short' or a combination for date+time like 'full|short' or a combination for format+date+time like 'full|full|short', or a skeleton pattern prefixed by '~', e.g. '~yMd'.

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns the requested ISO format

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# getSkeletonFormat( string $skeleton, string $locale = '' )

Get the ISO format based on a skeleton.

Get the ISO format based on a skeleton.

Parameters

$skeleton
The locale-independent skeleton, e.g. "yMMMd" or "Hm".
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns the requested ISO format

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns#TOC-Additional-Date-Time-Formats
http://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems
public static array
# getIntervalFormat( string $skeleton, string $greatestDifference, string $locale = '' )

Get the ISO format for a date/time interval.

Get the ISO format for a date/time interval.

Parameters

$skeleton
The locale-independent skeleton, e.g. "yMMMd" or "Hm".
$greatestDifference
The calendar field with the greatest distance between the two dates. Must be one of the fields mentioned in $differenceFields.
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data.

Returns

array

an array with two entries: - string: The ISO interval format - bool|null: Whether the earliest date is the first of the two dates in the pattern, or null if the dates are identical within the granularity specified by the skeleton

Throws

Punic\Exception
Throws an exception in case of problems

See

http://www.unicode.org/reports/tr35/tr35-dates.html#intervalFormats
public static integer
# getDeltaDays( DateTime|DateTimeInterface $dateEnd, DateTime|DateTimeInterface|null $dateStart = null )

Returns the difference in days between two dates (or between a date and today).

Returns the difference in days between two dates (or between a date and today).

Parameters

$dateEnd
The first date
$dateStart
The final date (if it has a timezone different than $dateEnd, we'll use the one of $dateEnd)

Returns

integer
Returns the diffence $dateEnd - $dateStart in days

Throws

Punic\Exception\BadArgumentType
public static string
# describeInterval( DateTime|DateTimeInterface $dateEnd, DateTime|DateTimeInterface|null $dateStart = null, integer $maxParts = 2, string $width = 'short', string $locale = '' )

Describe an interval between two dates (eg '2 days and 4 hours').

Describe an interval between two dates (eg '2 days and 4 hours').

Parameters

$dateEnd
The first date
$dateStart
The final date (if it has a timezone different than $dateEnd, we'll use the one of $dateEnd)
$maxParts
The maximim parts (eg with 2 you may have '2 days and 4 hours', with 3 '2 days, 4 hours and 24 minutes')
$width
The format name; it can be 'long' (eg '3 seconds'), 'short' (eg '3 s') or 'narrow' (eg '3s')
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string

Throws

Punic\Exception\BadArgumentType
public static string
# formatDate( DateTime|DateTimeInterface $value, string $width, string $locale = '' )

Format a date.

Format a date.

Parameters

$value
The \DateTimeInterface instance for which you want the localized textual representation
$width

The format name; it can be 'full' (eg 'EEEE, MMMM d, y' - 'Wednesday, August 20, 2014'), 'long' (eg 'MMMM d, y' - 'August 20, 2014'), 'medium' (eg 'MMM d, y' - 'August 20, 2014') or 'short' (eg 'M/d/yy' - '8/20/14'), or a skeleton pattern prefixed by '~', e.g. '~yMd'. You can also append a caret ('^') or an asterisk ('') to $width. If so, special day names may be used (like 'Today', 'Yesterday', 'Tomorrow' with '^' and 'today', 'yesterday', 'tomorrow' width '') instead of the date.

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatDateEx( number|DateTime|DateTimeInterface|string $value, string $width, string|DateTimeZone $toTimezone = '', string $locale = '' )

Format a date (extended version: various date/time representations - see toDateTime()).

Format a date (extended version: various date/time representations - see toDateTime()).

Parameters

$value
A Unix timestamp, a \DateTimeInterface instance or a string accepted by strtotime.
$width

The format name; it can be 'full' (eg 'EEEE, MMMM d, y' - 'Wednesday, August 20, 2014'), 'long' (eg 'MMMM d, y' - 'August 20, 2014'), 'medium' (eg 'MMM d, y' - 'August 20, 2014') or 'short' (eg 'M/d/yy' - '8/20/14'), or a skeleton pattern prefixed by '~', e.g. '~yMd'. You can also append a caret ('^') or an asterisk ('') to $width. If so, special day names may be used (like 'Today', 'Yesterday', 'Tomorrow' with '^' and 'today', 'yesterday', 'tomorrow' width '') instead of the date.

$toTimezone
The timezone to set; leave empty to use the default timezone (or the timezone associated to $value if it's already a \DateTime)
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

Punic\Calendar::toDateTime()
http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatTime( DateTime|DateTimeInterface $value, string $width, string $locale = '' )

Format a time.

Format a time.

Parameters

$value
The \DateTimeInterface instance for which you want the localized textual representation
$width

The format name; it can be 'full' (eg 'h:mm:ss a zzzz' - '11:42:13 AM GMT+2:00'), 'long' (eg 'h:mm:ss a z' - '11:42:13 AM GMT+2:00'), 'medium' (eg 'h:mm:ss a' - '11:42:13 AM') or 'short' (eg 'h:mm a' - '11:42 AM'), or a skeleton pattern prefixed by '~', e.g. '~Hm'.

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatTimeEx( number|DateTime|DateTimeInterface|string $value, string $width, string|DateTimeZone $toTimezone = '', string $locale = '' )

Format a time (extended version: various date/time representations - see toDateTime()).

Format a time (extended version: various date/time representations - see toDateTime()).

Parameters

$value
A Unix timestamp, a \DateTimeInterface instance or a string accepted by strtotime.
$width

The format name; it can be 'full' (eg 'h:mm:ss a zzzz' - '11:42:13 AM GMT+2:00'), 'long' (eg 'h:mm:ss a z' - '11:42:13 AM GMT+2:00'), 'medium' (eg 'h:mm:ss a' - '11:42:13 AM') or 'short' (eg 'h:mm a' - '11:42 AM'), or a skeleton pattern prefixed by '~', e.g. '~Hm'.

$toTimezone
The timezone to set; leave empty to use the default timezone (or the timezone associated to $value if it's already a \DateTime)
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

Punic\Calendar::toDateTime()
http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatDatetime( DateTime|DateTimeInterface $value, string $width, string $locale = '' )

Format a date/time.

Format a date/time.

Parameters

$value
The \DateTimeInterface instance for which you want the localized textual representation
$width

The format name; it can be 'full', 'long', 'medium', 'short' or a skeleton pattern prefixed by '~', or a combination for date+time like 'full|short' or a combination for format+date+time like 'full|full|short' You can also append an asterisk ('*') to the date parh of $width. If so, special day names may be used (like 'Today', 'Yesterday', 'Tomorrow') instead of the date part.

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatDatetimeEx( number|DateTime|DateTimeInterface|string $value, string $width, string|DateTimeZone $toTimezone = '', string $locale = '' )

Format a date/time (extended version: various date/time representations - see toDateTime()).

Format a date/time (extended version: various date/time representations - see toDateTime()).

Parameters

$value
A Unix timestamp, a \DateTimeInterface instance or a string accepted by strtotime.
$width

The format name; it can be 'full', 'long', 'medium', 'short' or a combination for date+time like 'full|short' or a combination for format+date+time like 'full|full|short' You can also append an asterisk ('*') to the date parh of $width. If so, special day names may be used (like 'Today', 'Yesterday', 'Tomorrow') instead of the date part.

$toTimezone
The timezone to set; leave empty to use the default timezone (or the timezone associated to $value if it's already a \DateTime)
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

Punic\Calendar::toDateTime()
http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatInterval( DateTime|DateTimeInterface $earliest, DateTime|DateTimeInterface $latest, string $skeleton, string $locale = '' )

Format a date/time interval.

Format a date/time interval.

Parameters

$earliest
the first date of the interval
$latest
The last date of the
$skeleton
The locale-independent skeleton, e.g. "yMMMd" or "Hm".
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data.

Returns

string
Returns the localized textual representation of the interval

See

http://www.unicode.org/reports/tr35/tr35-dates.html#intervalFormats
public static string
# formatIntervalEx( number|DateTime|DateTimeInterface|string $earliest, number|DateTime|DateTimeInterface|string $latest, string $skeleton, string|DateTimeZone $toTimezone = '', string $locale = '' )

Format a date/time interval (extended version: various date/time representations - see toDateTime()).

Format a date/time interval (extended version: various date/time representations - see toDateTime()).

Parameters

$earliest
An Unix timestamp, a \DateTime instance or a string accepted by strtotime.
$latest
An Unix timestamp, a \DateTime instance or a string accepted by strtotime.
$skeleton
The locale-independent skeleton, e.g. "yMMMd" or "Hm".
$toTimezone
The timezone to set; leave empty to use the default timezone (or the timezone associated to $value if it's already a \DateTime)
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data.

Returns

string
Returns the localized textual representation of the interval
public static string
# format( DateTime|DateTimeInterface $value, string $format, string $locale = '' )

Format a date and/or time.

Format a date and/or time.

Parameters

$value
The \DateTimeInterface instance for which you want the localized textual representation
$format

The ISO format that specify how to render the date/time. The following extra format chunks are available: - 'P': ISO-8601 numeric representation of the day of the week (same as 'e' but not locale dependent) - 'PP': Numeric representation of the day of the week, from 0 (for Sunday) to 6 (for Saturday) - 'PPP': English ordinal suffix for the day of the month - 'PPPP': The day of the year (starting from 0) - 'PPPPP': Number of days in the given month - 'PPPPPP': Whether it's a leap year: 1 if it is a leap year, 0 otherwise. - 'PPPPPPP': Lowercase Ante meridiem and Post meridiem (English only, for other locales it's the same as 'a') - 'PPPPPPPP': Swatch Internet time - 'PPPPPPPPP': Microseconds - 'PPPPPPPPPP': Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. - 'PPPPPPPPPPP': Timezone offset in seconds - 'PPPPPPPPPPPP': RFC 2822 formatted date (Example: 'Thu, 21 Dec 2000 16:01:07 +0200') - 'PPPPPPPPPPPPP': Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# formatEx( number|DateTime|DateTimeInterface|string $value, string $format, string|DateTimeZone $toTimezone = '', string $locale = '' )

Format a date and/or time (extended version: various date/time representations - see toDateTime()).

Format a date and/or time (extended version: various date/time representations - see toDateTime()).

Parameters

$value
A Unix timestamp, a \DateTimeInterface instance or a string accepted by strtotime.
$format

The ISO format that specify how to render the date/time. The following extra format chunks are valid: - 'P': ISO-8601 numeric representation of the day of the week (same as 'e' but not locale dependent) - 'PP': Numeric representation of the day of the week, from 0 (for Sunday) to 6 (for Saturday) - 'PPP': English ordinal suffix for the day of the month - 'PPPP': The day of the year (starting from 0) - 'PPPPP': Number of days in the given month - 'PPPPPP': Whether it's a leap year: 1 if it is a leap year, 0 otherwise. - 'PPPPPPP': Lowercase Ante meridiem and Post meridiem (English only, for other locales it's the same as 'a') - 'PPPPPPPP': Swatch Internet time - 'PPPPPPPPP': Microseconds - 'PPPPPPPPPP': Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. - 'PPPPPPPPPPP': Timezone offset in seconds - 'PPPPPPPPPPPP': RFC 2822 formatted date (Example: 'Thu, 21 Dec 2000 16:01:07 +0200') - 'PPPPPPPPPPPPP': Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

$toTimezone
The timezone to set; leave empty to use the default timezone (or the timezone associated to $value if it's already a \DateTime)
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns an empty string if $value is empty, the localized textual representation otherwise

Throws

Punic\Exception
Throws an exception in case of problems

See

http://cldr.unicode.org/translation/date-time-patterns
http://cldr.unicode.org/translation/date-time
http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
public static string
# getDateRelativeName( DateTime|DateTimeInterface $datetime, boolean $ucFirst = false, string $locale = '' )

Retrieve the relative day name (eg 'yesterday', 'tomorrow'), if available.

Retrieve the relative day name (eg 'yesterday', 'tomorrow'), if available.

Parameters

$datetime
The date for which you want the relative day name
$ucFirst
Force first letter to be upper case?
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns the relative name if available, otherwise returns an empty string
Punic APIs API documentation generated by ApiGen