Zend_Date-Overview.xml 52 KB

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