README.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. INFORMATION FOR DEVELOPERS
  2. Once the Date API is installed, all functions in the API are available to be
  3. used anywhere by any module.
  4. The API uses the PHP 5.2 date functions to create and manipulate dates.
  5. Example, the following will create a date for the local value in one
  6. timezone, adjust it to a different timezone, then return the offset in seconds
  7. in the new timezone for the input date; The offset will be adjusted for both
  8. the timezone difference and daylight savings time, if necessary:
  9. $date = date_create('2007-03-11 02:00:00', timezone_open('America/Chicago'));
  10. $chicago_time = date_format($date, 'Y-m-d H:i');
  11. print 'At '. $chicago_time .' in Chicago, the timezone offset in seconds
  12. was '. date_offset_get($date);
  13. date_timezone_set($date, timezone_open('Europe/Berlin');
  14. $berlin_time = date_format($date, 'Y-m-d H:i');
  15. print 'It was '. $berlin_time .' in Berlin when it
  16. was '. $chicago_time .' in Chicago.';
  17. print 'At that time in Berlin, the timezone offset in seconds was
  18. '. date_offset_get($date);
  19. A helper class is available, new DateObject($string, $timezone, $format), where
  20. $string is a unixtimestamp, an ISO date, or a string like YYYY-MM-DD HH:MM:SS,
  21. $timezone is the name of the timezone this date is in, and $format is the format
  22. of date it is (DATE_FORMAT_UNIX, DATE_FORMAT_ISO, or DATE_FORMAT_DATETIME). It
  23. creates and return a date object set to the right date and timezone.
  24. Simpletest tests for these functions are included in the package.
  25. Available functions include the following (more documentation is provided in
  26. the files):
  27. ============================================================================
  28. Preconfigured arrays
  29. ============================================================================
  30. Both translated and untranslated values are available. The
  31. date_week_days_ordered() function will shift an array of week day names so it
  32. starts with the site's first day of the week, otherwise the weekday names start
  33. with Sunday as the first value, which is the expected order for many php and sql
  34. functions.
  35. date_month_names();
  36. date_month_names_abbr();
  37. date_month_names_untranslated();
  38. date_week_days();
  39. date_week_days_abbr();
  40. date_week_days_untranslated();
  41. date_week_days_ordered();
  42. date_years();
  43. date_hours();
  44. date_minutes();
  45. date_seconds();
  46. date_timezone_names();
  47. date_ampm();
  48. ============================================================================
  49. Miscellaneous date manipulation functions
  50. ============================================================================
  51. Pre-defined constants and functions that will handle pre-1970 and post-2038
  52. dates in both PHP 4 and PHP 5, in any OS. Dates can be converted from one
  53. type to another and date parts can be extracted from any date type.
  54. DATE_DATETIME
  55. DATE_ISO
  56. DATE_UNIX
  57. DATE_ARRAY
  58. DATE_OBJECT
  59. DATE_ICAL
  60. date_convert()
  61. date_is_valid();
  62. date_part_is_valid();
  63. date_part_extract();
  64. ============================================================================
  65. Date calculation and navigation
  66. ============================================================================
  67. date_difference() will find the time difference between any two days, measured
  68. in seconds, minutes, hours, days, months, weeks, or years.
  69. date_days_in_month();
  70. date_days_in_year();
  71. date_weeks_in_year();
  72. date_last_day_of_month();
  73. date_day_of_week();
  74. date_day_of_week_name();
  75. date_difference();
  76. ============================================================================
  77. Date regex and format helpers
  78. ============================================================================
  79. Pre-defined constants, an array of date format strings and their
  80. equivalent regex strings.
  81. DATE_REGEX_LOOSE is a very loose regex that will pull date parts out
  82. of an ISO date with or without separators, using either 'T' or a space
  83. to separate date and time, and with or without time.
  84. date_format_date() is similar to format_date(), except it takes a
  85. date object instead of a timestamp as the first parameter.
  86. DATE_FORMAT_ISO
  87. DATE_FORMAT_DATETIME
  88. DATE_FORMAT_UNIX
  89. DATE_FORMAT_ICAL
  90. DATE_REGEX_ISO
  91. DATE_REGEX_DATETIME
  92. DATE_REGEX_LOOSE
  93. date_format_date();
  94. date_short_formats();
  95. date_medium_formats();
  96. date_long_formats();
  97. date_format_patterns();
  98. ============================================================================
  99. Standardized ical parser and creator
  100. ============================================================================
  101. The iCal parser is found in date_api_ical.inc, which is not included by default.
  102. Include that file if you want to use these functions:
  103. Complete rewrite of ical imports to parse vevents, vlocations, valarms,
  104. and all kinds of timezone options and repeat rules for ical imports.
  105. The function now sticks to parsing the ical into an array that can be used
  106. in various ways. It no longer trys to convert timezones while parsing,
  107. instead a date_ical_date_format() function is provided that can be used to
  108. convert from the ical timezone to whatever timezone is desired in the
  109. results. Repeat rules are parsed into an array which other modules can
  110. manipulate however they like to create additional events from the results.
  111. date_ical_export();
  112. date_ical_import();
  113. date_ical_date_format();
  114. ============================================================================
  115. Helpers for portable date SQL
  116. ============================================================================
  117. The SQL functions are found in date_api_sql.inc, which is not included by
  118. default. Include that file if you want to use these functions:
  119. date_sql();
  120. date_server_zone_adj();
  121. date_sql_concat();
  122. date_sql_pad();
  123. ============================================================================
  124. Date forms and validators
  125. ============================================================================
  126. Reusable, configurable, self-validating FAPI date elements are found in
  127. date_api_elements.inc, which is not included by default. Include it
  128. if you want to use these elements. To use them, create a form element
  129. and set the '#type' to one of the following:
  130. date_select
  131. The date_select element will create a collection of form elements, with a
  132. separate select or textfield for each date part. The whole collection will
  133. get reformatted back into a date value of the requested type during validation.
  134. date_text
  135. The date_text element will create a textfield that can contain a whole
  136. date or any part of a date as text. The user input value will be re-formatted
  137. back into a date value of the requested type during validation.
  138. date_timezone
  139. The date_timezone element will create a drop-down selector to pick a
  140. timezone name.
  141. The custom date elements require a few other pieces of information to work
  142. correctly, like #date_format and #date_type. See the internal documentation
  143. for more information.
  144. ============================================================================
  145. Date Popup Module
  146. ============================================================================
  147. A new module is included in the package that will enable a popup jQuery
  148. calendar date picker and timepicker in date and time fields.
  149. It is implemented as a custom form element, so set '#type' to 'date_popup'
  150. to use this element. See the internal documentation for more information.
  151. ============================================================================
  152. Date Repeat API
  153. ============================================================================
  154. An API for repeating dates is available if installed. It can be used by
  155. other modules to create a form element that will allow users to select
  156. repeat rules and store those selections in an iCal RRULE string, and a
  157. calculation function that will parse the RRULE and return an array of dates
  158. that match those rules. The API is implemented in the Date module as a
  159. new date widget if the Date Repeat API is installed.
  160. ============================================================================
  161. RDF Integration
  162. ============================================================================
  163. To make RDF easier to use, the base date themes (date_display_single and
  164. date_display_range) have been expanded so they pass attributes and
  165. RDF mappings for the field, if any, to the theme. If RDF is installed
  166. and no other mappings are provided, the theme adds RDF information
  167. to mark both the Start and End dates as 'xsd:dateTime' datatypes with the
  168. property of 'dc:date'. This occurs in the theme preprocess layer, in
  169. particular via the functions template_preprocess_date_display_single() and
  170. template_preprocess_date_display_range().
  171. To mark these as events instead, you could install the schemaorg
  172. module, which will load the schema.org vocabulary. The mark the content type
  173. that contains events as an 'Event', using the UI exposed by that
  174. module and set the event start date field with the 'dateStart'
  175. property and tag other fields in the content type with the appropriate
  176. property types. The Date module theme will wrap the start and end
  177. date output with appropriate markup.
  178. If the result is not quite what you need, you should be able to implement your
  179. own theme preprocess functions, e.g. MYTHEME_preprocess_date_display_single()
  180. or MYTHEME_preprocess_date_display_range() and alter the attributes to use the
  181. values you want.