source: sipes/modules_contrib/date/README.txt @ 1e95969

stableversion-3.0
Last change on this file since 1e95969 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100755
File size: 11.9 KB
Línea 
1INFORMATION FOR DEVELOPERS
2
3Once the Date API is installed, all functions in the API are available to be used
4anywhere by any module. If the Date Timezone module is installed, the system site
5timezone selector and the user timezone selectors are overwritten to allow the
6selection of timezone names instead of offsets. Proper timezone conversion
7requires knowledge of those timezone names, something that is not currently
8available in Drupal core, and the change in selectors makes it possible to track it.
9
10In most cases, you should enable the Date Timezone module any time you use the
11Date API to be able to set the site and user timezone names. It is not enabled by
12default in case another module is setting timezone names in the database.
13
14The API uses the PHP 5.2 date functions to create and manipulate dates, and
15contains an option module that will emulate those functions in earlier versions
16of PHP.
17
18If you are using PHP 4 or PHP 5.0 or 5.1, native date handling won't work right.
19Install the Date_PHP4 module to enable wrapper functions so this code will work
20in old PHP versions.
21
22Example, the following will create a date for the local value in one
23timezone, adjust it to a different timezone, then return the offset in seconds
24in the new timezone for the input date; The offset will be adjusted for both
25the timezone difference and daylight savings time, if necessary:
26
27$date = date_create('2007-03-11 02:00:00', timezone_open('America/Chicago'));
28$chicago_time = date_format($date, 'Y-m-d H:i');
29
30print 'At '. $chicago_time .' in Chicago, the timezone offset in seconds
31  was '. date_offset_get($date);
32
33date_timezone_set($date, timezone_open('Europe/Berlin');
34$berlin_time = date_format($date, 'Y-m-d H:i');
35
36print 'It was '. $berlin_time .' in Berlin when it
37  was '. $chicago_time .' in Chicago.';
38print 'At that time in Berlin, the timezone offset in seconds was
39  '. date_offset_get($date);
40
41A helper function is available, date_make_date($string, $timezone, $type),
42where $string is a unixtimestamp, an ISO date, or a string like YYYY-MM-DD HH:MM:SS,
43$timezone is the name of the timezone this date is in, and $type is the type
44of date it is (DATE_UNIX, DATE_ISO, or DATE_DATETIME). It create and return
45a date object set to the right date and timezone.
46
47Simpletest tests for these functions are included in the package.
48
49Available functions include the following (more documentation is provided in
50the files):
51
52============================================================================
53Date PHP4 Module
54============================================================================
55PHP 4 substitutions for the PHP 5 date functions are supplied. Use the PHP 5
56functions in your code as they would normally be used and the PHP 4
57alternatives will be automatically be substituted in when needed.
58
59You cannot do everything with these functions that can be done in PHP 5, but
60you can create dates, find timezone offsets, and format the results.
61Timezone handling uses native PHP 5 functions when available and degrades
62automatically for PHP 4 to use substitutions like those
63provided in previous versions of the Date and Event modules.
64
65Read the doxygen documentation in this module for more information
66about using the functions in ways that will work in PHP 4.
67
68Simpletest tests for the PHP 4 equivalent functions are included in the package.
69
70The following functions are emulated in PHP4:
71date_create()
72date_date_set()
73date_format()
74date_offset_get()
75date_timezone_set()
76timezone_abbreviations_list()
77timezone_identifiers_list()
78timezone_offset_get()
79timezone_open()
80
81============================================================================
82Preconfigured arrays
83============================================================================
84Both translated and untranslated values are available. The date_week_days_ordered()
85function will shift an array of week day names so it starts with the site's
86first day of the week, otherwise the weekday names start with Sunday as the first
87value, the expected order for many php and sql functions.
88
89date_month_names();
90date_month_names_abbr();
91date_month_names_untranslated();
92date_week_days();
93date_week_days_abbr();
94date_week_days_untranslated();
95date_week_days_ordered();
96date_years();
97date_hours();
98date_minutes();
99date_seconds();
100date_timezone_names();
101date_ampm();
102
103============================================================================
104Miscellaneous date manipulation functions
105============================================================================
106Pre-defined constants and functions that will handle pre-1970 and post-2038
107dates in both PHP 4 and PHP 5, in any OS. Dates can be converted from one
108type to another and date parts can be extracted from any date type.
109
110DATE_DATETIME
111DATE_ISO
112DATE_UNIX
113DATE_ARRAY
114DATE_OBJECT
115DATE_ICAL
116
117date_convert()
118date_is_valid();
119date_part_is_valid();
120date_part_extract();
121
122============================================================================
123Date calculation and navigation
124============================================================================
125date_difference() will find the time difference between any two days, measured
126in seconds, minutes, hours, days, months, weeks, or years.
127
128date_days_in_month();
129date_days_in_year();
130date_weeks_in_year();
131date_last_day_of_month();
132date_day_of_week();
133date_day_of_week_name();
134date_difference();
135
136============================================================================
137Date regex and format helpers
138============================================================================
139Pre-defined constants, an array of date format strings and their
140equivalent regex strings.
141
142DATE_REGEX_LOOSE is a very loose regex that will pull date parts out
143of an ISO date with or without separators, using either 'T' or a space
144to separate date and time, and with or without time.
145
146date_format_date() is similar to format_date(), except it takes a
147date object instead of a timestamp as the first parameter.
148
149DATE_FORMAT_ISO
150DATE_FORMAT_DATETIME
151DATE_FORMAT_UNIX
152DATE_FORMAT_ICAL
153
154DATE_REGEX_ISO
155DATE_REGEX_DATETIME
156DATE_REGEX_LOOSE
157
158date_format_date();
159date_t()
160date_short_formats();
161date_medium_formats();
162date_long_formats();
163date_format_patterns();
164
165============================================================================
166Standardized ical parser and creator
167============================================================================
168The iCal parser is found in date_api_ical.inc, which is not included by default.
169Include that file if you want to use these functions:
170
171Complete rewrite of ical imports to parse vevents, vlocations, valarms,
172and all kinds of timezone options and repeat rules for ical imports.
173The function now sticks to parsing the ical into an array that can be used
174in various ways. It no longer trys to convert timezones while parsing,
175instead a date_ical_date_format() function is provided that can be used to
176convert from the ical timezone to whatever timezone is desired in the
177results. Repeat rules are parsed into an array which other modules can
178manipulate however they like to create additional events from the results.
179
180date_ical_export();
181date_ical_import();
182date_ical_date_format();
183
184============================================================================
185Helpers for portable date SQL
186============================================================================
187The SQL functions are found in date_api_sql.inc, which is not included by default.
188Include that file if you want to use these functions:
189
190date_sql();
191date_server_zone_adj();
192date_sql_concat();
193date_sql_pad();
194
195============================================================================
196Date forms and validators
197============================================================================
198Reusable, configurable, self-validating FAPI date elements are found in
199date_api_elements.inc, which is not included by default. Include it
200if you want to use these elements. To use them, create a form element
201and set the '#type' to one of the following:
202
203date_select
204  The date_select element will create a collection of form elements, with a
205  separate select or textfield for each date part. The whole collection will
206  get re-formatted back into a date value of the requested type during validation.
207
208date_text
209 The date_text element will create a textfield that can contain a whole
210 date or any part of a date as text. The user input value will be re-formatted
211 back into a date value of the requested type during validation.
212
213date_timezone
214 The date_timezone element will create a drop-down selector to pick a
215 timezone name.
216
217The custom date elements require a few other pieces of information to work
218correctly, like #date_format and #date_type. See the internal documentation
219for more information.
220
221============================================================================
222Date Popup Module
223============================================================================
224
225A new module is included in the package that will enable a popup jQuery
226calendar date picker and timepicker in date and time fields.
227
228It is implemented as a custom form element, so set '#type' to 'date_popup'
229to use this element. See the internal documentation for more information.
230
231============================================================================
232Date Repeat API
233============================================================================
234
235An API for repeating dates is available if installed. It can be used by
236other modules to create a form element that will allow users to select
237repeat rules and store those selections in an iCal RRULE string, and a
238calculation function that will parse the RRULE and return an array of dates
239that match those rules. The API is implemented in the Date module as a
240new date widget if the Date Repeat API is installed.
241
242============================================================================
243Install file for dependent modules
244============================================================================
245
246The following code is an example of what should go in the .install file for
247any module that uses the new Date API. This is needed to be sure the system
248is not using an earlier version of the API that didn't include all these new
249features. Testing for version '5.2' will pick up any version on or after the
250change to the new API.
251
252/**
253 * Implementation of hook_requirements().
254 */
255function calendar_requirements($phase) {
256  $requirements = array();
257  $t = get_t();
258
259  // This is the minimum required version for the Date API so that it will
260     work with this module.
261  $required_version = 5.2;
262
263  // Make sure the matching version of date_api is installed.
264  // Use info instead of an error at install time since the problem may
265  // just be that they were installed in the wrong order.
266  switch ($phase) {
267    case 'runtime':
268      if (variable_get('date_api_version', 0) < $required_version) {
269        $requirements['calendar_api_version'] = array(
270          'title' => $t('Calendar requirements'),
271          'value' => $t('The Calendar module requires a more current version
272             of the Date API. Please check for a newer version.'),
273          'severity' => REQUIREMENT_ERROR,
274          );
275      }
276      break;
277     case 'install':
278      if (variable_get('date_api_version', 0) < $required_version) {
279        $requirements['calendar_api_version'] = array(
280          'title' => $t('Calendar requirements'),
281          'value' => $t('The Calendar module requires the latest version
282             of the Date API, be sure you are installing the latest versions
283             of both modules.'),
284          'severity' => REQUIREMENT_INFO,
285          );
286      }
287      break;
288  }
289  return $requirements;
290}
291
292/**
293 * Implementation of hook_install().
294 */
295function calendar_install() {
296  // Make sure this module loads after date_api.
297  db_query("UPDATE {system} SET weight = 1 WHERE name = 'calendar'");
298}
299
300/**
301 * Implementation of hook_update().
302 */
303function calendar_update_5000() {
304  $ret = array();
305  $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'calendar'");
306  return $ret;
307}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.