Zend_Date-Theory.xml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.date.definition.theory">
  4. <title>Theory of Operation</title>
  5. <para>
  6. Why is there only one class <classname>Zend_Date</classname> for handling dates and times in
  7. the Zend Framework?
  8. </para>
  9. <para>
  10. Many languages split the handling of times and calendar dates into two classes. However,
  11. Zend Framework strives for extreme simplicity, and forcing the developer to manage different
  12. objects with different methods for times and dates becomes a burden in many situations.
  13. Since <classname>Zend_Date</classname> methods support working with ambiguous dates that
  14. might not include all parts (era, year, month, day, hour, minute, second, timezone),
  15. developers enjoy the flexibility and ease of using the same class and the same methods to
  16. perform the same manipulations (e.g. addition, subtraction, comparison, merging of date
  17. parts, etc.). Splitting the handling of these date fragments into multiple classes would
  18. create complications when smooth interoperation is desired with a small learning curve. A
  19. single class reduces code duplication for similar operations, without the need for a complex
  20. inheritance hierarchy.
  21. </para>
  22. <sect2 id="zend.date.theory.internals">
  23. <title>Internals</title>
  24. <itemizedlist mark='opencircle'>
  25. <listitem>
  26. <para>
  27. UNIX Timestamp
  28. </para>
  29. <para>
  30. All dates and times, even ambiguous ones (e.g. no year), are represented
  31. internally as absolute moments in time, represented as a UNIX timestamp
  32. expressing the difference between the desired time and January 1st, 1970
  33. 00:00:00 <acronym>GMT</acronym>/UTC. This was only possible, because
  34. <classname>Zend_Date</classname> is not limited to UNIX timestamps nor
  35. integer values. The BCMath extension is required to support extremely large
  36. dates outside of the range Fri, 13 Dec 1901 20:45:54 <acronym>GMT</acronym>
  37. to Tue, 19 Jan 2038 03:14:07 <acronym>GMT</acronym>. Additional, tiny math
  38. errors may arise due to the inherent limitations of float data types and
  39. rounding, unless using the BCMath extension.
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. Date parts as timestamp offsets
  45. </para>
  46. <para>
  47. Thus, an instance object representing three hours would be expressed as
  48. three hours after January 1st, 1970 00:00:00 <acronym>GMT</acronym>/UTC
  49. -i.e. 0 + 3 * 60 * 60 = 10800.
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>
  54. <acronym>PHP</acronym> functions
  55. </para>
  56. <para>
  57. Where possible, <classname>Zend_Date</classname> usually uses
  58. <acronym>PHP</acronym> functions to improve performance.
  59. </para>
  60. </listitem>
  61. </itemizedlist>
  62. </sect2>
  63. </sect1>
  64. <!--vim:se ts=4 sw=4 et:-->