date_content_generate.inc in Date 6
File
date/date_content_generate.inc
View source
<?php
function _date_content_generate($node, $field) {
$node_field = array();
if (isset($field['widget']['year_range'])) {
$split = ':';
$back = str_replace('-', '', $split[0]);
$forward = str_replace('+', '', $split[1]);
}
else {
$back = 2;
$forward = 2;
}
$year = date_format(date_now(), 'Y') - $back + rand(0, $forward + $back);
$start = date_make_date($year . '-01-01 00:00:00', 'UTC');
$leap = date_format($start, 'L');
$max_days = $leap ? 366 : 365;
date_modify($start, '+' . rand(0, $max_days * 86400) . ' seconds');
$start2 = drupal_clone($start);
date_modify($start2, '+' . rand(60, 1440) . ' minutes');
if ($field['tz_handling'] == 'date') {
$timezones = array_keys(date_timezone_names(TRUE, TRUE));
shuffle($timezones);
$timezone = $timezones[0];
}
switch ($field['type']) {
case 'date':
$format = DATE_FORMAT_ISO;
break;
case 'datestamp':
$format = DATE_FORMAT_UNIX;
break;
case 'datetime':
$format = DATE_FORMAT_DATETIME;
break;
}
$count = $field['multiple'] > 0 && $field['multiple'] < 99 ? rand(1, 6) : 1;
for ($i = 0; $i < $count; $i++) {
$node_field[$i]['value'] = date_format($start, $format);
if ($field['todate']) {
$node_field[$i]['value2'] = date_format($start2, $format);
}
if ($field['tz_handling'] == 'date') {
date_timezone_set($start, timezone_open($timezone));
$node_field[$i]['timezone'] = $timezone;
$node_field[$i]['offset'] = date_offset_get($start);
if ($field['todate']) {
date_timezone_set($start2, timezone_open($timezone));
$node_field[$i]['offset2'] = date_offset_get($start2);
}
}
}
if ($field['multiple'] == 99) {
}
return $node_field;
}