[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/i18n/ -> sfDateTimeFormatInfo.class.php (source)

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


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7