is there some example lying around that will help convert from event.module timestamp+timezone schema to date fields? can anyone suggest an approach?

Comments

Let me think about this. It should be possible using the date functions in date.inc.

OK, not sure if this is what you mean, but here is a bit of code to calculate the parts of an event date and get them into formats needed by the date module. I haven't actually tested this, so hopefully I didn't make any typos :-)

<?php
include_once(drupal_get_path('module', 'date') .'/date.inc');
include_once(
DATE_TIMEZONES);
// starting values
$timestamp = time(); // event timestamp
$zid = 477; // event timezone id
// calculate the offset for this date
$offset = event_get_offset($zid, $timestamp);
// get the timezone name for this date
$timezones = event_get_timezones();
$timezone = $timezones[$zid]['timezone'];
// calculate the ISO value for this date
$date = date_make_date();
date_set_date($date, $timestamp, $timezone, 'local', DATE_UNIX);
date_show_value($date, 'db', DATE_ISO);
?>

Or actually, the ISO value for the db value of the date could even just be this, since the timestamp is stored as GMT:

<?php
// calculate the ISO value for this date
$date = date_make_date();
date_set_date($date, $timestamp, 'GMT', 'db', DATE_UNIX);
date_show_value($date, 'db', DATE_ISO);
?>

I imagine you're trying to create an import script. I should play with this some more and try to come up with a more complete approach to take an event value out of the database and insert it into a date field. But anyway in the meantime maybe these will help.

This is completely untested and is just the beginning of a solution, but something like this might work:

<?php
include_once(drupal_get_path('module', 'date') .'/date.inc');
include_once(
DATE_TIMEZONES);
$type_name   = 'content_event'; // the content type to import these values into.
$field_name  = 'field_date'; // the field to import the start time into.
$field_name2 = 'field_date2'; // the field to import the end time into
$field_description = 'field_description'; // the field to import the description into
// Get info about the field we are importing into
$field   = content_fields($field_name);
// Get date tz handling, could be date, site, GMT, or none.
$tz_handling  = $field['tz_handling'];
// Get event tz handling, could be event, site, or user.
$event_tz_handling = variable_get('event_timezone_display', 'event');
$timezones = event_get_timezones();
$result = db_query("SELECT * FROM {event} ORDER BY event_start");
while (
$event = db_fetch_object($result)) {
 
$node = node_load($event->nid);
 
$node->nid = 0;
 
$node->type = $type_name;
 
$node->$description[0]['value'] = $node->body;
  unset(
$node->body);
 
$timestamp  = $event->event_start;
 
$timestamp2 = $event->event_end;
  if (
$field['type'] == 'date') {
   
$node->$field_name[0]['value'] = date_unix2iso($timestamp);
   
$node->$field_name2[0]['value'] = date_unix2iso($timestamp2);
  }
  else {
   
$node->$field_name[0]['value'] = $timestamp;
   
$node->$field_name2[0]['value'] = $timestamp2;
  }
  if (
$tz_handling == 'date' && $event_tz_handling == 'event') {
   
$node->$field_name[0]['timezone'] = $timezones[$event->timezone];
   
$node->$field_name[0]['offset']   = event_get_offset($event->timezone, $timestamp);
   
$node->$field_name2[0]['timezone'] = $timezones[$event->timezone2];
   
$node->$field_name2[0]['offset']   = event_get_offset($event->timezone, $timestamp2);
  }
 
node_save($node);
}
?>

Already saw a problem event without trying it. Should be:

<?php
include_once(drupal_get_path('module', 'date') .'/date.inc');
include_once(
DATE_TIMEZONES);
$type_name   = 'content_event'; // the content type to import these values into.
$field_name  = 'field_date'; // the field to import the start time into.
$field_name2 = 'field_date2'; // the field to import the end time into
$field_description = 'field_description'; // the field to import the description into
// Get info about the field we are importing into
$field   = content_fields($field_name);
// Get date tz handling, could be date, site, GMT, or none.
$tz_handling  = $field['tz_handling'];
// Get event tz handling, could be event, site, or user.
$event_tz_handling = variable_get('event_timezone_display', 'event');
$timezones = event_get_timezones();
$result = db_query("SELECT * FROM {event} ORDER BY event_start");
while (
$event = db_fetch_object($result)) {
 
$node = node_load($event->nid);
 
$node->nid = 0;
 
$node->type = $type_name;
 
$node->$description[0]['value'] = $node->body;
  unset(
$node->body);
 
$timestamp  = $event->event_start;
 
$timestamp2 = $event->event_end;
  if (
$field['type'] == 'date') {
   
$node->$field_name[0]['value'] = date_unix2iso($timestamp);
   
$node->$field_name2[0]['value'] = date_unix2iso($timestamp2);
  }
  else {
   
$node->$field_name[0]['value'] = $timestamp;
   
$node->$field_name2[0]['value'] = $timestamp2;
  }
  if (
$tz_handling == 'date' && $event_tz_handling == 'event') {
   
$node->$field_name[0]['timezone'] = $timezones[$event->timezone]['timezone'];
   
$node->$field_name[0]['offset']   = event_get_offset($event->timezone, $timestamp);
   
$node->$field_name2[0]['timezone'] = $timezones[$event->timezone2]['timezone'];
   
$node->$field_name2[0]['offset']   = event_get_offset($event->timezone, $timestamp2);
  }
 
node_save($node);
}
?>

Title:Code snippit for converting event.module timestamps to cck date fieldsImport Dates from Event or iCal
Category:task» feature

I just committed a very experimental module to the HEAD version of the Date code. It's called Date Copy and it allows you to import date information from either Event nodes or from an iCal feed. This is not production ready and needs testing, but is available for anyone who wants to try it out.

Status:Active» Fixed

Import for Events and iCal now seems to be working fairly well in the 5.x version (as an optional included module called Date Copy), so it is now available in both HEAD and 5.x. If someone wants it backported and creates a patch to do it, I'll commit the patch, but otherwise have no plans to backport this to 4.7 because is uses some 5.x FAPI features.

Status:Fixed» Closed (fixed)

Any port for drupal 6?

Just installed the date module - its tools do not seem to have any way to import d6 events to d7. Am I wrong?

@andrius when i was trying to solve this, i had to go back into D6 and use the date module event-to-date converter there, and then Date fields upgrade easily into D7. Really pesky!

Version:7.x-1.x-dev» 6.x-2.9

@HongPong - i have been trying to do this... the "date tools-import" event-to-date-convertor creates new node numbers. by doing this, other links gets messed up. additionally, the comments are lost in doing so. how can this be fixed?

I have been using the event module for my karting website for a number of years now. The site is now on drupal 6 and I plan to migrate to 7 soon. the site: http://club.my-kart.org/

not having a properly converted event becomes a problem for my existing events as well as future event scheduling (as my karting group organises regular karting events).