Zend_Date-Overview.xml 46 KB

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