Zend_Date-Overview.xml 49 KB

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