Révision 599a39cd
Ajouté par Assos Assos il y a environ 3 ans
drupal7/sites/all/modules/date/date.devel_generate.inc | ||
---|---|---|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* Implements hook_devel_generate(). |
10 |
* |
|
11 |
* Included only when needed. |
|
12 | 10 |
*/ |
13 | 11 |
function date_devel_generate($entity, $field, $instance, $bundle) { |
14 |
|
|
15 | 12 |
$entity_field = array(); |
16 | 13 |
if (isset($instance['widget']['settings']['year_range'])) { |
17 | 14 |
$split = explode(':', $instance['widget']['settings']['year_range']); |
18 | 15 |
// Determine how much to go back and forward depending on whether a relative |
19 | 16 |
// number of years (with - or + sign) or an absolute year is given. |
20 |
$back = strpos($split[0], '-') === 0 |
|
21 |
? str_replace('-', '', $split[0]) |
|
22 |
: date_format(date_now(), 'Y') - $split[0]; |
|
23 |
$forward = strpos($split[1], '+') === 0 |
|
24 |
? str_replace('+', '', $split[1]) |
|
25 |
: $split[1] - date_format(date_now(), 'Y'); |
|
17 |
$back = $split[0]; |
|
18 |
$forward = $split[1]; |
|
26 | 19 |
} |
27 | 20 |
else { |
28 | 21 |
$back = 2; |
... | ... | |
30 | 23 |
} |
31 | 24 |
// Pick a random year within the time range, |
32 | 25 |
// and a random second within that year. |
33 |
$year = date_format(date_now(), 'Y') - $back + mt_rand(0, ($forward + $back)); |
|
26 |
$this_year = date_format(date_now(), 'Y'); |
|
27 |
$year = mt_rand($this_year + $back, $this_year + $forward); |
|
34 | 28 |
$start = new DateObject($year . '-01-01 00:00:00', date_get_timezone_db($field['settings']['tz_handling'])); |
35 | 29 |
$leap = date_format($start, 'L'); |
36 | 30 |
$max_days = $leap ? 366 : 365; |
... | ... | |
39 | 33 |
$increment = $instance['widget']['settings']['increment']; |
40 | 34 |
date_increment_round($start, $increment); |
41 | 35 |
|
42 |
// Modify End date by 1 hour to 3 days, shorter for repeating dates |
|
43 |
// longer for others.
|
|
44 |
$start2 = clone($start);
|
|
36 |
// Modify End date by 1 hour to 3 days, shorter for repeating dates longer
|
|
37 |
// for others. |
|
38 |
$start2 = clone $start;
|
|
45 | 39 |
$max = !empty($field['settings']['repeat']) ? 720 : 4320; |
46 | 40 |
$max = 240; |
47 | 41 |
date_modify($start2, '+' . mt_rand(60, $max) . ' minutes'); |
48 | 42 |
date_increment_round($start2, $increment); |
49 | 43 |
|
50 | 44 |
if ($field['settings']['tz_handling'] == 'date') { |
51 |
// Choose a random timezone. |
|
52 |
// Not all keys exist, so we have to check. |
|
45 |
// Choose a random timezone. Not all keys exist, so we have to check. |
|
53 | 46 |
$timezones = array_keys(date_timezone_names(TRUE)); |
54 | 47 |
$key = mt_rand(0, count($timezones) - 1); |
55 | 48 |
if (!array_key_exists($key, $timezones)) { |
... | ... | |
86 | 79 |
date_timezone_set($start2, timezone_open($timezone)); |
87 | 80 |
$entity_field['offset2'] = date_offset_get($start2); |
88 | 81 |
return $entity_field; |
89 |
|
|
90 | 82 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules