Zend_Date-Introduction.xml 7.7 KB

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