Zend_Date-Introduction.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.date.introduction">
  4. <title>Introduction</title>
  5. <para>
  6. The <classname>Zend_Date</classname> component offers a detailed, but simple API for manipulating dates and times. Its
  7. methods accept a wide variety of types of information, including date parts, in numerous combinations yielding
  8. many features and possibilities above and beyond the existing PHP date related functions. For the very latest
  9. manual updates, please see
  10. <ulink url="http://framework.zend.com/wiki/display/ZFDOCDEV/Home">our online manual
  11. (frequently synced to Subversion)</ulink>
  12. .
  13. </para>
  14. <para>
  15. Although simplicity remains the goal, working with localized dates and times while modifying, combining, and
  16. comparing parts involves some unavoidable complexity. Dates, as well as times, are often written differently in
  17. different locales. For example, some place the month first, while other write the year first when expressing
  18. calendar dates. For more information about handling localization and normalization, please refer to
  19. <link linkend="zend.locale.date.datesandtimes"><classname>Zend_Locale</classname>
  20. </link>
  21. .
  22. </para>
  23. <para>
  24. <classname>Zend_Date</classname> also supports abbreviated names of months in many languages. <classname>Zend_Locale</classname>
  25. facilitates the normalization of localized month and weekday names to timestamps, which may, in turn, be shown
  26. localized to other regions.
  27. </para>
  28. <sect2 id="zend.date.setdefaulttimezone">
  29. <title>Always Set a Default Timezone</title>
  30. <para>
  31. Before using any date related functions in PHP or Zend Framework, first make certain your application
  32. has a correct default timezone, by either setting the TZ environment variable, using the
  33. <code>date.timezone</code> php.ini setting, or using
  34. <ulink url="http://php.net/date_default_timezone_set">date_default_timezone_set()</ulink>
  35. . In PHP, we can adjust all date and time related functions to work for a particular user by setting a
  36. default timezone according to the user's expectations. For a complete list of timezone settings, see the
  37. <ulink url="http://unicode.org/cldr/data/diff/supplemental/territory_containment_un_m_49.html">CLDR Timezone Identifier List</ulink>
  38. .
  39. <example id="zend.date.setdefaulttimezone.example-1">
  40. <title>Setting a Default Timezone</title>
  41. <programlisting role="php"><![CDATA[
  42. // timezone for an American in California
  43. date_default_timezone_set('America/Los_Angeles');
  44. // timezone for a German in Germany
  45. date_default_timezone_set('Europe/Berlin');
  46. ]]></programlisting>
  47. </example>
  48. <emphasis role="strong">When creating Zend_Date instances, their timezone will automatically become the
  49. current default timezone!</emphasis> Thus, the timezone setting will account for any Daylight Savings Time
  50. (DST) in effect, eliminating the need to explicitly specify DST.
  51. </para>
  52. <para>
  53. Keep in mind that the timezones <emphasis role="strong">UTC</emphasis> and
  54. <emphasis role="strong">GMT</emphasis> do not include Daylight Saving Time. This means that even
  55. if you define per hand that <classname>Zend_Date</classname> should work with DST, it would automatically
  56. be switched back for the instances of <classname>Zend_Date</classname> which have been set to UTC or GMT.
  57. </para>
  58. </sect2>
  59. <sect2 id="zend.date.why">
  60. <title>Why Use Zend_Date?</title>
  61. <para>
  62. <classname>Zend_Date</classname> offers the following features, which extend the scope of PHP date functions:
  63. </para>
  64. <itemizedlist mark='opencircle'>
  65. <listitem>
  66. <para>
  67. Simple API
  68. </para>
  69. <para>
  70. <classname>Zend_Date</classname> offers a very simple API, which combines the best of date/time functionality
  71. from four programming languages. It is possible, for example, to add or compare two times within a
  72. single row.
  73. </para>
  74. </listitem>
  75. <listitem>
  76. <para>
  77. Completely internationalized
  78. </para>
  79. <para>
  80. All full and abbreviated names of months and weekdays are supported for more than 130 languages.
  81. Methods support both input and the output of dates using the localized names of months and weekdays,
  82. in the conventional format associated with each locale.
  83. </para>
  84. </listitem>
  85. <listitem>
  86. <para>
  87. Unlimited timestamps
  88. </para>
  89. <para>
  90. Although PHP 5.2 docs state, "The valid range of a timestamp is typically from Fri, 13 Dec 1901
  91. 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT," <classname>Zend_Date</classname> supports a nearly unlimited
  92. range, with the help of the BCMath extension. If BCMath is not available, then Zend_Date will have
  93. reduced support only for timestamps within the range of the <code>float</code> type supported by
  94. your server. "The size of a float is platform-dependent, although a maximum of ~1.8e308 with a
  95. precision of roughly 14 decimal digits is a common value (that's 64 bit IEEE format)." [
  96. <ulink url="http://www.php.net/float">http://www.php.net/float</ulink>
  97. ]. Additionally, inherent limitations of float data types, and rounding error of float numbers
  98. may introduce errors into calculations. To avoid these problems, the ZF I18n components use
  99. BCMath extension, if available.
  100. </para>
  101. </listitem>
  102. <listitem>
  103. <para>
  104. Support for ISO_8601 date specifications
  105. </para>
  106. <para>
  107. ISO_8601 date specifications are supported. Even partially compliant ISO_8601 date specifications
  108. will be identified. These date formats are particularly useful when working with databases. For
  109. example, even though MsSQL and
  110. <ulink url="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html">MySQL</ulink>
  111. differ a little from each other, both are supported by <classname>Zend_Date</classname> using the
  112. <link linkend="zend.date.constants.list">Zend_Date::ISO_8601</link>
  113. format specification constant. When date strings conform to "Y/m/d" or "Y-m-d H:i:s", according to
  114. PHP date() format tokens, use Zend_Date's built-in support for ISO 8601 formatted dates.
  115. </para>
  116. </listitem>
  117. <listitem>
  118. <para>
  119. Calculate sunrise and sunset
  120. </para>
  121. <para>
  122. For any place and day, the times for sunrise and sunset can be displayed, so that you won't miss a
  123. single daylight second for working on your favorite PHP project :)
  124. </para>
  125. </listitem>
  126. </itemizedlist>
  127. </sect2>
  128. </sect1>
  129. <!--
  130. vim:se ts=4 sw=4 et:
  131. -->