Zend_Date-Theory.xml 3.2 KB

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