datefmt_api.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. /**
  3. * Date Formatter class - locale-dependent formatting/parsing of dates using pattern strings and/or canned patterns.
  4. *
  5. * This class represents the ICU date formatting functionality. It allows users to
  6. * display dates in a localized format or to parse strings
  7. * into PHP date values using pattern strings and/or canned patterns.
  8. *
  9. * Example:
  10. * <code>
  11. * $datefmt = new DateFormatter("de-DE", LONG, SHORT, date_default_timezone_get());
  12. * echo $formatter->format(time());
  13. * </code>
  14. *
  15. * <code>
  16. * $datefmt = new DateFormatter("de-DE", LONG, SHORT, date_default_timezone_get() , GREGORIAN , "yyyy-MM-dd HH:mm:ss z");
  17. * echo $formatter->format(time());
  18. * </code>
  19. *
  20. * @see http://www.icu-project.org/apiref/icu4c/udat_8h.html
  21. *
  22. */
  23. class DateFormatter {
  24. #############################################################################
  25. # Common constants.
  26. #############################################################################
  27. /**
  28. * The following constants are used to specify different formats
  29. * in the constructor.
  30. */
  31. const NONE = -1;
  32. const FULL = 0;
  33. const LONG = 1;
  34. const MEDIUM = 2;
  35. const SHORT = 3;
  36. /**
  37. * The following int constants are used to specify the calendar.
  38. * These calendars are all based directly on the Gregorian calendar
  39. * Non-Gregorian calendars need to be specified in locale.
  40. * Examples might include locale="hi@calendar=BUDDHIST"
  41. */
  42. const TRADITIONAL = 0; // non-Gregorian calendar that is locale-defined, required by ICU
  43. const GREGORIAN = 1 ;// Gregorian calendar
  44. #############################################################################
  45. # Object-oriented API
  46. #############################################################################
  47. /**
  48. * Create a date formatter
  49. *
  50. * @param string $locale Locale to use when formatting or parsing
  51. * @param integer $datetype Date type to use (none, short, medium, long, full)
  52. * @param integer $timetype Time type to use (none, short, medium, long, full)
  53. * @param [String] $timezone Time zone ID ; default is system default
  54. * @param [integer] $calendar Calendar to use for formatting or parsing; default is
  55. * GREGORIAN
  56. * @param [string] $pattern Optional pattern to use when formatting or parsing
  57. * @return DateFormatter
  58. * @see __construct
  59. * @see datefmt_create
  60. */
  61. public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar= null , $pattern= null) {}
  62. /**
  63. * Create a date formatter
  64. *
  65. * @param string $locale Locale to use when formatting or parsing
  66. * @param integer $datetype Date type to use (none, short, medium, long, full)
  67. * @param integer $timetype Time type to use (none, short, medium, long, full)
  68. * @param [string] $timezone Time zone ID ; default is system default
  69. * @param [integer] $calendar Calendar to use for formatting or parsing; default is
  70. * GREGORIAN
  71. * @param [string] $pattern Optional pattern to use when formatting or parsing
  72. * @return DateFormatter
  73. * @see __construct
  74. * @see datefmt_create
  75. */
  76. public static function create($locale, $datetype, $timetype, $timezone = null, $calendar= null , $pattern= null) {}
  77. /**
  78. * formats the time value as a string.
  79. * @param mixed $value - value to format
  80. * integer: a unix timestamp value (seconds since epoch, UTC)
  81. * array: a localtime array - uses 24 hour clock in tm_hour field
  82. * @return string a formatted string or, if an error occurred, 'null'.
  83. */
  84. public function format($value) {}
  85. /**
  86. * converts string $value to an incremental time value, starting at
  87. * $parse_pos and consuming as much of the input value as possible
  88. * If no error occurs before $value is consumed, $parse_pos will contain -1
  89. * otherwise it will contain the position at which parsing ended (and the error
  90. * occurred).
  91. * @param string $value string to convert to a time
  92. * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
  93. * This variable will contain the end position if the parse fails
  94. * If $parse_pos > strlen($value), the parse fails immediately.
  95. * @return integer timestamp parsed value
  96. */
  97. public function parse($value, $parse_pos=0) {}
  98. /**
  99. * converts string $value to a field-based time value, starting at
  100. * $parse_pos and consuming as much of the input value as possible
  101. * If no error occurs before $value is consumed, $parse_pos will contain -1
  102. * otherwise it will contain the position at which parsing ended (and the error
  103. * occurred).
  104. * @param string $value string to convert to a time
  105. * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
  106. * This variable will contain the end position if the parse fails
  107. * If $parse_pos > strlen($value), the parse fails immediately.
  108. * @return array localtime compatible array of integers - uses 24 hour clock in tm_hour field
  109. */
  110. public function localtime($value, $parse_pos=0) {}
  111. /**
  112. * Gets the datetype in use
  113. * @return integer the current 'datetype' value of the formatter
  114. */
  115. public function getDateType() {}
  116. /**
  117. * Gets the timetype in use
  118. * @return integer the current 'timetype' value of the formatter
  119. */
  120. public function getTimeType() {}
  121. /**
  122. * Gets the leniency in use
  123. * @return boolean 'true' if parser is lenient, 'false' if parser is strict
  124. * default value for parser is 'false'.
  125. */
  126. public function isLenient() {}
  127. /**
  128. * Sets the leniency to use
  129. * @param boolean $lenient sets whether the parser is lenient or not, default is 'false'
  130. * 'true' sets the parser to accept otherwise flawed date or
  131. * time patterns, parsing as much as possible to obtain a value.
  132. * 'false' sets the parser to strictly parse strings into dates.
  133. * Extra space, unrecognized tokens, or invalid values
  134. * ("Feburary 30th") are not accepted.
  135. *
  136. * @return boolean 'true' if successful; 'false' if an error occurred.
  137. */
  138. public function setLenient($lenient) {}
  139. /**
  140. * Gets the locale in use
  141. * @param [integer] which locale should be returned?
  142. * values may include ULOC_ACTUAL_LOCALE,
  143. * ULOC_VALID_LOCALE. By default the actual
  144. * locale is returned.
  145. * @return string the locale of this formatter or 'false' if error
  146. */
  147. public function getLocale($type = ULOC_ACTUAL_LOCALE) {}
  148. /**
  149. * @return string ID string for the time zone used by this formatter
  150. */
  151. public function getTimeZoneId() {}
  152. /**
  153. * sets the time zone to use
  154. * @param string $zone zone ID string of the time zone to use.
  155. * if null or the empty string, the default time zone for
  156. * the runtime is used.
  157. * @return boolean 'true' on successful setting of the time zone, 'false'
  158. * if an error occurred (such as the time zone wasn't recognized).
  159. */
  160. public function setTimeZoneId($zone) {}
  161. /**
  162. * Sets the calendar used to the appropriate calendar, which must be
  163. * one of the constants defined above. Some examples include:
  164. * - Gregorian calendar
  165. * - Traditional
  166. * Default value is GREGORIAN
  167. * @param integer $which the calendar (an enumerated constant) to use.
  168. * @return boolean 'true' if successful, 'false' if an error occurred or if the calendar was not recognized
  169. */
  170. public function setCalendar($which) {}
  171. /**
  172. * Gets the Calendar in use
  173. * @return integer the calendar being used by the formatter
  174. */
  175. public function getCalendar() {}
  176. /**
  177. * Gets the pattern in use
  178. * @return string the pattern string being used to format/parse
  179. */
  180. public function getPattern() {}
  181. /**
  182. * Sets the pattern to use
  183. * @param string $pattern new pattern string to use
  184. * @return boolean 'true' if successful, 'false' if an error occurred. Bad format
  185. * strings are usually the cause of the latter.
  186. */
  187. public function setPattern($pattern) {}
  188. /**
  189. * Get the error code from last operation
  190. *
  191. * Returns error code from the last number formatting operation.
  192. *
  193. * @return integer the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
  194. */
  195. public function getErrorCode() {}
  196. /**
  197. * Get the error text from the last operation.
  198. *
  199. * @return string Description of the last error.
  200. */
  201. public function getErrorMessage() {}
  202. }
  203. #############################################################################
  204. # Procedural API
  205. #############################################################################
  206. /**
  207. * Create a date formatter
  208. *
  209. * @param string $locale Locale to use when formatting or parsing
  210. * @param integer $datetype Date type to use (none, short, medium, long, full)
  211. * @param integer $timetype Time type to use (none, short, medium, long, full)
  212. * @param [string] $timezone Time zone ID ; default is system default
  213. * @param [integer] $calendar Calendar to use for formatting or parsing; default is
  214. * GREGORIAN
  215. * @param [string] $pattern Optional pattern to use when formatting or parsing
  216. * @return DateFormatter
  217. * @see datefmt_create
  218. */
  219. function datefmt_create($locale, $datetype, $timetype, $timezone = null, $calendar= null ,$pattern=null ) {}
  220. /**
  221. * formats the time value as a string.
  222. * @param DateFormatter $fmt The date formatter resource
  223. * @param mixed $value - value to format
  224. * integer: a unix timestamp value (seconds since epoch, UTC)
  225. * array: a localtime array - uses 24 hour clock in tm_hour field
  226. * @return string a formatted string or, if an error occurred, 'null'.
  227. */
  228. function datefmt_format($fmt , $value) {}
  229. /**
  230. * converts string $value to an incremental time value, starting at
  231. * $parse_pos and consuming as much of the input value as possible
  232. * If no error occurs before $value is consumed, $parse_pos will contain -1
  233. * otherwise it will contain the position at which parsing ended (and the error
  234. * occurred).
  235. * @param DateFormatter $fmt The date formatter resource
  236. * @param string $value string to convert to a time
  237. * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
  238. * This variable will contain the end position if the parse fails
  239. * If $parse_pos > strlen($value), the parse fails immediately.
  240. * @return integer timestamp parsed value
  241. */
  242. function datefmt_parse($fmt , $value, $parse_pos=0) {}
  243. /**
  244. * converts string $value to a field-based time value, starting at
  245. * $parse_pos and consuming as much of the input value as possible
  246. * If no error occurs before $value is consumed, $parse_pos will contain -1
  247. * otherwise it will contain the position at which parsing ended (and the error
  248. * occurred).
  249. * @param DateFormatter $fmt The date formatter resource
  250. * @param string $value string to convert to a time
  251. * @param integer $parse_pos position at which to start the parsing in $value (zero-based)
  252. * This variable will contain the end position if the parse fails
  253. * If $parse_pos > strlen($value), the parse fails immediately.
  254. * @return array localtime compatible array of integers - uses 24 hour clock in tm_hour field
  255. */
  256. function datefmt_localtime($fmt , $value, $parse_pos=0) {}
  257. /**
  258. * Gets the Datetype in use
  259. * @param DateFormatter $fmt The date formatter resource
  260. * @return integer the current 'datetype' value of the formatter
  261. */
  262. function datefmt_get_datetype($fmt ) {}
  263. /**
  264. * Gets the timetype in use
  265. * @param DateFormatter $fmt The date formatter resource
  266. * @return integer the current 'timetype' value of the formatter
  267. */
  268. function datefmt_get_timetype($fmt) {}
  269. /**
  270. * Gets the leniency of the formatter
  271. * @param DateFormatter $fmt The date formatter resource
  272. * @return boolean 'true' if parser is lenient, 'false' if parser is strict
  273. * default value for parser is 'false'.
  274. */
  275. function datefmt_is_lenient($fmt) {}
  276. /**
  277. * Sets the leniency of the formatter
  278. * @param DateFormatter $fmt The date formatter resource
  279. * @param boolean $lenient sets whether the parser is lenient or not, default is 'false'
  280. * 'true' sets the parser to accept otherwise flawed date or
  281. * time patterns, parsing as much as possible to obtain a value.
  282. * 'false' sets the parser to strictly parse strings into dates.
  283. * Extra space, unrecognized tokens, or invalid values
  284. * ("Feburary 30th") are not accepted.
  285. *
  286. * @return boolean 'true' if successful; 'false' if an error occurred.
  287. */
  288. function datefmt_set_lenient($fmt , $lenient) {}
  289. /**
  290. * Gets the locale in use
  291. * @param DateFormatter $fmt The date formatter resource
  292. * @param [integer] which locale should be returned?
  293. * values may include ULOC_ACTUAL_LOCALE,
  294. * ULOC_VALID_LOCALE. By default the actual
  295. * locale is returned.
  296. * @return string the locale of this formatter or 'false' if error
  297. */
  298. function datefmt_get_locale($fmt , $type = ULOC_ACTUAL_LOCALE) {}
  299. /**
  300. * Gets the time zone id in use
  301. * @param DateFormatter $fmt The date formatter resource
  302. * @return string ID string for the time zone used by this formatter
  303. */
  304. function datefmt_get_timezone_id($fmt) {}
  305. /**
  306. * Sets the time zone to use
  307. * @param DateFormatter $fmt The date formatter resource
  308. * @param string $zone zone ID string of the time zone to use.
  309. * if null or the empty string, the default time zone for
  310. * the runtime is used.
  311. * @return boolean 'true' on successful setting of the time zone, 'false'
  312. * if an error occurred (such as the time zone wasn't recognized).
  313. */
  314. function datefmt_set_timezone_id($fmt , $zone) {}
  315. /**
  316. * Sets the calendar used to the appropriate calendar, which must be
  317. * one of the constants defined above. Some examples include:
  318. * - Gregorian calendar
  319. * - Traditional
  320. * Default value is GREGORIAN
  321. * @param DateFormatter $fmt The date formatter resource
  322. * @param integer $which the calendar (an enumerated constant) to use.
  323. * @return boolean 'true' if successful, 'false' if an error occurred or if the calendar was not recognized
  324. */
  325. function datefmt_set_calendar($fmt , $which) {}
  326. /**
  327. * Gets the calendar in use
  328. * @param DateFormatter $fmt The date formatter resource
  329. * @return integer the calendar being used by the formatter
  330. */
  331. function datefmt_get_calendar($fmt) {}
  332. /**
  333. * Gets the pattern in use
  334. * @param DateFormatter $fmt The date formatter resource
  335. * @return string the pattern string being used to format/parse
  336. */
  337. function datefmt_get_pattern($fmt) {}
  338. /**
  339. * Sets the pattern to use
  340. * @param DateFormatter $fmt The date formatter resource
  341. * @param string $pattern new pattern string to use
  342. * @return boolean 'true' if successful, 'false' if an error occurred. Bad format
  343. * strings are usually the cause of the latter.
  344. */
  345. function datefmt_set_pattern($fmt , $pattern) {}
  346. /**
  347. * Get the error code from last operation
  348. *
  349. * @param DateFormatter $fmt The date formatter resource
  350. * Returns error code from the last number formatting operation.
  351. *
  352. * @return integer the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
  353. */
  354. function datefmt_get_error_code($fmt) {}
  355. /**
  356. * Get the error text from the last operation.
  357. *
  358. * @param DateFormatter $fmt The date formatter resource
  359. * @return string Description of the last error.
  360. */
  361. function datefmt_get_error_message($fmt) {}