/[drupal]/contributions/modules/quiz/quiz_datetime.inc
ViewVC logotype

Contents of /contributions/modules/quiz/quiz_datetime.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Thu Aug 13 16:48:17 2009 UTC (3 months, 2 weeks ago) by sivaji
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
File MIME type: text/x-php
Merging GSoC code with HEAD.
1 <?php
2 // $Id: quiz_datetime.inc,v 1.3 2009/05/28 16:52:06 mbutcher Exp $
3
4 /////////////////////////////////
5 // Date and time routines for use with quiz module.
6 // - Based on event module
7 // - All references to event variables should be optional
8 /////////////////////////////////
9
10 /**
11 * @file
12 * Handles the start and end times in a node form submission.
13 * - Takes the array from form_date() and turns it into a timestamp
14 * - Adjusts times for time zone offsets.
15 * - Adapted from event.module
16 *
17 * @param $node The submitted node with form data.
18 * @param $date The name of the date ('quiz_open' or 'quiz_close') to translate.
19 */
20 function quiz_translate_form_date(&$node, $date) {
21 $prefix = $node->$date;
22 // If we have all the parameters, re-calculate $node->event_$date .
23 if (isset($prefix['year']) && isset($prefix['month']) && isset($prefix['day'])) {
24 // Build a timestamp based on the date supplied and the configured timezone.
25 $node->$date = _quiz_mktime(0, 0, 0, $prefix['month'], $prefix['day'], $prefix['year'], 0);
26 }
27 else {
28 form_set_error('quiz_open', t('Please supply a valid date.'));
29 }
30 }
31
32 /**
33 * Formats local time values to GMT timestamp using time zone offset supplied.
34 * All time values in the database are GMT and translated here prior to insertion.
35 *
36 * Time zone settings are applied in the following order:
37 * 1. If supplied, time zone offset is applied
38 * 2. If user time zones are enabled, user time zone offset is applied
39 * 3. If neither 1 nor 2 apply, the site time zone offset is applied
40 *
41 * @param $format The date() format to apply to the timestamp.
42 * @param $timestamp The GMT timestamp value.
43 * @param $offset Time zone offset to apply to the timestamp.
44 * @return gmdate() formatted date value
45 */
46 function _quiz_mktime($hour, $minute, $second, $month, $day, $year, $offset = NULL) {
47 global $user;
48 //print $user->timezone. " and ". variable_get('date_default_timezone', 0);
49 $timestamp = gmmktime($hour, $minute, $second, $month, $day, $year);
50 if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
51 return $timestamp - $user->timezone;
52 }
53 else {
54 return $timestamp - variable_get('date_default_timezone', 0);
55 }
56 }
57
58 /**
59 * Formats a GMT timestamp to local date values using time zone offset supplied.
60 * All timestamp values in event nodes are GMT and translated for display here.
61 *
62 * Pulled from event
63 *
64 * Time zone settings are applied in the following order
65 * 1. If supplied, time zone offset is applied
66 * 2. If user time zones are enabled, user time zone offset is applied
67 * 3. If neither 1 nor 2 apply, the site time zone offset is applied
68 *
69 * @param $format The date() format to apply to the timestamp.
70 * @param $timestamp The GMT timestamp value.
71 * @param $offset Time zone offset to apply to the timestamp.
72 * @return gmdate() formatted date value
73 */
74 function _quiz_date($format, $timestamp, $offset = NULL) {
75 global $user;
76
77 if (isset($offset)) {
78 $timestamp += $offset;
79 }
80 elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
81 $timestamp += $user->timezone;
82 }
83 else {
84 $timestamp += variable_get('date_default_timezone', 0);
85 }
86
87 // make sure we apply the site first day of the week setting for dow requests
88 $result = gmdate($format, $timestamp);
89 return $result;
90 }

  ViewVC Help
Powered by ViewVC 1.1.2