Zend_Date-Overview.xml 50 KB

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