Zend_Date-Overview.xml 53 KB

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