Zend_Date-Theory.xml 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. 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. <acronym>UNIX</acronym> 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 <acronym>UNIX</acronym>
  32. timestamp expressing the difference between the desired time and
  33. January 1st, 1970 00:00:00 <acronym>GMT</acronym>. This was only possible,
  34. because <classname>Zend_Date</classname> is not limited to
  35. <acronym>UNIX</acronym> timestamps nor integer values. The BCMath extension is
  36. required to support extremely large dates outside of the range
  37. Fri, 13 Dec 1901 20:45:54 <acronym>GMT</acronym> to
  38. Tue, 19 Jan 2038 03:14:07 <acronym>GMT</acronym>. Additional, tiny math
  39. errors may arise due to the inherent limitations of float data types and
  40. rounding, unless using the BCMath extension.
  41. </para>
  42. </listitem>
  43. <listitem>
  44. <para>
  45. Date parts as timestamp offsets
  46. </para>
  47. <para>
  48. Thus, an instance object representing three hours would be expressed as
  49. three hours after January 1st, 1970 00:00:00 <acronym>GMT</acronym>
  50. -i.e. 0 + 3 * 60 * 60 = 10800.
  51. </para>
  52. </listitem>
  53. <listitem>
  54. <para>
  55. <acronym>PHP</acronym> functions
  56. </para>
  57. <para>
  58. Where possible, <classname>Zend_Date</classname> usually uses
  59. <acronym>PHP</acronym> functions to improve performance.
  60. </para>
  61. </listitem>
  62. </itemizedlist>
  63. </sect2>
  64. </sect1>
  65. <!--vim:se ts=4 sw=4 et:-->