Zend_Date-Introduction.xml 8.1 KB

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