123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <?php
- /**
- * Date Formatter class - locale-dependent formatting/parsing of dates using pattern strings and/or canned patterns.
- *
- * This class represents the ICU date formatting functionality. It allows users to
- * display dates in a localized format or to parse strings
- * into PHP date values using pattern strings and/or canned patterns.
- *
- * Example:
- * <code>
- * $datefmt = new DateFormatter("de-DE", LONG, SHORT, date_default_timezone_get());
- * echo $formatter->format(time());
- * </code>
- *
- * <code>
- * $datefmt = new DateFormatter("de-DE", LONG, SHORT, date_default_timezone_get() , GREGORIAN , "yyyy-MM-dd HH:mm:ss z");
- * echo $formatter->format(time());
- * </code>
- *
- * @see http://www.icu-project.org/apiref/icu4c/udat_8h.html
- *
- */
- class DateFormatter {
- #############################################################################
- # Common constants.
- #############################################################################
- /**
- * The following constants are used to specify different formats
- * in the constructor.
- */
- const NONE = -1;
- const FULL = 0;
- const LONG = 1;
- const MEDIUM = 2;
- const SHORT = 3;
- /**
- * The following int constants are used to specify the calendar.
- * These calendars are all based directly on the Gregorian calendar
- * Non-Gregorian calendars need to be specified in locale.
- * Examples might include locale="hi@calendar=BUDDHIST"
- */
- const TRADITIONAL = 0; // non-Gregorian calendar that is locale-defined, required by ICU
- const GREGORIAN = 1 ;// Gregorian calendar
-
- #############################################################################
- # Object-oriented API
- #############################################################################
- /**
- * Create a date formatter
- *
- * @param string $locale Locale to use when formatting or parsing
- * @param integer $datetype Date type to use (none, short, medium, long, full)
- * @param integer $timetype Time type to use (none, short, medium, long, full)
- * @param [String] $timezone Time zone ID ; default is system default
- * @param [integer] $calendar Calendar to use for formatting or parsing; default is
- * GREGORIAN
- * @param [string] $pattern Optional pattern to use when formatting or parsing
- * @return DateFormatter
- * @see __construct
- * @see datefmt_create
- */
- public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar= null , $pattern= null) {}
- /**
- * Create a date formatter
- *
- * @param string $locale Locale to use when formatting or parsing
- * @param integer $datetype Date type to use (none, short, medium, long, full)
- * @param integer $timetype Time type to use (none, short, medium, long, full)
- * @param [string] $timezone Time zone ID ; default is system default
- * @param [integer] $calendar Calendar to use for formatting or parsing; default is
- * GREGORIAN
- * @param [string] $pattern Optional pattern to use when formatting or parsing
- * @return DateFormatter
- * @see __construct
- * @see datefmt_create
- */
- public static function create($locale, $datetype, $timetype, $timezone = null, $calendar= null , $pattern= null) {}
- /**
- * formats the time value as a string.
- * @param mixed $value - value to format
- * integer: a unix timestamp value (seconds since epoch, UTC)
- * array: a localtime array - uses 24 hour clock in tm_hour field
- * @return string a formatted string or, if an error occurred, 'null'.
- */
- public function format($value) {}
- /**
- * converts string $value to an incremental time value, starting at
- * $parse_pos and consuming as much of the input value as possible
- * If no error occurs before $value is consumed, $parse_pos will contain -1
- * otherwise it will contain the position at which parsing ended (and the error
- * occurred).
- * @param string $value string to convert to a time
- * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
- * This variable will contain the end position if the parse fails
- * If $parse_pos > strlen($value), the parse fails immediately.
- * @return integer timestamp parsed value
- */
- public function parse($value, $parse_pos=0) {}
-
- /**
- * converts string $value to a field-based time value, starting at
- * $parse_pos and consuming as much of the input value as possible
- * If no error occurs before $value is consumed, $parse_pos will contain -1
- * otherwise it will contain the position at which parsing ended (and the error
- * occurred).
- * @param string $value string to convert to a time
- * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
- * This variable will contain the end position if the parse fails
- * If $parse_pos > strlen($value), the parse fails immediately.
- * @return array localtime compatible array of integers - uses 24 hour clock in tm_hour field
- */
- public function localtime($value, $parse_pos=0) {}
- /**
- * Gets the datetype in use
- * @return integer the current 'datetype' value of the formatter
- */
- public function getDateType() {}
- /**
- * Gets the timetype in use
- * @return integer the current 'timetype' value of the formatter
- */
- public function getTimeType() {}
- /**
- * Gets the leniency in use
- * @return boolean 'true' if parser is lenient, 'false' if parser is strict
- * default value for parser is 'false'.
- */
- public function isLenient() {}
- /**
- * Sets the leniency to use
- * @param boolean $lenient sets whether the parser is lenient or not, default is 'false'
- * 'true' sets the parser to accept otherwise flawed date or
- * time patterns, parsing as much as possible to obtain a value.
- * 'false' sets the parser to strictly parse strings into dates.
- * Extra space, unrecognized tokens, or invalid values
- * ("Feburary 30th") are not accepted.
- *
- * @return boolean 'true' if successful; 'false' if an error occurred.
- */
- public function setLenient($lenient) {}
- /**
- * Gets the locale in use
- * @param [integer] which locale should be returned?
- * values may include ULOC_ACTUAL_LOCALE,
- * ULOC_VALID_LOCALE. By default the actual
- * locale is returned.
- * @return string the locale of this formatter or 'false' if error
- */
- public function getLocale($type = ULOC_ACTUAL_LOCALE) {}
- /**
- * @return string ID string for the time zone used by this formatter
- */
- public function getTimeZoneId() {}
- /**
- * sets the time zone to use
- * @param string $zone zone ID string of the time zone to use.
- * if null or the empty string, the default time zone for
- * the runtime is used.
- * @return boolean 'true' on successful setting of the time zone, 'false'
- * if an error occurred (such as the time zone wasn't recognized).
- */
- public function setTimeZoneId($zone) {}
- /**
- * Sets the calendar used to the appropriate calendar, which must be
- * one of the constants defined above. Some examples include:
- * - Gregorian calendar
- * - Traditional
- * Default value is GREGORIAN
- * @param integer $which the calendar (an enumerated constant) to use.
- * @return boolean 'true' if successful, 'false' if an error occurred or if the calendar was not recognized
- */
- public function setCalendar($which) {}
- /**
- * Gets the Calendar in use
- * @return integer the calendar being used by the formatter
- */
- public function getCalendar() {}
- /**
- * Gets the pattern in use
- * @return string the pattern string being used to format/parse
- */
- public function getPattern() {}
- /**
- * Sets the pattern to use
- * @param string $pattern new pattern string to use
- * @return boolean 'true' if successful, 'false' if an error occurred. Bad format
- * strings are usually the cause of the latter.
- */
- public function setPattern($pattern) {}
- /**
- * Get the error code from last operation
- *
- * Returns error code from the last number formatting operation.
- *
- * @return integer the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
- */
- public function getErrorCode() {}
- /**
- * Get the error text from the last operation.
- *
- * @return string Description of the last error.
- */
- public function getErrorMessage() {}
- }
- #############################################################################
- # Procedural API
- #############################################################################
- /**
- * Create a date formatter
- *
- * @param string $locale Locale to use when formatting or parsing
- * @param integer $datetype Date type to use (none, short, medium, long, full)
- * @param integer $timetype Time type to use (none, short, medium, long, full)
- * @param [string] $timezone Time zone ID ; default is system default
- * @param [integer] $calendar Calendar to use for formatting or parsing; default is
- * GREGORIAN
- * @param [string] $pattern Optional pattern to use when formatting or parsing
- * @return DateFormatter
- * @see datefmt_create
- */
- function datefmt_create($locale, $datetype, $timetype, $timezone = null, $calendar= null ,$pattern=null ) {}
- /**
- * formats the time value as a string.
- * @param DateFormatter $fmt The date formatter resource
- * @param mixed $value - value to format
- * integer: a unix timestamp value (seconds since epoch, UTC)
- * array: a localtime array - uses 24 hour clock in tm_hour field
- * @return string a formatted string or, if an error occurred, 'null'.
- */
- function datefmt_format($fmt , $value) {}
- /**
- * converts string $value to an incremental time value, starting at
- * $parse_pos and consuming as much of the input value as possible
- * If no error occurs before $value is consumed, $parse_pos will contain -1
- * otherwise it will contain the position at which parsing ended (and the error
- * occurred).
- * @param DateFormatter $fmt The date formatter resource
- * @param string $value string to convert to a time
- * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
- * This variable will contain the end position if the parse fails
- * If $parse_pos > strlen($value), the parse fails immediately.
- * @return integer timestamp parsed value
- */
- function datefmt_parse($fmt , $value, $parse_pos=0) {}
-
- /**
- * converts string $value to a field-based time value, starting at
- * $parse_pos and consuming as much of the input value as possible
- * If no error occurs before $value is consumed, $parse_pos will contain -1
- * otherwise it will contain the position at which parsing ended (and the error
- * occurred).
- * @param DateFormatter $fmt The date formatter resource
- * @param string $value string to convert to a time
- * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
- * This variable will contain the end position if the parse fails
- * If $parse_pos > strlen($value), the parse fails immediately.
- * @return array localtime compatible array of integers - uses 24 hour clock in tm_hour field
- */
- function datefmt_localtime($fmt , $value, $parse_pos=0) {}
- /**
- * Gets the Datetype in use
- * @param DateFormatter $fmt The date formatter resource
- * @return integer the current 'datetype' value of the formatter
- */
- function datefmt_get_datetype($fmt ) {}
- /**
- * Gets the timetype in use
- * @param DateFormatter $fmt The date formatter resource
- * @return integer the current 'timetype' value of the formatter
- */
- function datefmt_get_timetype($fmt) {}
- /**
- * Gets the leniency of the formatter
- * @param DateFormatter $fmt The date formatter resource
- * @return boolean 'true' if parser is lenient, 'false' if parser is strict
- * default value for parser is 'false'.
- */
- function datefmt_is_lenient($fmt) {}
- /**
- * Sets the leniency of the formatter
- * @param DateFormatter $fmt The date formatter resource
- * @param boolean $lenient sets whether the parser is lenient or not, default is 'false'
- * 'true' sets the parser to accept otherwise flawed date or
- * time patterns, parsing as much as possible to obtain a value.
- * 'false' sets the parser to strictly parse strings into dates.
- * Extra space, unrecognized tokens, or invalid values
- * ("Feburary 30th") are not accepted.
- *
- * @return boolean 'true' if successful; 'false' if an error occurred.
- */
- function datefmt_set_lenient($fmt , $lenient) {}
- /**
- * Gets the locale in use
- * @param DateFormatter $fmt The date formatter resource
- * @param [integer] which locale should be returned?
- * values may include ULOC_ACTUAL_LOCALE,
- * ULOC_VALID_LOCALE. By default the actual
- * locale is returned.
- * @return string the locale of this formatter or 'false' if error
- */
- function datefmt_get_locale($fmt , $type = ULOC_ACTUAL_LOCALE) {}
- /**
- * Gets the time zone id in use
- * @param DateFormatter $fmt The date formatter resource
- * @return string ID string for the time zone used by this formatter
- */
- function datefmt_get_timezone_id($fmt) {}
- /**
- * Sets the time zone to use
- * @param DateFormatter $fmt The date formatter resource
- * @param string $zone zone ID string of the time zone to use.
- * if null or the empty string, the default time zone for
- * the runtime is used.
- * @return boolean 'true' on successful setting of the time zone, 'false'
- * if an error occurred (such as the time zone wasn't recognized).
- */
- function datefmt_set_timezone_id($fmt , $zone) {}
- /**
- * Sets the calendar used to the appropriate calendar, which must be
- * one of the constants defined above. Some examples include:
- * - Gregorian calendar
- * - Traditional
- * Default value is GREGORIAN
- * @param DateFormatter $fmt The date formatter resource
- * @param integer $which the calendar (an enumerated constant) to use.
- * @return boolean 'true' if successful, 'false' if an error occurred or if the calendar was not recognized
- */
- function datefmt_set_calendar($fmt , $which) {}
- /**
- * Gets the calendar in use
- * @param DateFormatter $fmt The date formatter resource
- * @return integer the calendar being used by the formatter
- */
- function datefmt_get_calendar($fmt) {}
- /**
- * Gets the pattern in use
- * @param DateFormatter $fmt The date formatter resource
- * @return string the pattern string being used to format/parse
- */
- function datefmt_get_pattern($fmt) {}
- /**
- * Sets the pattern to use
- * @param DateFormatter $fmt The date formatter resource
- * @param string $pattern new pattern string to use
- * @return boolean 'true' if successful, 'false' if an error occurred. Bad format
- * strings are usually the cause of the latter.
- */
- function datefmt_set_pattern($fmt , $pattern) {}
- /**
- * Get the error code from last operation
- *
- * @param DateFormatter $fmt The date formatter resource
- * Returns error code from the last number formatting operation.
- *
- * @return integer the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
- */
- function datefmt_get_error_code($fmt) {}
- /**
- * Get the error text from the last operation.
- *
- * @param DateFormatter $fmt The date formatter resource
- * @return string Description of the last error.
- */
- function datefmt_get_error_message($fmt) {}
|