You are here

README.txt in Date 7.3

Date API
--------
Once the Date API is installed, all functions in the API are available to be
used anywhere by any module.

The API uses the PHP 5.2 date functions to create and manipulate dates.

Example, the following will create a date for the local value in one
timezone, adjust it to a different timezone, then return the offset in seconds
in the new timezone for the input date; The offset will be adjusted for both
the timezone difference and daylight savings time, if necessary:

$date = date_create('2007-03-11 02:00:00', timezone_open('America/Chicago'));
$chicago_time = date_format($date, 'Y-m-d H:i');

print 'At '. $chicago_time .' in Chicago, the timezone offset in seconds
  was '. date_offset_get($date);

date_timezone_set($date, timezone_open('Europe/Berlin');
$berlin_time = date_format($date, 'Y-m-d H:i');

print 'It was '. $berlin_time .' in Berlin when it
  was '. $chicago_time .' in Chicago.';
print 'At that time in Berlin, the timezone offset in seconds was
  '. date_offset_get($date);

A helper class is available, new DateObject($string, $timezone, $format), where
$string is a unixtimestamp, an ISO date, or a string like YYYY-MM-DD HH:MM:SS,
$timezone is the name of the timezone this date is in, and $format is the format
of date it is (DATE_FORMAT_UNIX, DATE_FORMAT_ISO, or DATE_FORMAT_DATETIME). It
creates and return a date object set to the right date and timezone.

Simpletest tests for these functions are included in the package.

Available functions include the following (more documentation is provided in
the files).


Preconfigured arrays
--------------------------------------------------------------------------------
Both translated and untranslated values are available.  For example the
'date_week_days_ordered()' function will shift an array of week day names so it
starts with the site's first day of the week, otherwise the weekday names start
with Sunday as the first value, which is the expected order for many PHP and SQL
functions.

date_month_names();
date_month_names_abbr();
date_month_names_untranslated();
date_week_days();
date_week_days_abbr();
date_week_days_untranslated();
date_week_days_ordered();
date_years();
date_hours();
date_minutes();
date_seconds();
date_timezone_names();
date_timezone_abbr();
date_timezone_is_valid();
date_default_timezone();
date_default_timezone_object();
date_ampm();
date_hidden_element();
date_granularity_names();
date_granularity_sorted();
date_granularity_array_from_precision();
date_granularity_precision();
date_granularity_format();
date_now();


Miscellaneous date manipulation functions
--------------------------------------------------------------------------------
Pre-defined constants and functions that will handle pre-1970 and post-2038
dates in both PHP 4 and PHP 5, in any OS. Dates can be converted from one
type to another and date parts can be extracted from any date type.

DATE_DATETIME
DATE_ISO
DATE_UNIX
DATE_ARRAY
DATE_OBJECT
DATE_ICAL

date_is_all_day();
date_increment_round();
date_is_date();
date_pad();
date_has_time();
date_has_date();
date_part_format();
date_limit_format();
date_nongranularity();
date_order_translated();
date_order();
date_range_valid();
date_range_years();
date_range_string();
date_format_type_options();
date_example_date();
date_is_all_day();
date_increment_round();
date_make_iso_valid();


Date calculation and navigation
--------------------------------------------------------------------------------
For example 'date_days_in_month()' identifies the number of days in a month for
a date.

date_days_in_month();
date_days_in_year();
date_iso_weeks_in_year();
date_iso_week_range();
date_weeks_in_year();
date_day_of_week();
date_day_of_week_name();
date_week_range();
date_week();
date_get_timezone();
date_get_timezone_db();


Date regex and format helpers
--------------------------------------------------------------------------------
Pre-defined constants, an array of date format strings and their
equivalent regex strings.

DATE_REGEX_LOOSE is a very loose regex that will pull date parts out
of an ISO date with or without separators, using either 'T' or a space
to separate date and time, and with or without time.

'date_format_date()'' is similar to 'format_date()', except it takes a
date object instead of a timestamp as the first parameter.

DATE_FORMAT_ISO
DATE_FORMAT_DATETIME
DATE_FORMAT_UNIX
DATE_FORMAT_ICAL

DATE_REGEX_ISO
DATE_REGEX_DATETIME
DATE_REGEX_LOOSE

date_format_date();
date_format_patterns();
date_format_interval();
date_format_order();
date_format_type_options();
date_type_format();


Standardized ical parser and creator
--------------------------------------------------------------------------------
The iCal parser is found in 'date_api_ical.inc', which is not included by
default. Include that file if you want to use these functions:

Complete rewrite of ical imports to parse vevents, vlocations, valarms,
and all kinds of timezone options and repeat rules for ical imports.
The function now sticks to parsing the ical into an array that can be used
in various ways. It no longer trys to convert timezones while parsing instead a
'date_ical_date()' function is provided that can be used to convert from the
ical timezone to the local timezone.
iCal properties can be parsed into an array which other modules can manipulate
however they like to create additional events from the results.
The function 'date_api_ical_build_rrule()'' can be used to build an iCal RULE
from $form_values.

date_ical_import();
date_ical_parse();
date_ical_parse_date();
date_ical_parse_rrule();
date_ical_parse_exceptions();
date_ical_parse_duration();
date_ical_parse_text();
date_ical_parse_location();
date_ical_date();
date_ical_escape_text();
date_api_ical_build_rrule();


Helpers for portable date SQL
--------------------------------------------------------------------------------
The SQL functions are found in date_api_sql.inc, which is not included by
default. Include that file if you want to use these functions:

date_sql_concat();
date_sql_coalesce();
date_sql_pad();


Date forms and validators
--------------------------------------------------------------------------------
Reusable, configurable, self-validating FAPI date elements are found in
date_api_elements.inc, which is not included by default. Include it if you want
to use these elements. To use them, create a form element and set the '#type'
to one of the following:

date_select
  The date_select element will create a collection of form elements, with a
  separate select or textfield for each date part. The whole collection will
  get reformatted back into a date value of the requested type during
  validation.

date_text
  The date_text element will create a textfield that can contain a whole date
  or any part of a date as text. The user input value will be re-formatted back
  into a date value of the requested type during validation.

date_timezone
  The date_timezone element will create a drop-down selector to pick a timezone
  name.

The custom date elements require a few other pieces of information to work
correctly, like #date_format and #date_type. See the internal documentation
for more information.


Date Repeat API
--------------------------------------------------------------------------------
An API for repeating dates is available if installed. It can be used by other
modules to create a form element that will allow users to select repeat rules
and store those selections in an iCal RRULE string, and a calculation function
that will parse the RRULE and return an array of dates that match those rules.
The API is implemented in the Date module as a new date widget if the Date
Repeat API is installed.


RDF Integration
--------------------------------------------------------------------------------
To make RDF easier to use, the base date themes ('date_display_single' and
'date_display_range') have been expanded so they pass attributes and RDF
mappings for the field, if any, to the theme. If RDF is installed and no other
mappings are provided, the theme adds RDF information to mark both the Start
and End dates as 'xsd:dateTime' datatypes with the property of 'dc:date'. This
occurs in the theme preprocess layer, in particular via the functions
'template_preprocess_date_display_single()' and
'template_preprocess_date_display_range()'.

To mark these as events instead, you could install the schemaorg module [1],
which will load the schema.org vocabulary. The mark the content type that
contains events as an 'Event', using the UI exposed by that module and set the
event start date field with the 'dateStart' property and tag other fields in the
content type with the appropriate property types. The Date module theme will
wrap the start and end date output with appropriate markup.

If the result is not quite what you need, you should be able to implement your
own theme preprocess functions, e.g. 'MYTHEME_preprocess_date_display_single()'
or 'MYTHEME_preprocess_date_display_range()' and alter the attributes to use the
values you want.


References
--------------------------------------------------------------------------------
1: https://www.drupal.org/project/schemaorg

File

date_api/README.txt
View source
  1. Date API
  2. --------
  3. Once the Date API is installed, all functions in the API are available to be
  4. used anywhere by any module.
  5. The API uses the PHP 5.2 date functions to create and manipulate dates.
  6. Example, the following will create a date for the local value in one
  7. timezone, adjust it to a different timezone, then return the offset in seconds
  8. in the new timezone for the input date; The offset will be adjusted for both
  9. the timezone difference and daylight savings time, if necessary:
  10. $date = date_create('2007-03-11 02:00:00', timezone_open('America/Chicago'));
  11. $chicago_time = date_format($date, 'Y-m-d H:i');
  12. print 'At '. $chicago_time .' in Chicago, the timezone offset in seconds
  13. was '. date_offset_get($date);
  14. date_timezone_set($date, timezone_open('Europe/Berlin');
  15. $berlin_time = date_format($date, 'Y-m-d H:i');
  16. print 'It was '. $berlin_time .' in Berlin when it
  17. was '. $chicago_time .' in Chicago.';
  18. print 'At that time in Berlin, the timezone offset in seconds was
  19. '. date_offset_get($date);
  20. A helper class is available, new DateObject($string, $timezone, $format), where
  21. $string is a unixtimestamp, an ISO date, or a string like YYYY-MM-DD HH:MM:SS,
  22. $timezone is the name of the timezone this date is in, and $format is the format
  23. of date it is (DATE_FORMAT_UNIX, DATE_FORMAT_ISO, or DATE_FORMAT_DATETIME). It
  24. creates and return a date object set to the right date and timezone.
  25. Simpletest tests for these functions are included in the package.
  26. Available functions include the following (more documentation is provided in
  27. the files).
  28. Preconfigured arrays
  29. --------------------------------------------------------------------------------
  30. Both translated and untranslated values are available. For example 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_timezone_abbr();
  48. date_timezone_is_valid();
  49. date_default_timezone();
  50. date_default_timezone_object();
  51. date_ampm();
  52. date_hidden_element();
  53. date_granularity_names();
  54. date_granularity_sorted();
  55. date_granularity_array_from_precision();
  56. date_granularity_precision();
  57. date_granularity_format();
  58. date_now();
  59. Miscellaneous date manipulation functions
  60. --------------------------------------------------------------------------------
  61. Pre-defined constants and functions that will handle pre-1970 and post-2038
  62. dates in both PHP 4 and PHP 5, in any OS. Dates can be converted from one
  63. type to another and date parts can be extracted from any date type.
  64. DATE_DATETIME
  65. DATE_ISO
  66. DATE_UNIX
  67. DATE_ARRAY
  68. DATE_OBJECT
  69. DATE_ICAL
  70. date_is_all_day();
  71. date_increment_round();
  72. date_is_date();
  73. date_pad();
  74. date_has_time();
  75. date_has_date();
  76. date_part_format();
  77. date_limit_format();
  78. date_nongranularity();
  79. date_order_translated();
  80. date_order();
  81. date_range_valid();
  82. date_range_years();
  83. date_range_string();
  84. date_format_type_options();
  85. date_example_date();
  86. date_is_all_day();
  87. date_increment_round();
  88. date_make_iso_valid();
  89. Date calculation and navigation
  90. --------------------------------------------------------------------------------
  91. For example 'date_days_in_month()' identifies the number of days in a month for
  92. a date.
  93. date_days_in_month();
  94. date_days_in_year();
  95. date_iso_weeks_in_year();
  96. date_iso_week_range();
  97. date_weeks_in_year();
  98. date_day_of_week();
  99. date_day_of_week_name();
  100. date_week_range();
  101. date_week();
  102. date_get_timezone();
  103. date_get_timezone_db();
  104. Date regex and format helpers
  105. --------------------------------------------------------------------------------
  106. Pre-defined constants, an array of date format strings and their
  107. equivalent regex strings.
  108. DATE_REGEX_LOOSE is a very loose regex that will pull date parts out
  109. of an ISO date with or without separators, using either 'T' or a space
  110. to separate date and time, and with or without time.
  111. 'date_format_date()'' is similar to 'format_date()', except it takes a
  112. date object instead of a timestamp as the first parameter.
  113. DATE_FORMAT_ISO
  114. DATE_FORMAT_DATETIME
  115. DATE_FORMAT_UNIX
  116. DATE_FORMAT_ICAL
  117. DATE_REGEX_ISO
  118. DATE_REGEX_DATETIME
  119. DATE_REGEX_LOOSE
  120. date_format_date();
  121. date_format_patterns();
  122. date_format_interval();
  123. date_format_order();
  124. date_format_type_options();
  125. date_type_format();
  126. Standardized ical parser and creator
  127. --------------------------------------------------------------------------------
  128. The iCal parser is found in 'date_api_ical.inc', which is not included by
  129. default. Include that file if you want to use these functions:
  130. Complete rewrite of ical imports to parse vevents, vlocations, valarms,
  131. and all kinds of timezone options and repeat rules for ical imports.
  132. The function now sticks to parsing the ical into an array that can be used
  133. in various ways. It no longer trys to convert timezones while parsing instead a
  134. 'date_ical_date()' function is provided that can be used to convert from the
  135. ical timezone to the local timezone.
  136. iCal properties can be parsed into an array which other modules can manipulate
  137. however they like to create additional events from the results.
  138. The function 'date_api_ical_build_rrule()'' can be used to build an iCal RULE
  139. from $form_values.
  140. date_ical_import();
  141. date_ical_parse();
  142. date_ical_parse_date();
  143. date_ical_parse_rrule();
  144. date_ical_parse_exceptions();
  145. date_ical_parse_duration();
  146. date_ical_parse_text();
  147. date_ical_parse_location();
  148. date_ical_date();
  149. date_ical_escape_text();
  150. date_api_ical_build_rrule();
  151. Helpers for portable date SQL
  152. --------------------------------------------------------------------------------
  153. The SQL functions are found in date_api_sql.inc, which is not included by
  154. default. Include that file if you want to use these functions:
  155. date_sql_concat();
  156. date_sql_coalesce();
  157. date_sql_pad();
  158. Date forms and validators
  159. --------------------------------------------------------------------------------
  160. Reusable, configurable, self-validating FAPI date elements are found in
  161. date_api_elements.inc, which is not included by default. Include it if you want
  162. to use these elements. To use them, create a form element and set the '#type'
  163. to one of the following:
  164. date_select
  165. The date_select element will create a collection of form elements, with a
  166. separate select or textfield for each date part. The whole collection will
  167. get reformatted back into a date value of the requested type during
  168. validation.
  169. date_text
  170. The date_text element will create a textfield that can contain a whole date
  171. or any part of a date as text. The user input value will be re-formatted back
  172. into a date value of the requested type during validation.
  173. date_timezone
  174. The date_timezone element will create a drop-down selector to pick a timezone
  175. name.
  176. The custom date elements require a few other pieces of information to work
  177. correctly, like #date_format and #date_type. See the internal documentation
  178. for more information.
  179. Date Repeat API
  180. --------------------------------------------------------------------------------
  181. An API for repeating dates is available if installed. It can be used by other
  182. modules to create a form element that will allow users to select repeat rules
  183. and store those selections in an iCal RRULE string, and a calculation function
  184. that will parse the RRULE and return an array of dates that match those rules.
  185. The API is implemented in the Date module as a new date widget if the Date
  186. Repeat API is installed.
  187. RDF Integration
  188. --------------------------------------------------------------------------------
  189. To make RDF easier to use, the base date themes ('date_display_single' and
  190. 'date_display_range') have been expanded so they pass attributes and RDF
  191. mappings for the field, if any, to the theme. If RDF is installed and no other
  192. mappings are provided, the theme adds RDF information to mark both the Start
  193. and End dates as 'xsd:dateTime' datatypes with the property of 'dc:date'. This
  194. occurs in the theme preprocess layer, in particular via the functions
  195. 'template_preprocess_date_display_single()' and
  196. 'template_preprocess_date_display_range()'.
  197. To mark these as events instead, you could install the schemaorg module [1],
  198. which will load the schema.org vocabulary. The mark the content type that
  199. contains events as an 'Event', using the UI exposed by that module and set the
  200. event start date field with the 'dateStart' property and tag other fields in the
  201. content type with the appropriate property types. The Date module theme will
  202. wrap the start and end date output with appropriate markup.
  203. If the result is not quite what you need, you should be able to implement your
  204. own theme preprocess functions, e.g. 'MYTHEME_preprocess_date_display_single()'
  205. or 'MYTHEME_preprocess_date_display_range()' and alter the attributes to use the
  206. values you want.
  207. References
  208. --------------------------------------------------------------------------------
  209. 1: https://www.drupal.org/project/schemaorg