Zend_Date-Overview.xml 51 KB

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