Zend_Date-Overview.xml 51 KB

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