Zend_Date-Introduction.xml 8.4 KB

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