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. 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. <para>
  25. <itemizedlist mark='opencircle'>
  26. <listitem>
  27. <para>
  28. UNIX Timestamp
  29. </para>
  30. <para>
  31. All dates and times, even ambiguous ones (e.g. no year), are represented
  32. internally as absolute moments in time, represented as a UNIX timestamp
  33. expressing the difference between the desired time and January 1st, 1970
  34. 00:00:00 GMT/UTC. This was only possible, because
  35. <classname>Zend_Date</classname> is not limited to UNIX timestamps nor
  36. integer values. The BCMath extension is required to support extremely large
  37. dates outside of the range Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038
  38. 03:14:07 GMT. Additional, tiny math errors may arise due to the inherent
  39. limitations of float data types and rounding, unless using the BCMath
  40. 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 GMT/UTC -i.e. 0 + 3 * 60 * 60 =
  50. 10800.
  51. </para>
  52. </listitem>
  53. <listitem>
  54. <para>
  55. PHP functions
  56. </para>
  57. <para>
  58. Where possible, <classname>Zend_Date</classname> usually uses PHP functions
  59. to improve performance.
  60. </para>
  61. </listitem>
  62. </itemizedlist>
  63. </para>
  64. </sect2>
  65. </sect1>
  66. <!--vim:se ts=4 sw=4 et:-->