Zend_Date-Overview.xml 53 KB

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