[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 3 /** 4 * DateTimeFormatInfo class file. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the BSD License. 8 * 9 * Copyright(c) 2004 by Qiang Xue. All rights reserved. 10 * 11 * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue} 12 * The latest version of PRADO can be obtained from: 13 * {@link http://prado.sourceforge.net/} 14 * 15 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 16 * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $ 17 * @package System.I18N.core 18 */ 19 20 /** 21 * Get the CultureInfo class. 22 */ 23 require_once(dirname(__FILE__).'/CultureInfo.php'); 24 25 26 /** 27 * Defines how DateTime values are formatted and displayed, depending 28 * on the culture. 29 * 30 * This class contains information, such as date patterns, time patterns, 31 * and AM/PM designators. 32 * 33 * To create a DateTimeFormatInfo for a specific culture, create a 34 * CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat 35 * property. For example: 36 * <code> 37 * $culture = new CultureInfo('en_AU'); 38 * $dtfi = $culture->DateTimeFormat; 39 * </code> 40 * 41 * To create a DateTimeFormatInfo for the invariant culture, use 42 * <code> 43 * DateTimeFormatInfo::getInstance($culture=null); 44 * </code> 45 * you may pass a CultureInfo parameter $culture to get the DateTimeFormatInfo 46 * for a specific culture. 47 * 48 * DateTime values are formatted using standard or custom patterns stored in 49 * the properties of a DateTimeFormatInfo. 50 * 51 * The standard patterns can be replaced with custom patterns by setting the 52 * associated properties of DateTimeFormatInfo. 53 * 54 * The following table lists the standard format characters for each standard 55 * pattern and the associated DateTimeFormatInfo property that can be set to 56 * modify the standard pattern. The format characters are case-sensitive; 57 * for example, 'g' and 'G' represent slightly different patterns. 58 * 59 * <code> 60 * Format Character Associated Property Example Format Pattern (en-US) 61 * -------------------------------------------------------------------------- 62 * d ShortDatePattern MM/dd/yyyy 63 * D LongDatePattern dddd, dd MMMM yyyy 64 * F FullDateTimePattern dddd, dd MMMM yyyy HH:mm:ss 65 * m, M MonthDayPattern MMMM dd 66 * r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT' 67 * s SortableDateTimePattern yyyy'-'MM'-'dd'T'HH':'mm':'ss 68 * t ShortTimePattern HH:mm 69 * T LongTimePattern HH:mm:ss 70 * Y YearMonthPattern yyyy MMMM 71 * -------------------------------------------------------------------------- 72 * </code> 73 * 74 * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com> 75 * @version v1.0, last update on Fri Dec 03 22:30:31 EST 2004 76 * @package System.I18N.core 77 */ 78 class DateTimeFormatInfo 79 { 80 /** 81 * ICU date time formatting data. 82 * @var array 83 */ 84 private $data = array(); 85 86 /** 87 * A list of properties that are accessable/writable. 88 * @var array 89 */ 90 protected $properties = array(); 91 92 /** 93 * Allow functions that begins with 'set' to be called directly 94 * as an attribute/property to retrieve the value. 95 * @return mixed 96 */ 97 function __get($name) 98 { 99 $getProperty = 'get'.$name; 100 if(in_array($getProperty, $this->properties)) 101 return $this->$getProperty(); 102 else 103 throw new Exception('Property '.$name.' does not exists.'); 104 } 105 106 /** 107 * Allow functions that begins with 'set' to be called directly 108 * as an attribute/property to set the value. 109 */ 110 function __set($name, $value) 111 { 112 $setProperty = 'set'.$name; 113 if(in_array($setProperty, $this->properties)) 114 $this->$setProperty($value); 115 else 116 throw new Exception('Property '.$name.' can not be set.'); 117 } 118 119 /** 120 * Initializes a new writable instance of the DateTimeFormatInfo class 121 * that is dependent on the ICU data for date time formatting 122 * information. <b>N.B.</b>You should not initialize this class directly 123 * unless you know what you are doing. Please use use 124 * DateTimeFormatInfo::getInstance() to create an instance. 125 * @param array ICU data for date time formatting. 126 * @see getInstance() 127 */ 128 function __construct($data=array()) 129 { 130 $this->properties = get_class_methods($this); 131 132 if(empty($data)) 133 throw new Exception('Please provide the ICU data to initialize.'); 134 135 $this->data = $data; 136 } 137 138 /** 139 * Get the internal ICU data for date time formatting. 140 * @return array ICU date time formatting data. 141 */ 142 protected function getData() 143 { 144 return $this->data; 145 } 146 147 /** 148 * Gets the default DateTimeFormatInfo that is culture-independent 149 * (invariant). 150 * @return DateTimeFormatInfo default DateTimeFormatInfo. 151 */ 152 static function getInvariantInfo() 153 { 154 static $invariant; 155 if(is_null($invariant)) 156 { 157 $culture = CultureInfo::getInvariantCulture(); 158 $invariant = $culture->getDateTimeFormat(); 159 } 160 return $invariant; 161 } 162 163 /** 164 * Returns the DateTimeFormatInfo associated with the specified culture. 165 * @param CultureInfo the culture that gets the DateTimeFormat property. 166 * @return DateTimeFormatInfo DateTimeFormatInfo for the specified 167 * culture. 168 */ 169 static function getInstance($culture=null) 170 { 171 172 if ($culture instanceof CultureInfo) 173 return $culture->getDateTimeFormat(); 174 else if(is_string($culture)) 175 { 176 $cultureInfo = new CultureInfo($culture); 177 return $cultureInfo->getDateTimeFormat(); 178 } 179 else 180 { 181 $cultureInfo = CultureInfo::getInvariantCulture(); 182 return $cultureInfo->getDateTimeFormat(); 183 } 184 } 185 186 /** 187 * A one-dimensional array of type String containing 188 * the culture-specific abbreviated names of the days 189 * of the week. The array for InvariantInfo contains 190 * "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat". 191 * @return array abbreviated day names 192 */ 193 function getAbbreviatedDayNames() 194 { 195 return $this->data['dayNames']['format']['abbreviated']; 196 //return $this->data['dayNames/format/abbreviated']; 197 } 198 199 /** 200 * Set the abbreviated day names. The value should be 201 * an array of string starting with Sunday and ends in Saturady. 202 * For example, 203 * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code> 204 * @param array abbreviated day names. 205 */ 206 function setAbbreviatedDayNames($value) 207 { 208 $this->data['dayNames']['format']['abbreviated'] = $value; 209 } 210 211 /** 212 * A one-dimensional array of type String containing 213 * the culture-specific narrow names of the days 214 * of the week. The array for InvariantInfo contains 215 * "S", "M", "T", "W", "T", "F", and "S". 216 * @return array narrow day names 217 */ 218 function getNarrowDayNames() 219 { 220 return $this->data['dayNames']['format']['narrow']; 221 } 222 223 /** 224 * Set the narrow day names. The value should be 225 * an array of string starting with Sunday and ends in Saturady. 226 * For example, 227 * <code>array("S", "M", "T", "W", "T", "F", "S");</code> 228 * @param array narrow day names. 229 */ 230 function setNarrowDayNames($value) 231 { 232 $this->data['dayNames']['format']['narrow'] = $value; 233 } 234 235 /** 236 * A one-dimensional array of type String containing the 237 * culture-specific full names of the days of the week. 238 * The array for InvariantInfo contains "Sunday", "Monday", 239 * "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday". 240 * @return array day names 241 */ 242 function getDayNames() 243 { 244 return $this->data['dayNames']['format']['wide']; 245 } 246 247 248 /** 249 * Set the day names. The value should be 250 * an array of string starting with Sunday and ends in Saturady. 251 * For example, 252 * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 253 * "Friday", "Saturday".);</code> 254 * @param array day names. 255 */ 256 function setDayNames($value) 257 { 258 $this->data['dayNames']['format']['wide'] = $value; 259 } 260 261 /** 262 * A one-dimensional array of type String containing the 263 * culture-specific narrow names of the months. The array 264 * for InvariantInfo contains "J", "F", "M", "A", "M", "J", 265 * "J", "A", "S", "O", "N", and "D". 266 * @return array narrow month names. 267 */ 268 function getNarrowMonthNames() 269 { 270 return $this->data['monthNames']['format']['narrow']; 271 } 272 273 /** 274 * Set the narrow month names. The value should be 275 * an array of string starting with J and ends in D. 276 * For example, 277 * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code> 278 * @param array month names. 279 */ 280 function setNarrowMonthNames($value) 281 { 282 $this->data['monthNames']['format']['narrow'] = $value; 283 } 284 285 /** 286 * A one-dimensional array of type String containing the 287 * culture-specific abbreviated names of the months. The array 288 * for InvariantInfo contains "Jan", "Feb", "Mar", "Apr", "May", 289 * "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and "Dec". 290 * @return array abbreviated month names. 291 */ 292 function getAbbreviatedMonthNames() 293 { 294 return $this->data['monthNames']['format']['abbreviated']; 295 } 296 297 /** 298 * Set the abbreviated month names. The value should be 299 * an array of string starting with Jan and ends in Dec. 300 * For example, 301 * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun", 302 * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code> 303 * @param array month names. 304 */ 305 function setAbbreviatedMonthNames($value) 306 { 307 $this->data['monthNames']['format']['abbreviated'] = $value; 308 } 309 310 /** 311 * A one-dimensional array of type String containing the 312 * culture-specific full names of the months. The array for 313 * InvariantInfo contains "January", "February", "March", "April", 314 * "May", "June", "July", "August", "September", "October", "November", 315 * and "December" 316 * @return array month names. 317 */ 318 function getMonthNames() 319 { 320 return $this->data['monthNames']['format']['wide']; 321 } 322 323 /** 324 * Set the month names. The value should be 325 * an array of string starting with Janurary and ends in December. 326 * For example, 327 * <code>array("January", "February", "March", "April", "May", "June", 328 * "July", "August", "September","October","November","December");</code> 329 * @param array month names. 330 */ 331 function setMonthNames($value) 332 { 333 $this->data['monthNames']['format']['wide'] = $value; 334 } 335 336 /** 337 * A string containing the name of the era. 338 * @param int era The integer representing the era. 339 * @return string the era name. 340 */ 341 function getEra($era) 342 { 343 $eraName = $this->data['eras']['abbreviated']; 344 return $eraName[$era]; 345 } 346 347 /** 348 * The string designator for hours that are "ante meridiem" (before noon). 349 * The default for InvariantInfo is "AM". 350 * @return string AM designator. 351 */ 352 function getAMDesignator() 353 { 354 $result = $this->getAMPMMarkers(); 355 return $result[0]; 356 } 357 358 /** 359 * Set the AM Designator. For example, 'AM'. 360 * @param string AM designator. 361 */ 362 function setAMDesignator($value) 363 { 364 $markers = $this->getAMPMMarkers(); 365 $markers[0] = $value; 366 $this->setAMPMMarkers($markers); 367 } 368 369 /** 370 * The string designator for hours that are "post meridiem" (after noon). 371 * The default for InvariantInfo is "PM". 372 * @return string PM designator. 373 */ 374 function getPMDesignator() 375 { 376 $result = $this->getAMPMMarkers(); 377 return $result[1]; 378 } 379 380 /** 381 * Set the PM Designator. For example, 'PM'. 382 * @param string PM designator. 383 */ 384 function setPMDesignator($value) 385 { 386 $markers = $this->getAMPMMarkers(); 387 $markers[1] = $value; 388 $this->setAMPMMarkers($markers); 389 } 390 391 /** 392 * Get the AM and PM markers array. 393 * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code> 394 * @return array AM and PM markers 395 */ 396 function getAMPMMarkers() 397 { 398 return $this->data['AmPmMarkers']; 399 } 400 401 /** 402 * Set the AM and PM markers array. 403 * For example <code>array('AM','PM');</code> 404 * @param array AM and PM markers 405 */ 406 function setAMPMMarkers($value) 407 { 408 $this->data['AmPmMarkers'] = $value; 409 } 410 411 /** 412 * Returns the full time pattern "HH:mm:ss z" (default). 413 * This is culture sensitive. 414 * @return string pattern "HH:mm:ss z". 415 */ 416 function getFullTimePattern() 417 { 418 return $this->data['DateTimePatterns'][0]; 419 } 420 421 /** 422 * Returns the long time pattern "HH:mm:ss z" (default). 423 * This is culture sensitive. 424 * @return string pattern "HH:mm:ss z". 425 */ 426 function getLongTimePattern() 427 { 428 return $this->data['DateTimePatterns'][1]; 429 } 430 431 /** 432 * Returns the medium time pattern "HH:mm:ss" (default). 433 * This is culture sensitive. 434 * @return string pattern "HH:mm:ss". 435 */ 436 function getMediumTimePattern() 437 { 438 return $this->data['DateTimePatterns'][2]; 439 } 440 441 /** 442 * Returns the short time pattern "HH:mm" (default). 443 * This is culture sensitive. 444 * @return string pattern "HH:mm". 445 */ 446 function getShortTimePattern() 447 { 448 return $this->data['DateTimePatterns'][3]; 449 } 450 451 /** 452 * Returns the full date pattern "EEEE, yyyy MMMM dd" (default). 453 * This is culture sensitive. 454 * @return string pattern "EEEE, yyyy MMMM dd". 455 */ 456 function getFullDatePattern() 457 { 458 return $this->data['DateTimePatterns'][4]; 459 } 460 461 /** 462 * Returns the long date pattern "yyyy MMMM d" (default). 463 * This is culture sensitive. 464 * @return string pattern "yyyy MMMM d". 465 */ 466 function getLongDatePattern() 467 { 468 return $this->data['DateTimePatterns'][5]; 469 } 470 471 /** 472 * Returns the medium date pattern "yyyy MMMM d" (default). 473 * This is culture sensitive. 474 * @return string pattern "yyyy MMM d". 475 */ 476 function getMediumDatePattern() 477 { 478 return $this->data['DateTimePatterns'][6]; 479 } 480 481 /** 482 * Returns the short date pattern "yy/MM/dd" (default). 483 * This is culture sensitive. 484 * @return string pattern "yy/MM/dd". 485 */ 486 function getShortDatePattern() 487 { 488 return $this->data['DateTimePatterns'][7]; 489 } 490 491 /** 492 * Returns the date time order pattern, "{1} {0}" (default). 493 * This is culture sensitive. 494 * @return string pattern "{1} {0}". 495 */ 496 function getDateTimeOrderPattern() 497 { 498 return $this->data['DateTimePatterns'][8]; 499 } 500 501 /** 502 * Formats the date and time in a culture sensitive paterrn. 503 * The default is "Date Time". 504 * @return string date and time formated 505 */ 506 function formatDateTime($date, $time) 507 { 508 $pattern = $this->getDateTimeOrderPattern(); 509 return str_replace(array('{0}','{1}'), array($time, $date), $pattern); 510 } 511 512 } 513 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |