Zend_Date-Overview.xml 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.date.overview">
  4. <title>Zend_Date API Overview</title>
  5. <para>
  6. While the <classname>Zend_Date</classname> API remains simplistic and unitary, its design remains flexible and powerful
  7. through the rich permutations of operations and operands.
  8. </para>
  9. <sect2 id="zend.date.options">
  10. <title>Zend_Date Options</title>
  11. <sect3 id="zend.date.options.formattype">
  12. <title>Selecting the Date Format Type</title>
  13. <para>
  14. Several methods use date format strings, in a way similar to PHP's <code>date()</code>.
  15. If you are more comfortable with PHP's date format specifier than with ISO format specifiers,
  16. then you can use <classname>Zend_Date::setOptions(array('format_type' => 'php'))</classname>.
  17. Afterward, use PHP's date format specifiers for all functions which accept a <code>$format</code> parameter.
  18. Use <classname>Zend_Date::setOptions(array('format_type' => 'iso'))</classname> to switch back to the default mode of
  19. supporting only ISO date format tokens. For a list of supported format codes, see
  20. <xref linkend="zend.date.constants.phpformats" />
  21. </para>
  22. </sect3>
  23. <sect3 id="zend.date.options.fixdst">
  24. <title>DST and Date Math</title>
  25. <para>
  26. When dates are manipulated, sometimes they cross over a DST change, normally resulting in the date
  27. losing or gaining an hour. For exmaple, when adding months to a date before a DST change, if the
  28. resulting date is after the DST change, then the resulting date will appear to lose or gain an hour,
  29. resulting in the time value of the date changing. For boundary dates, such as midnight of the first
  30. or last day of a month, adding enough months to cross a date boundary results in the date losing
  31. an hour and becoming the last hour of the preceding month, giving the appearance of an "off by 1"
  32. error. To avoid this situation, the DST change ignored by using the <code>fix_dst</code> option.
  33. When crossing the Summer/Winter DST boundary, normally an hour is substracted or added depending
  34. on the date. For example, date math crossing the Spring DST leads to a date having a day value
  35. one less than expected, if the time part of the date was originally 00:00:00. Since Zend_Date
  36. is based on timestamps, and not calendar dates with a time component, the timestamp loses an hour,
  37. resulting in the date having a calendar day value one less than expected.
  38. To prevent such problems use the option <code>fix_dst</code>, which defaults to true, causing DST
  39. to have no effect on date "math" (<code>addMOnth(), subMonth()</code>). Use
  40. <classname>Zend_Date::setOptions(array('fix_dst' => false))</classname> to enable the subtraction or addition
  41. of the DST adjustment when performing date "math".
  42. </para>
  43. <para>
  44. <emphasis role="strong">If your actual timezone within the instance of <classname>Zend_Date</classname>
  45. is set to UTC or GMT the option <code>'fix_dst'</code> will not be used</emphasis> because
  46. these two timezones do not work with DST. When you change the timezone for this instance
  47. again to a timezone which is not UTC or GMT the previous set 'fix_dst' option will be used
  48. again for date "math".
  49. </para>
  50. </sect3>
  51. <sect3 id="zend.date.options.extendmonth">
  52. <title>Month Calculations</title>
  53. <para>
  54. When adding or substracting months from an existing date, the resulting value for the day of
  55. the month might be unexpected, if the original date fell on a day close to the end of the month.
  56. For example, when adding one month to January 31st, people familiar with SQL will expect February
  57. 28th as the result. On the other side, people familiar with Excel and OpenOffice will expect
  58. March 3rd as the result. The problem only occurs, if the resulting month does not have the day,
  59. which is set in the original date. For ZF developers, the desired behavior is selectable using
  60. the <code>extend_month</code> option to choose either the SQL behaviour, if set to false,
  61. or the spreadsheet behaviour when set to true. The default behaviour for <code>extend_month</code>
  62. is false, providing behavior compatible to SQL. By default, <classname>Zend_Date</classname> computes month
  63. calculations by truncating dates to the end of the month (if necessary), without wrapping into the
  64. next month when the original date designates a day of the month exceeding the number of days in
  65. the resulting month. Use <classname>Zend_Date::setOptions(array('extend_month' => true));</classname>
  66. to make month calculations work like popular spreadsheet programs.
  67. </para>
  68. </sect3>
  69. <sect3 id="zend.date.options.cache">
  70. <title>Speed up Date Localization and Normalization with Zend_Cache</title>
  71. <para>
  72. You can speed up <classname>Zend_Date</classname> by using an <classname>Zend_Cache</classname> adapter.
  73. This speeds up all methods of <classname>Zend_Date</classname> when you are using localized data.
  74. For example all methods which accept <classname>Zend_Date::DATE</classname> and
  75. <classname>Zend_Date::TIME</classname> constants would benefit from this. To set an <classname>Zend_Cache</classname>
  76. adapter to <classname>Zend_Date</classname> just use
  77. <classname>Zend_Date::setOptions(array('cache' => $adapter));</classname>.
  78. </para>
  79. </sect3>
  80. <sect3 id="zend.date.options.timesync">
  81. <title>Receiving Syncronised Timestamps with Zend_TimeSync</title>
  82. <para>
  83. Normally the clocks from servers and computers differ from each other. <classname>Zend_Date</classname>
  84. is able to handle such problems with the help of <classname>Zend_TimeSync</classname>. You can set a
  85. timeserver with <classname>Zend_Date::setOptions(array('timesync' => $timeserver));</classname> which
  86. will set the offset between the own actual timestamp and the real actual timestamp for all
  87. instances of Zend_Date. Using this option does not change the timestamp of existing instances.
  88. So best usage is to set it within the bootstrap file.
  89. </para>
  90. </sect3>
  91. </sect2>
  92. <sect2 id="zend.date.values">
  93. <title>Working with Date Values</title>
  94. <para>
  95. Once input has been normalized via the creation of a <classname>Zend_Date</classname> object, it will have an
  96. associated timezone, but an internal representation using standard
  97. <ulink url="http://en.wikipedia.org/wiki/Unix_Time">UNIX timestamps</ulink>
  98. . In order for a date to be rendered in a localized manner, a timezone must be known first. The default
  99. timezone is always GMT/UTC. To examine an object's timezone use <code>getTimeZone())</code>. To change an
  100. object's timezone, use <code>setTimeZone())</code>. All manipulations of these objects are assumed to be
  101. relative to this timezone.
  102. </para>
  103. <para>
  104. Beware of mixing and matching operations with date parts between date objects for different timezones, which
  105. generally produce undesireable results, unless the manipulations are only related to the timestamp.
  106. Operating on <classname>Zend_Date</classname> objects having different timezones generally works, except as just
  107. noted, since dates are normalized to UNIX timestamps on instantiation of <classname>Zend_Date</classname>.
  108. </para>
  109. <para>
  110. Most methods expect a constant selecting the desired <code>$part</code> of a date, such as
  111. <classname>Zend_Date::HOUR</classname>. These constants are valid for all of the functions below. A list of all
  112. available constants is provided in
  113. <xref linkend="zend.date.constants.list" />
  114. . If no <code>$part</code> is specified, then <classname>Zend_Date::TIMESTAMP</classname> is assumed. Alternatively, a
  115. user-specified format may be used for <code>$part</code>, using the same underlying mechanism and format
  116. codes as
  117. <link linkend="zend.locale.date.normalize"><classname>Zend_Locale_Format::getDate()</classname>
  118. </link>
  119. . If a date object is constructed using an obviously invalid date (e.g. a month number greater than 12),
  120. then <classname>Zend_Date</classname> will throw an exception, unless no specific date format has been selected -i.e.
  121. <code>$part</code> is either <code>null</code> or <classname>Zend_Date::DATES</classname> (a "loose" format).
  122. </para>
  123. <example id="zend.date.values.example-1">
  124. <title>User-Specified Input Date Format</title>
  125. <programlisting role="php"><![CDATA[
  126. $date1 = new Zend_Date('Feb 31, 2007', null, 'en_US');
  127. echo $date1, "\n"; // outputs "Mar 3, 2007 12:00:00 AM"
  128. $date2 = new Zend_Date('Feb 31, 2007', Zend_Date::DATES, 'en_US');
  129. echo $date2, "\n"; // outputs "Mar 3, 2007 12:00:00 AM"
  130. // strictly restricts interpretation to specified format
  131. $date3 = new Zend_Date('Feb 31, 2007', 'MM.dd.yyyy');
  132. echo $date3, "\n"; // outputs "Mar 3, 2007 12:00:00 AM"
  133. ]]></programlisting>
  134. </example>
  135. <para>
  136. If the optional <code>$locale</code> parameter is provided, then the <code>$locale</code> disambiguates the
  137. <code>$date</code> operand by replacing month and weekday names for string <code>$date</code> operands, and
  138. even parsing date strings expressed according to the conventions of that locale (see <code>
  139. <link linkend="zend.locale.date.normalize">Zend_Locale_Format::getDate()</link>
  140. </code> ). The automatic normalization of localized <code>$date</code> operands of a string type occurs when
  141. <code>$part</code> is one of the <classname>Zend_Date::DATE*</classname> or <classname>Zend_Date::TIME*</classname> constants.
  142. The locale identifies which language should be used to parse month names and weekday names, if the
  143. <code>$date</code> is a string containing a date. If there is no <code>$date</code> input parameter, then
  144. the <code>$locale</code> parameter specifies the locale to use for localizing output (e.g. the date format
  145. for a string representation). Note that the <code>$date</code> input parameter might actually have a type
  146. name instead (e.g. <code>$hour</code> for <code>addHour()</code>), although that does not prevent the use of
  147. <classname>Zend_Date</classname> objects as arguments for that parameter. If no <code>$locale</code> was specified,
  148. then the locale of the current object is used to interpret <code>$date</code>, or select the localized
  149. format for output.
  150. </para>
  151. <para>
  152. Since Zend Framework 1.7.0 <classname>Zend_Date</classname> does also support the usage of an application
  153. wide locale. You can simply set a <classname>Zend_Locale</classname> instance to the registry like shown
  154. below. With this notation you can forget about setting the locale manually with each instance when
  155. you want to use the same locale multiple times.
  156. </para>
  157. <programlisting role="php"><![CDATA[
  158. // in your bootstrap file
  159. $locale = new Zend_Locale('de_AT');
  160. Zend_Registry::set('Zend_Locale', $locale);
  161. // somewhere in your application
  162. $date = new Zend_Date('31.Feb.2007');
  163. ]]></programlisting>
  164. </sect2>
  165. <sect2 id="id.date.basic">
  166. <title>Basic Zend_Date Operations Common to Many Date Parts</title>
  167. <para>
  168. The methods <code>add(), sub(), compare(), get(), and set()</code> operate generically on dates. In each
  169. case, the operation is performed on the date held in the instance object. The <code>$date</code> operand is
  170. required for all of these methods, except <code>get()</code>, and may be a <classname>Zend_Date</classname> instance
  171. object, a numeric string, or an integer. These methods assume <code>$date</code> is a timestamp, if it is
  172. not an object. However, the <code>$part</code> operand controls which logical part of the two dates are
  173. operated on, allowing operations on parts of the object's date, such as year or minute, even when
  174. <code>$date</code> contains a long form date string, such as, "December 31, 2007 23:59:59". The result of
  175. the operation changes the date in the object, except for <code>compare()</code>, and <code>get()</code>.
  176. </para>
  177. <example id="zend.date.basic.example-1">
  178. <title>Operating on Parts of Dates</title>
  179. <programlisting role="php"><![CDATA[
  180. $date = new Zend_Date(); // $date's timestamp === time()
  181. // changes $date by adding 12 hours
  182. $date->add('12', Zend_Date::HOUR);
  183. print $date;
  184. ]]></programlisting>
  185. </example>
  186. <para>
  187. Convenience methods exist for each combination of the basic operations and several common date parts as
  188. shown in the tables below. These convenience methods help us lazy programmers avoid having to type out the
  189. <link linkend="zend.date.constants.list">date part constants</link>
  190. when using the general methods above. Conveniently, they are named by combining a prefix (name of a basic
  191. operation) with a suffix (type of date part), such as <code>addYear()</code>. In the list below, all
  192. combinations of "Date Parts" and "Basic Operations" exist. For example, the operation "add" exists for each
  193. of these date parts, including <code>addDay()</code>, <code>addYear()</code>, etc.
  194. </para>
  195. <para>
  196. These convenience methods have the same equivalent functionality as the basic operation methods, but expect
  197. string and integer <code>$date</code> operands containing only the values representing the type indicated by
  198. the suffix of the convenience method. Thus, the names of these methods (e.g. "Year" or "Minute") identify
  199. the units of the <code>$date</code> operand, when <code>$date</code> is a string or integer.
  200. </para>
  201. <sect3 id="id.date.basic.parts">
  202. <title>List of Date Parts</title>
  203. <table id="id.date.basic.parts.table">
  204. <title>Date Parts</title>
  205. <tgroup cols="2">
  206. <thead>
  207. <row>
  208. <entry>Date Part</entry>
  209. <entry>Explanation</entry>
  210. </row>
  211. </thead>
  212. <tbody>
  213. <row>
  214. <entry>
  215. <ulink url="http://en.wikipedia.org/wiki/Unix_Time">Timestamp</ulink>
  216. </entry>
  217. <entry>
  218. UNIX timestamp, expressed in seconds elapsed since January 1st, 1970 00:00:00 GMT/UTC.
  219. </entry>
  220. </row>
  221. <row>
  222. <entry>
  223. <ulink url="http://en.wikipedia.org/wiki/Gregorian_calendar">Year</ulink>
  224. </entry>
  225. <entry>Gregorian calendar year (e.g. 2006)</entry>
  226. </row>
  227. <row>
  228. <entry>
  229. <ulink url="http://en.wikipedia.org/wiki/Month#Julian_and_Gregorian_calendars">Month</ulink>
  230. </entry>
  231. <entry>Gregorian calendar month (1-12, localized names supported)</entry>
  232. </row>
  233. <row>
  234. <entry>
  235. <ulink url="http://en.wikipedia.org/wiki/24-hour_clock">24 hour clock</ulink>
  236. </entry>
  237. <entry>Hours of the day (0-23) denote the hours elapsed, since the start of the day.</entry>
  238. </row>
  239. <row>
  240. <entry>
  241. <ulink url="http://en.wikipedia.org/wiki/Minute">minute</ulink>
  242. </entry>
  243. <entry>Minutes of the hour (0-59) denote minutes elapsed, since the start of the hour.</entry>
  244. </row>
  245. <row>
  246. <entry>
  247. <ulink url="http://en.wikipedia.org/wiki/Second">Second</ulink>
  248. </entry>
  249. <entry>Seconds of the minute (0-59) denote the elapsed seconds, since the start of the minute.</entry>
  250. </row>
  251. <row>
  252. <entry>
  253. <ulink url="http://en.wikipedia.org/wiki/Millisecond">millisecond</ulink>
  254. </entry>
  255. <entry>Milliseconds denote thousandths of a second (0-999). <classname>Zend_Date</classname> supports two additional methods for working with time units smaller than seconds. By default, <classname>Zend_Date</classname> instances use a precision defaulting to milliseconds, as seen using <code>getFractionalPrecision()</code>. To change the precision use <code>setFractionalPrecision($precision)</code>. However, precision is limited practically to microseconds, since <classname>Zend_Date</classname> uses <code>
  256. <ulink url="http://php.net/microtime">microtime()</ulink></code>.</entry>
  257. </row>
  258. <row>
  259. <entry>
  260. <ulink url="http://en.wikipedia.org/wiki/Day">Day</ulink>
  261. </entry>
  262. <entry><classname>Zend_Date::DAY_SHORT</classname> is extracted from <code>$date</code> if the <code>$date</code> operand is an instance of <classname>Zend_Date</classname> or a numeric string. Otherwise, an attempt is made to extract the day according to the conventions documented for these constants: <classname>Zend_Date::WEEKDAY_NARROW</classname>, <classname>Zend_Date::WEEKDAY_NAME</classname>, <classname>Zend_Date::WEEKDAY_SHORT</classname>, <classname>Zend_Date::WEEKDAY</classname> (Gregorian calendar assumed)</entry>
  263. </row>
  264. <row>
  265. <entry>
  266. <ulink url="http://en.wikipedia.org/wiki/Week">Week</ulink>
  267. </entry>
  268. <entry><classname>Zend_Date::WEEK</classname> is extracted from <code>$date</code> if the <code>$date</code> operand is an instance of <classname>Zend_Date</classname> or a numeric string. Otherwise an exception is raised. (Gregorian calendar assumed)</entry>
  269. </row>
  270. <row>
  271. <entry>Date</entry>
  272. <entry><classname>Zend_Date::DAY_MEDIUM</classname> is extracted from <code>$date</code> if the <code>$date</code> operand is an instance of <classname>Zend_Date</classname>. Otherwise, an attempt is made to normalize the <code>$date</code> string into a Zend_Date::DATE_MEDIUM formatted date. The format of <classname>Zend_Date::DAY_MEDIUM</classname> depends on the object's locale.</entry>
  273. </row>
  274. <row>
  275. <entry>Weekday</entry>
  276. <entry>Weekdays are represented numerically as 0 (for Sunday) through 6 (for Saturday). <classname>Zend_Date::WEEKDAY_DIGIT</classname> is extracted from <code>$date</code>, if the <code>$date</code> operand is an instance of <classname>Zend_Date</classname> or a numeric string. Otherwise, an attempt is made to extract the day according to the conventions documented for these constants: <classname>Zend_Date::WEEKDAY_NARROW</classname>, <classname>Zend_Date::WEEKDAY_NAME</classname>, <classname>Zend_Date::WEEKDAY_SHORT</classname>, <classname>Zend_Date::WEEKDAY</classname> (Gregorian calendar assumed)</entry>
  277. </row>
  278. <row>
  279. <entry>DayOfYear</entry>
  280. <entry>In <classname>Zend_Date</classname>, the day of the year represents the number of calendar days elapsed since the start of the year (0-365). As with other units above, fractions are rounded down to the nearest whole number. (Gregorian calendar assumed)
  281. </entry>
  282. </row>
  283. <row>
  284. <entry>
  285. <ulink url="http://www.faqs.org/rfcs/rfc822.html">Arpa</ulink>
  286. </entry>
  287. <entry>Arpa dates (i.e. RFC 822 formatted dates) are supported. Output uses either a "GMT" or "Local differential hours+min" format (see section 5 of RFC 822). Before PHP 5.2.2, using the DATE_RFC822 constant with PHP date functions sometimes produces <ulink url="http://bugs.php.net/bug.php?id=40308">incorrect results</ulink>. Zend_Date's results are correct. Example: <code>Mon, 31 Dec 06 23:59:59 GMT</code>
  288. </entry>
  289. </row>
  290. <row>
  291. <entry>
  292. <ulink url="http://en.wikipedia.org/wiki/ISO_8601">Iso</ulink>
  293. </entry>
  294. <entry>Only complete ISO 8601 dates are supported for output. Example: <code>2009-02-14T00:31:30+01:00</code>
  295. </entry>
  296. </row>
  297. </tbody>
  298. </tgroup>
  299. </table>
  300. </sect3>
  301. <sect3 id="id.date.basic.operations">
  302. <title>List of Date Operations</title>
  303. <para>
  304. The basic operations below can be used instead of the convenience operations for specific date parts, if
  305. the
  306. <link linkend="zend.date.constants.list">appropriate constant</link>
  307. is used for the <code>$part</code> parameter.
  308. </para>
  309. <table id="id.date.basic.operations.table">
  310. <title>Basic Operations</title>
  311. <tgroup cols="2">
  312. <thead>
  313. <row>
  314. <entry>Basic Operation</entry>
  315. <entry>Explanation</entry>
  316. </row>
  317. </thead>
  318. <tbody>
  319. <row>
  320. <entry>get()</entry>
  321. <entry>
  322. <para>
  323. <emphasis role="strong">get($part = null, $locale = null)</emphasis>
  324. </para>
  325. <para>
  326. Use <code>get($part)</code> to retrieve the date <code>$part</code> of this object's
  327. date localized to <code>$locale</code> as a formatted string or integer. When using
  328. the BCMath extension, numeric strings might be returned instead of integers for
  329. large values. <emphasis role="strong">NOTE:</emphasis> Unlike <code>get()</code>,
  330. the other get*() convenience methods only return instances of <classname>Zend_Date</classname>
  331. containing a date representing the selected or computed date/time.
  332. </para>
  333. </entry>
  334. </row>
  335. <row>
  336. <entry>set()</entry>
  337. <entry>
  338. <para>
  339. <emphasis role="strong">set($date, $part = null, $locale = null)</emphasis>
  340. </para>
  341. <para>
  342. Sets the <code>$part</code> of the current object to the corresponding value for
  343. that part found in the input <code>$date</code> having a locale
  344. <code>$locale</code>.
  345. </para>
  346. </entry>
  347. </row>
  348. <row>
  349. <entry>add()</entry>
  350. <entry>
  351. <para>
  352. <emphasis role="strong">add($date, $part = null, $locale = null)</emphasis>
  353. </para>
  354. <para>
  355. Adds the <code>$part</code> of <code>$date</code> having a locale
  356. <code>$locale</code> to the current object's date.
  357. </para>
  358. </entry>
  359. </row>
  360. <row>
  361. <entry>sub()</entry>
  362. <entry>
  363. <para>
  364. <emphasis role="strong">sub($date, $part = null, $locale = null)</emphasis>
  365. </para>
  366. <para>
  367. Subtracts the <code>$part</code> of <code>$date</code> having a locale
  368. <code>$locale</code> from the current object's date.
  369. </para>
  370. </entry>
  371. </row>
  372. <row>
  373. <entry>copyPart()</entry>
  374. <entry>
  375. <para>
  376. <emphasis role="strong">copyPart($part, $locale = null)</emphasis>
  377. </para>
  378. <para>
  379. Returns a cloned object, with only <code>$part</code> of the object's date copied to
  380. the clone, with the clone have its locale arbitrarily set to <code>$locale</code>
  381. (if specified).
  382. </para>
  383. </entry>
  384. </row>
  385. <row>
  386. <entry>compare()</entry>
  387. <entry>
  388. <para>
  389. <emphasis role="strong">compare($date, $part = null, $locale = null)</emphasis>
  390. </para>
  391. <para>
  392. compares <code>$part</code> of <code>$date</code> to this object's timestamp,
  393. returning 0 if they are equal, 1 if this object's part was more recent than $date's
  394. part, otherwise -1.
  395. </para>
  396. </entry>
  397. </row>
  398. </tbody>
  399. </tgroup>
  400. </table>
  401. </sect3>
  402. </sect2>
  403. <sect2 id="zend.date.others.comparison">
  404. <title>Comparing Dates</title>
  405. <para>
  406. The following basic operations do not have corresponding convenience methods for the date parts listed in
  407. <xref linkend="zend.date.overview" />
  408. .
  409. </para>
  410. <table id="zend.date.others.comparison.table">
  411. <title>Date Comparison Methods</title>
  412. <tgroup cols="2">
  413. <thead>
  414. <row>
  415. <entry>Method</entry>
  416. <entry>Explanation</entry>
  417. </row>
  418. </thead>
  419. <tbody>
  420. <row>
  421. <entry>equals()</entry>
  422. <entry>
  423. <para>
  424. <emphasis role="strong">equals($date, $part = null, $locale = null)</emphasis>
  425. </para>
  426. <para>
  427. returns true, if <code>$part</code> of <code>$date</code> having locale
  428. <code>$locale</code> is the same as this object's date <code>$part</code>, otherwise
  429. false
  430. </para>
  431. </entry>
  432. </row>
  433. <row>
  434. <entry>isEarlier()</entry>
  435. <entry>
  436. <para>
  437. <emphasis role="strong">isEarlier($date, $part = null, $locale = null)</emphasis>
  438. </para>
  439. <para>
  440. returns true, if <code>$part</code> of this object's date is earlier than
  441. <code>$part</code> of <code>$date</code> having a locale <code>$locale</code>
  442. </para>
  443. </entry>
  444. </row>
  445. <row>
  446. <entry>isLater()</entry>
  447. <entry>
  448. <para>
  449. <emphasis role="strong">isLater($date, $part = null, $locale = null)</emphasis>
  450. </para>
  451. <para>
  452. returns true, if <code>$part</code> of this object's date is later than
  453. <code>$part</code> of <code>$date</code> having a locale <code>$locale</code>
  454. </para>
  455. </entry>
  456. </row>
  457. <row>
  458. <entry>isToday()</entry>
  459. <entry>
  460. <para>
  461. <emphasis role="strong">isToday()</emphasis>
  462. </para>
  463. <para>
  464. Tests if today's year, month, and day match this object's date value, using this
  465. object's timezone.
  466. </para>
  467. </entry>
  468. </row>
  469. <row>
  470. <entry>isTomorrow()</entry>
  471. <entry>
  472. <para>
  473. <emphasis role="strong">isTomorrow()</emphasis>
  474. </para>
  475. <para>
  476. Tests if tomorrow's year, month, and day match this object's date value, using this
  477. object's timezone.
  478. </para>
  479. </entry>
  480. </row>
  481. <row>
  482. <entry>isYesterday()</entry>
  483. <entry>
  484. <para>
  485. <emphasis role="strong">isYesterday()</emphasis>
  486. </para>
  487. <para>
  488. Tests if yesterday's year, month, and day match this object's date value, using this
  489. object's timezone.
  490. </para>
  491. </entry>
  492. </row>
  493. <row>
  494. <entry>isLeapYear()</entry>
  495. <entry>
  496. <para>
  497. <emphasis role="strong">isLeapYear()</emphasis>
  498. </para>
  499. <para>
  500. Use <code>isLeapYear()</code> to determine if the current object is a leap year, or use
  501. Zend_Date::checkLeapYear($year) to check $year, which can be a string, integer, or
  502. instance of <classname>Zend_Date</classname>. Is the year a leap year?
  503. </para>
  504. </entry>
  505. </row>
  506. <row>
  507. <entry>isDate()</entry>
  508. <entry>
  509. <para>
  510. <emphasis role="strong">isDate($date, $format = null, $locale = null)</emphasis>
  511. </para>
  512. <para>
  513. This method checks if a given date is a real date and returns true if all checks are ok.
  514. It works like PHP's checkdate() function but can also check for localized month names and
  515. for dates extending the range of checkdate()
  516. false
  517. </para>
  518. </entry>
  519. </row>
  520. </tbody>
  521. </tgroup>
  522. </table>
  523. </sect2>
  524. <sect2 id="zend.date.others.gettingparts">
  525. <title>Getting Dates and Date Parts</title>
  526. <para>
  527. Several methods support retrieving values related to a <classname>Zend_Date</classname> instance.
  528. </para>
  529. <table id="zend.date.others.gettingparts.table">
  530. <title>Date Output Methods</title>
  531. <tgroup cols="2">
  532. <thead>
  533. <row>
  534. <entry>Method</entry>
  535. <entry>Explanation</entry>
  536. </row>
  537. </thead>
  538. <tbody>
  539. <row>
  540. <entry>toString()</entry>
  541. <entry>
  542. <para>
  543. <emphasis role="strong">toString($format = null, $locale = null)</emphasis>
  544. </para>
  545. <para>
  546. Invoke directly or via the magic method <code>__toString()</code>. The
  547. <code>toString()</code> method automatically formats the date object's value according
  548. to the conventions of the object's locale, or an optionally specified
  549. <code>$locale</code>. For a list of supported format codes, see
  550. <xref linkend="zend.date.constants.selfdefinedformats" />
  551. .
  552. </para>
  553. </entry>
  554. </row>
  555. <row>
  556. <entry>toArray()</entry>
  557. <entry>
  558. <para>
  559. <emphasis role="strong">toArray()</emphasis>
  560. </para>
  561. <para>
  562. Returns an array representation of the selected date according to
  563. the conventions of the object's locale. The returned array is equivalent to
  564. PHP's <ulink url="http://php.net/getdate">getdate()</ulink> function and includes:
  565. </para>
  566. <para>
  567. <itemizedlist>
  568. <listitem>
  569. <para>
  570. Number of day as '<emphasis role="strong">day</emphasis>'
  571. (<classname>Zend_Date::DAY_SHORT</classname>)
  572. </para>
  573. </listitem>
  574. <listitem>
  575. <para>
  576. Number of month as '<emphasis role="strong">month</emphasis>'
  577. (<classname>Zend_Date::MONTH_SHORT</classname>)
  578. </para>
  579. </listitem>
  580. <listitem>
  581. <para>
  582. Year as '<emphasis role="strong">year</emphasis>'
  583. (<classname>Zend_Date::YEAR</classname>)
  584. </para>
  585. </listitem>
  586. <listitem>
  587. <para>
  588. Hour as '<emphasis role="strong">hour</emphasis>'
  589. (<classname>Zend_Date::HOUR_SHORT</classname>)
  590. </para>
  591. </listitem>
  592. <listitem>
  593. <para>
  594. Minute as '<emphasis role="strong">minute</emphasis>'
  595. (<classname>Zend_Date::MINUTE_SHORT</classname>)
  596. </para>
  597. </listitem>
  598. <listitem>
  599. <para>
  600. Second as '<emphasis role="strong">second</emphasis>'
  601. (<classname>Zend_Date::SECOND_SHORT</classname>)
  602. </para>
  603. </listitem>
  604. <listitem>
  605. <para>
  606. Abbreviated timezone as '<emphasis role="strong">timezone</emphasis>'
  607. (<classname>Zend_Date::TIMEZONE</classname>)
  608. </para>
  609. </listitem>
  610. <listitem>
  611. <para>
  612. Unix timestamp as '<emphasis role="strong">timestamp</emphasis>'
  613. (<classname>Zend_Date::TIMESTAMP</classname>)
  614. </para>
  615. </listitem>
  616. <listitem>
  617. <para>
  618. Number of weekday as '<emphasis role="strong">weekday</emphasis>'
  619. (<classname>Zend_Date::WEEKDAY_DIGIT</classname>)
  620. </para>
  621. </listitem>
  622. <listitem>
  623. <para>
  624. Day of year as '<emphasis role="strong">dayofyear</emphasis>'
  625. (<classname>Zend_Date::DAY_OF_YEAR</classname>)
  626. </para>
  627. </listitem>
  628. <listitem>
  629. <para>
  630. Week as '<emphasis role="strong">week</emphasis>'
  631. (<classname>Zend_Date::WEEK</classname>)
  632. </para>
  633. </listitem>
  634. <listitem>
  635. <para>
  636. Delay of timezone to GMT as
  637. '<emphasis role="strong">gmtsecs</emphasis>'
  638. (<classname>Zend_Date::GMT_SECS</classname>)
  639. </para>
  640. </listitem>
  641. </itemizedlist>
  642. </para>
  643. </entry>
  644. </row>
  645. <row>
  646. <entry>toValue()</entry>
  647. <entry>
  648. <para>
  649. <emphasis role="strong">toValue($part = null)</emphasis>
  650. </para>
  651. <para>
  652. Returns an integer representation of the selected date <code>$part</code> according to
  653. the conventions of the object's locale. Returns <code>false</code> when
  654. <code>$part</code> selects a non-numeric value, such as
  655. <classname>Zend_Date::MONTH_NAME_SHORT</classname>. <emphasis role="strong">NOTE:</emphasis> This
  656. method calls
  657. <link linkend="id.date.basic.operations"><code>get()</code>
  658. </link>
  659. and casts the result to a PHP integer, which will give unpredictable results, if
  660. <code>get()</code> returns a numeric string containing a number too large for a PHP
  661. integer on your system. Use <code>get()</code> instead.
  662. </para>
  663. </entry>
  664. </row>
  665. <row>
  666. <entry>
  667. <link linkend="id.date.basic.operations">get()</link>
  668. </entry>
  669. <entry>
  670. <para>
  671. <emphasis role="strong">get($part = null, $locale = null)</emphasis>
  672. </para>
  673. <para>
  674. This method returns the <code>$part</code> of object's date localized to
  675. <code>$locale</code> as a formatted string or integer. See
  676. <xref linkend="id.date.basic.operations" />
  677. for more information.
  678. </para>
  679. </entry>
  680. </row>
  681. <row>
  682. <entry>now()</entry>
  683. <entry>
  684. <para>
  685. <emphasis role="strong">now($locale = null)</emphasis>
  686. </para>
  687. <para>
  688. This convenience function is equivalent to <code>new Zend_Date()</code>. It returns the
  689. current date as a <classname>Zend_Date</classname> object, having <code>$locale</code>
  690. </para>
  691. </entry>
  692. </row>
  693. </tbody>
  694. </tgroup>
  695. </table>
  696. </sect2>
  697. <sect2 id="zend.date.others.fractions">
  698. <title>Working with Fractions of Seconds</title>
  699. <para>
  700. Several methods support retrieving values related to a <classname>Zend_Date</classname> instance.
  701. </para>
  702. <table id="zend.date.others.fractions.table">
  703. <title>Date Output Methods</title>
  704. <tgroup cols="2">
  705. <thead>
  706. <row>
  707. <entry>Method</entry>
  708. <entry>Explanation</entry>
  709. </row>
  710. </thead>
  711. <tbody>
  712. <row>
  713. <entry>
  714. <para>
  715. <emphasis role="strong">getFractionalPrecision()</emphasis>
  716. </para>
  717. </entry>
  718. <entry>Return the precision of the part seconds</entry>
  719. </row>
  720. <row>
  721. <entry>
  722. <para>
  723. <emphasis role="strong">setFractionalPrecision()</emphasis>
  724. </para>
  725. </entry>
  726. <entry>Set the precision of the part seconds</entry>
  727. </row>
  728. </tbody>
  729. </tgroup>
  730. </table>
  731. </sect2>
  732. <sect2 id="zend.date.other.sun">
  733. <title>Sunrise / Sunset</title>
  734. <para>
  735. Three methods provide access to geographically localized information about the Sun, including the time of
  736. sunrise and sunset.
  737. </para>
  738. <table id="zend.date.other.sun.table">
  739. <title>Miscellaneous Methods</title>
  740. <tgroup cols="2">
  741. <thead>
  742. <row>
  743. <entry>Method</entry>
  744. <entry>Explanation</entry>
  745. </row>
  746. </thead>
  747. <tbody>
  748. <row>
  749. <entry>
  750. <para>
  751. <emphasis role="strong">getSunrise($location)</emphasis>
  752. </para>
  753. </entry>
  754. <entry>Return the date's time of sunrise</entry>
  755. </row>
  756. <row>
  757. <entry>
  758. <para>
  759. <emphasis role="strong">getSunset($location)</emphasis>
  760. </para>
  761. </entry>
  762. <entry>Return the date's time of sunset</entry>
  763. </row>
  764. <row>
  765. <entry>
  766. <para>
  767. <emphasis role="strong">getSunInfo($location)</emphasis>
  768. </para>
  769. </entry>
  770. <entry>Return an array with the date's sun dates</entry>
  771. </row>
  772. </tbody>
  773. </tgroup>
  774. </table>
  775. </sect2>
  776. </sect1>
  777. <!--
  778. vim:se ts=4 sw=4 et:
  779. -->