Zend_Date-Overview.xml 53 KB

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