Révision b720ea3e
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/date/date_api/date_api.module | ||
---|---|---|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
if (module_exists('date_tools')) { |
62 |
$output .= '<h3>Date Tools</h3>' . t('Dates and calendars can be complicated to set up. The !date_wizard makes it easy to create a simple date content type and with a date field. ', array('!date_wizard' => l(t('Date wizard'), 'admin/config/date/tools/date_wizard')));
|
|
62 |
$output .= '<h3>Date Tools</h3>' . t('Dates and calendars can be complicated to set up. The !date_wizard makes it easy to create a simple date content type and with a date field.', array('!date_wizard' => l(t('Date wizard'), 'admin/config/date/tools/date_wizard'))); |
|
63 | 63 |
} |
64 | 64 |
else { |
65 |
$output .= '<h3>Date Tools</h3>' . t('Dates and calendars can be complicated to set up. If you enable the Date Tools module, it provides a Date Wizard that makes it easy to create a simple date content type with a date field. ');
|
|
65 |
$output .= '<h3>Date Tools</h3>' . t('Dates and calendars can be complicated to set up. If you enable the Date Tools module, it provides a Date Wizard that makes it easy to create a simple date content type with a date field.'); |
|
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
$output .= '<h2>More Information</h2><p>' . t('Complete documentation for the Date and Date API modules is available at <a href="@link">http://drupal.org/node/92460</a>.', array('@link' => 'http://drupal.org/node/262062')) . '</p>'; |
69 | 69 |
|
70 | 70 |
return $output; |
71 |
break; |
|
71 |
|
|
72 | 72 |
} |
73 | 73 |
} |
74 | 74 |
|
... | ... | |
101 | 101 |
$value = variable_get('date_format_medium'); |
102 | 102 |
if (isset($value)) { |
103 | 103 |
$now = date_now(); |
104 |
$success_messages[] = $t('The medium date format type has been set to to @value. You may find it helpful to add new format types like Date, Time, Month, or Year, with appropriate formats, at <a href="@regional_date_time">Date and time</a> settings.', array('@value' => $now->format($value), '@regional_date_time' => url('admin/config/regional/date-time')));
|
|
104 |
$success_messages[] = $t('The medium date format type has been set to @value. You may find it helpful to add new format types like Date, Time, Month, or Year, with appropriate formats, at <a href="@regional_date_time">Date and time</a> settings.', array('@value' => $now->format($value), '@regional_date_time' => url('admin/config/regional/date-time'))); |
|
105 | 105 |
} |
106 | 106 |
else { |
107 | 107 |
$error_messages[] = $t('The Date API requires that you set up the <a href="@regional_date_time">system date formats</a> to function correctly.', array('@regional_date_time' => url('admin/config/regional/date-time'))); |
... | ... | |
143 | 143 |
class DateObject extends DateTime { |
144 | 144 |
public $granularity = array(); |
145 | 145 |
public $errors = array(); |
146 |
protected static $allgranularity = array('year', 'month', 'day', 'hour', 'minute', 'second', 'timezone'); |
|
146 |
protected static $allgranularity = array( |
|
147 |
'year', |
|
148 |
'month', |
|
149 |
'day', |
|
150 |
'hour', |
|
151 |
'minute', |
|
152 |
'second', |
|
153 |
'timezone' |
|
154 |
); |
|
147 | 155 |
private $serializedTime; |
148 | 156 |
private $serializedTimezone; |
149 | 157 |
|
... | ... | |
402 | 410 |
* A single date part. |
403 | 411 |
*/ |
404 | 412 |
public function removeGranularity($g) { |
405 |
if ($key = array_search($g, $this->granularity)) {
|
|
413 |
if (($key = array_search($g, $this->granularity)) !== FALSE) {
|
|
406 | 414 |
unset($this->granularity[$key]); |
407 | 415 |
} |
408 | 416 |
} |
... | ... | |
458 | 466 |
$true = $this->hasGranularity() && (!$granularity || $flexible || $this->hasGranularity($granularity)); |
459 | 467 |
if (!$true && $granularity) { |
460 | 468 |
foreach ((array) $granularity as $part) { |
461 |
if (!$this->hasGranularity($part) && in_array($part, array('second', 'minute', 'hour', 'day', 'month', 'year'))) { |
|
469 |
if (!$this->hasGranularity($part) && in_array($part, array( |
|
470 |
'second', |
|
471 |
'minute', |
|
472 |
'hour', |
|
473 |
'day', |
|
474 |
'month', |
|
475 |
'year') |
|
476 |
)) { |
|
462 | 477 |
switch ($part) { |
463 | 478 |
case 'second': |
464 | 479 |
$this->errors[$part] = t('The second is missing.'); |
465 | 480 |
break; |
481 |
|
|
466 | 482 |
case 'minute': |
467 | 483 |
$this->errors[$part] = t('The minute is missing.'); |
468 | 484 |
break; |
485 |
|
|
469 | 486 |
case 'hour': |
470 | 487 |
$this->errors[$part] = t('The hour is missing.'); |
471 | 488 |
break; |
489 |
|
|
472 | 490 |
case 'day': |
473 | 491 |
$this->errors[$part] = t('The day is missing.'); |
474 | 492 |
break; |
493 |
|
|
475 | 494 |
case 'month': |
476 | 495 |
$this->errors[$part] = t('The month is missing.'); |
477 | 496 |
break; |
497 |
|
|
478 | 498 |
case 'year': |
479 | 499 |
$this->errors[$part] = t('The year is missing.'); |
480 | 500 |
break; |
... | ... | |
537 | 557 |
$temp = date_parse($time); |
538 | 558 |
// Special case for 'now'. |
539 | 559 |
if ($time == 'now') { |
540 |
$this->granularity = array('year', 'month', 'day', 'hour', 'minute', 'second'); |
|
560 |
$this->granularity = array( |
|
561 |
'year', |
|
562 |
'month', |
|
563 |
'day', |
|
564 |
'hour', |
|
565 |
'minute', |
|
566 |
'second', |
|
567 |
); |
|
541 | 568 |
} |
542 | 569 |
else { |
543 | 570 |
// This PHP date_parse() method currently doesn't have resolution down to |
... | ... | |
600 | 627 |
return FALSE; |
601 | 628 |
} |
602 | 629 |
$this->granularity = array(); |
603 |
$final_date = array('hour' => 0, 'minute' => 0, 'second' => 0, 'month' => 1, 'day' => 1, 'year' => 0); |
|
630 |
$final_date = array( |
|
631 |
'hour' => 0, |
|
632 |
'minute' => 0, |
|
633 |
'second' => 0, |
|
634 |
'month' => 1, |
|
635 |
'day' => 1, |
|
636 |
'year' => 0, |
|
637 |
); |
|
604 | 638 |
foreach ($letters as $i => $letter) { |
605 | 639 |
$value = $values[$i]; |
606 | 640 |
switch ($letter) { |
... | ... | |
609 | 643 |
$final_date['day'] = intval($value); |
610 | 644 |
$this->addGranularity('day'); |
611 | 645 |
break; |
646 |
|
|
612 | 647 |
case 'n': |
613 | 648 |
case 'm': |
614 | 649 |
$final_date['month'] = intval($value); |
615 | 650 |
$this->addGranularity('month'); |
616 | 651 |
break; |
652 |
|
|
617 | 653 |
case 'F': |
618 | 654 |
$array_month_long = array_flip(date_month_names()); |
619 | 655 |
$final_date['month'] = array_key_exists($value, $array_month_long) ? $array_month_long[$value] : -1; |
620 | 656 |
$this->addGranularity('month'); |
621 | 657 |
break; |
658 |
|
|
622 | 659 |
case 'M': |
623 | 660 |
$array_month = array_flip(date_month_names_abbr()); |
624 | 661 |
$final_date['month'] = array_key_exists($value, $array_month) ? $array_month[$value] : -1; |
625 | 662 |
$this->addGranularity('month'); |
626 | 663 |
break; |
664 |
|
|
627 | 665 |
case 'Y': |
628 | 666 |
$final_date['year'] = $value; |
629 | 667 |
$this->addGranularity('year'); |
... | ... | |
631 | 669 |
$this->errors['year'] = t('The year is invalid. Please check that entry includes four digits.'); |
632 | 670 |
} |
633 | 671 |
break; |
672 |
|
|
634 | 673 |
case 'y': |
635 | 674 |
$year = $value; |
636 | 675 |
// If no century, we add the current one ("06" => "2006"). |
637 | 676 |
$final_date['year'] = str_pad($year, 4, substr(date("Y"), 0, 2), STR_PAD_LEFT); |
638 | 677 |
$this->addGranularity('year'); |
639 | 678 |
break; |
679 |
|
|
640 | 680 |
case 'a': |
641 | 681 |
case 'A': |
642 | 682 |
$ampm = strtolower($value); |
643 | 683 |
break; |
684 |
|
|
644 | 685 |
case 'g': |
645 | 686 |
case 'h': |
646 | 687 |
case 'G': |
... | ... | |
648 | 689 |
$final_date['hour'] = intval($value); |
649 | 690 |
$this->addGranularity('hour'); |
650 | 691 |
break; |
692 |
|
|
651 | 693 |
case 'i': |
652 | 694 |
$final_date['minute'] = intval($value); |
653 | 695 |
$this->addGranularity('minute'); |
654 | 696 |
break; |
697 |
|
|
655 | 698 |
case 's': |
656 | 699 |
$final_date['second'] = intval($value); |
657 | 700 |
$this->addGranularity('second'); |
658 | 701 |
break; |
702 |
|
|
659 | 703 |
case 'U': |
660 | 704 |
parent::__construct($value, $tz ? $tz : new DateTimeZone("UTC")); |
661 | 705 |
$this->addGranularity('year'); |
... | ... | |
665 | 709 |
$this->addGranularity('minute'); |
666 | 710 |
$this->addGranularity('second'); |
667 | 711 |
return $this; |
668 |
break; |
|
712 |
|
|
669 | 713 |
} |
670 | 714 |
} |
671 | 715 |
if (isset($ampm) && $ampm == 'pm' && $final_date['hour'] < 12) { |
... | ... | |
758 | 802 |
// date or we will get date slippage, i.e. a value of 2011-00-00 will get |
759 | 803 |
// interpreted as November of 2010 by PHP. |
760 | 804 |
if ($full) { |
761 |
$arr += array('year' => 0, 'month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0); |
|
805 |
$arr += array( |
|
806 |
'year' => 0, |
|
807 |
'month' => 1, |
|
808 |
'day' => 1, |
|
809 |
'hour' => 0, |
|
810 |
'minute' => 0, |
|
811 |
'second' => 0, |
|
812 |
); |
|
762 | 813 |
} |
763 | 814 |
else { |
764 |
$arr += array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => ''); |
|
815 |
$arr += array( |
|
816 |
'year' => '', |
|
817 |
'month' => '', |
|
818 |
'day' => '', |
|
819 |
'hour' => '', |
|
820 |
'minute' => '', |
|
821 |
'second' => '', |
|
822 |
); |
|
765 | 823 |
} |
766 | 824 |
$datetime = ''; |
767 | 825 |
if ($arr['year'] !== '') { |
... | ... | |
839 | 897 |
case 'year': |
840 | 898 |
$fallback = $now->format('Y'); |
841 | 899 |
return !is_int($value) || empty($value) || $value < variable_get('date_min_year', 1) || $value > variable_get('date_max_year', 4000) ? $fallback : $value; |
842 |
break; |
|
900 |
|
|
843 | 901 |
case 'month': |
844 | 902 |
$fallback = $default == 'first' ? 1 : $now->format('n'); |
845 | 903 |
return !is_int($value) || empty($value) || $value <= 0 || $value > 12 ? $fallback : $value; |
846 |
break; |
|
904 |
|
|
847 | 905 |
case 'day': |
848 | 906 |
$fallback = $default == 'first' ? 1 : $now->format('j'); |
849 | 907 |
$max_day = isset($year) && isset($month) ? date_days_in_month($year, $month) : 31; |
850 | 908 |
return !is_int($value) || empty($value) || $value <= 0 || $value > $max_day ? $fallback : $value; |
851 |
break; |
|
909 |
|
|
852 | 910 |
case 'hour': |
853 | 911 |
$fallback = $default == 'first' ? 0 : $now->format('G'); |
854 | 912 |
return !is_int($value) || $value < 0 || $value > 23 ? $fallback : $value; |
855 |
break; |
|
913 |
|
|
856 | 914 |
case 'minute': |
857 | 915 |
$fallback = $default == 'first' ? 0 : $now->format('i'); |
858 | 916 |
return !is_int($value) || $value < 0 || $value > 59 ? $fallback : $value; |
859 |
break; |
|
917 |
|
|
860 | 918 |
case 'second': |
861 | 919 |
$fallback = $default == 'first' ? 0 : $now->format('s'); |
862 | 920 |
return !is_int($value) || $value < 0 || $value > 59 ? $fallback : $value; |
863 |
break; |
|
864 | 921 |
} |
865 | 922 |
} |
866 | 923 |
|
... | ... | |
898 | 955 |
case 'year': |
899 | 956 |
$errors['year'] = t('The year is invalid.'); |
900 | 957 |
break; |
958 |
|
|
901 | 959 |
case 'month': |
902 | 960 |
$errors['month'] = t('The month is invalid.'); |
903 | 961 |
break; |
962 |
|
|
904 | 963 |
case 'day': |
905 | 964 |
$errors['day'] = t('The day is invalid.'); |
906 | 965 |
break; |
966 |
|
|
907 | 967 |
case 'hour': |
908 | 968 |
$errors['hour'] = t('The hour is invalid.'); |
909 | 969 |
break; |
970 |
|
|
910 | 971 |
case 'minute': |
911 | 972 |
$errors['minute'] = t('The minute is invalid.'); |
912 | 973 |
break; |
974 |
|
|
913 | 975 |
case 'second': |
914 | 976 |
$errors['second'] = t('The second is invalid.'); |
915 | 977 |
break; |
... | ... | |
929 | 991 |
* The stop date. |
930 | 992 |
* @param string $measure |
931 | 993 |
* (optional) A granularity date part. Defaults to 'seconds'. |
932 |
* @param boolean $absolute
|
|
994 |
* @param bool $absolute |
|
933 | 995 |
* (optional) Indicate whether the absolute value of the difference should |
934 | 996 |
* be returned or if the sign should be retained. Defaults to TRUE. |
935 | 997 |
*/ |
... | ... | |
955 | 1017 |
// The easy cases first. |
956 | 1018 |
case 'seconds': |
957 | 1019 |
return $diff; |
1020 |
|
|
958 | 1021 |
case 'minutes': |
959 | 1022 |
return $diff / 60; |
1023 |
|
|
960 | 1024 |
case 'hours': |
961 | 1025 |
return $diff / 3600; |
1026 |
|
|
962 | 1027 |
case 'years': |
963 | 1028 |
return $year_diff; |
964 | 1029 |
|
... | ... | |
1013 | 1078 |
$sign = ($year_diff < 0) ? -1 : 1; |
1014 | 1079 |
|
1015 | 1080 |
for ($i = 1; $i <= abs($year_diff); $i++) { |
1016 |
date_modify($date1, (($sign > 0) ? '+': '-').'1 year');
|
|
1081 |
date_modify($date1, (($sign > 0) ? '+' : '-') . '1 year');
|
|
1017 | 1082 |
$week_diff += (date_iso_weeks_in_year($date1) * $sign); |
1018 | 1083 |
} |
1019 | 1084 |
return $week_diff; |
... | ... | |
1060 | 1125 |
switch ($type) { |
1061 | 1126 |
case DATE_ISO: |
1062 | 1127 |
return DATE_FORMAT_ISO; |
1128 |
|
|
1063 | 1129 |
case DATE_UNIX: |
1064 | 1130 |
return DATE_FORMAT_UNIX; |
1131 |
|
|
1065 | 1132 |
case DATE_DATETIME: |
1066 | 1133 |
return DATE_FORMAT_DATETIME; |
1134 |
|
|
1067 | 1135 |
case DATE_ICAL: |
1068 | 1136 |
return DATE_FORMAT_ICAL; |
1069 | 1137 |
} |
... | ... | |
1119 | 1187 |
} |
1120 | 1188 |
|
1121 | 1189 |
/** |
1122 |
* Constructs a translated array of month name abbreviations |
|
1190 |
* Constructs a translated array of month name abbreviations.
|
|
1123 | 1191 |
* |
1124 | 1192 |
* @param bool $required |
1125 | 1193 |
* (optional) If FALSE, the returned array will include a blank value. |
... | ... | |
1211 | 1279 |
case 1: |
1212 | 1280 |
$context = 'day_abbr1'; |
1213 | 1281 |
break; |
1282 |
|
|
1214 | 1283 |
case 2: |
1215 | 1284 |
$context = 'day_abbr2'; |
1216 | 1285 |
break; |
1286 |
|
|
1217 | 1287 |
default: |
1218 | 1288 |
$context = ''; |
1219 | 1289 |
break; |
... | ... | |
1248 | 1318 |
/** |
1249 | 1319 |
* Constructs an array of years. |
1250 | 1320 |
* |
1251 |
* @param int $min
|
|
1252 |
* The minimum year in the array.
|
|
1253 |
* @param int $max
|
|
1254 |
* The maximum year in the array.
|
|
1321 |
* @param int $start
|
|
1322 |
* The start year in the array.
|
|
1323 |
* @param int $end
|
|
1324 |
* The end year in the array.
|
|
1255 | 1325 |
* @param bool $required |
1256 | 1326 |
* (optional) If FALSE, the returned array will include a blank value. |
1257 | 1327 |
* Defaults to FALSE. |
... | ... | |
1259 | 1329 |
* @return array |
1260 | 1330 |
* An array of years in the selected range. |
1261 | 1331 |
*/ |
1262 |
function date_years($min = 0, $max = 0, $required = FALSE) {
|
|
1332 |
function date_years($start = 0, $end = 0, $required = FALSE) {
|
|
1263 | 1333 |
// Ensure $min and $max are valid values. |
1264 |
if (empty($min)) {
|
|
1265 |
$min = intval(date('Y', REQUEST_TIME) - 3);
|
|
1334 |
if (empty($start)) {
|
|
1335 |
$start = intval(date('Y', REQUEST_TIME) - 3);
|
|
1266 | 1336 |
} |
1267 |
if (empty($max)) {
|
|
1268 |
$max = intval(date('Y', REQUEST_TIME) + 3);
|
|
1337 |
if (empty($end)) {
|
|
1338 |
$end = intval(date('Y', REQUEST_TIME) + 3);
|
|
1269 | 1339 |
} |
1270 | 1340 |
$none = array(0 => ''); |
1271 |
return !$required ? $none + drupal_map_assoc(range($min, $max)) : drupal_map_assoc(range($min, $max));
|
|
1341 |
return !$required ? $none + drupal_map_assoc(range($start, $end)) : drupal_map_assoc(range($start, $end));
|
|
1272 | 1342 |
} |
1273 | 1343 |
|
1274 | 1344 |
/** |
... | ... | |
1474 | 1544 |
* An array of date parts. |
1475 | 1545 |
*/ |
1476 | 1546 |
function date_granularity_sorted($granularity) { |
1477 |
return array_intersect(array('year', 'month', 'day', 'hour', 'minute', 'second'), $granularity); |
|
1547 |
return array_intersect(array( |
|
1548 |
'year', |
|
1549 |
'month', |
|
1550 |
'day', |
|
1551 |
'hour', |
|
1552 |
'minute', |
|
1553 |
'second', |
|
1554 |
), $granularity); |
|
1478 | 1555 |
} |
1479 | 1556 |
|
1480 | 1557 |
/** |
... | ... | |
1492 | 1569 |
switch ($precision) { |
1493 | 1570 |
case 'year': |
1494 | 1571 |
return array_slice($granularity_array, -6, 1); |
1572 |
|
|
1495 | 1573 |
case 'month': |
1496 | 1574 |
return array_slice($granularity_array, -6, 2); |
1575 |
|
|
1497 | 1576 |
case 'day': |
1498 | 1577 |
return array_slice($granularity_array, -6, 3); |
1578 |
|
|
1499 | 1579 |
case 'hour': |
1500 | 1580 |
return array_slice($granularity_array, -6, 4); |
1581 |
|
|
1501 | 1582 |
case 'minute': |
1502 | 1583 |
return array_slice($granularity_array, -6, 5); |
1584 |
|
|
1503 | 1585 |
default: |
1504 | 1586 |
return $granularity_array; |
1505 | 1587 |
} |
... | ... | |
1533 | 1615 |
switch ($granularity) { |
1534 | 1616 |
case 'year': |
1535 | 1617 |
return substr($format, 0, 1); |
1618 |
|
|
1536 | 1619 |
case 'month': |
1537 | 1620 |
return substr($format, 0, 3); |
1621 |
|
|
1538 | 1622 |
case 'day': |
1539 | 1623 |
return substr($format, 0, 5); |
1624 |
|
|
1540 | 1625 |
case 'hour'; |
1541 | 1626 |
return substr($format, 0, 7); |
1627 |
|
|
1542 | 1628 |
case 'minute': |
1543 | 1629 |
return substr($format, 0, 9); |
1630 |
|
|
1544 | 1631 |
default: |
1545 | 1632 |
return $format; |
1546 | 1633 |
} |
... | ... | |
1657 | 1744 |
case 'l': |
1658 | 1745 |
$datestring .= t($date->format('l'), array(), array('context' => '', 'langcode' => $langcode)); |
1659 | 1746 |
break; |
1747 |
|
|
1660 | 1748 |
case 'D': |
1661 | 1749 |
$datestring .= t($date->format('D'), array(), array('context' => '', 'langcode' => $langcode)); |
1662 | 1750 |
break; |
1751 |
|
|
1663 | 1752 |
case 'F': |
1664 | 1753 |
$datestring .= t($date->format('F'), array(), array('context' => 'Long month name', 'langcode' => $langcode)); |
1665 | 1754 |
break; |
1755 |
|
|
1666 | 1756 |
case 'M': |
1667 | 1757 |
$datestring .= t($date->format('M'), array(), array('langcode' => $langcode)); |
1668 | 1758 |
break; |
1759 |
|
|
1669 | 1760 |
case 'A': |
1670 | 1761 |
case 'a': |
1671 | 1762 |
$datestring .= t($date->format($c), array(), array('context' => 'ampm', 'langcode' => $langcode)); |
1672 | 1763 |
break; |
1764 |
|
|
1673 | 1765 |
// The timezone name translations can use t(). |
1674 | 1766 |
case 'e': |
1675 | 1767 |
case 'T': |
1676 | 1768 |
$datestring .= t($date->format($c)); |
1677 | 1769 |
break; |
1770 |
|
|
1678 | 1771 |
// Remaining date parts need no translation. |
1679 | 1772 |
case 'O': |
1680 | 1773 |
$datestring .= sprintf('%s%02d%02d', (date_offset_get($date) < 0 ? '-' : '+'), abs(date_offset_get($date) / 3600), abs(date_offset_get($date) % 3600) / 60); |
1681 | 1774 |
break; |
1775 |
|
|
1682 | 1776 |
case 'P': |
1683 | 1777 |
$datestring .= sprintf('%s%02d:%02d', (date_offset_get($date) < 0 ? '-' : '+'), abs(date_offset_get($date) / 3600), abs(date_offset_get($date) % 3600) / 60); |
1684 | 1778 |
break; |
1779 |
|
|
1685 | 1780 |
case 'Z': |
1686 | 1781 |
$datestring .= date_offset_get($date); |
1687 | 1782 |
break; |
1783 |
|
|
1688 | 1784 |
case '\\': |
1689 | 1785 |
$datestring .= $format[++$i]; |
1690 | 1786 |
break; |
1787 |
|
|
1691 | 1788 |
case 'r': |
1692 |
$datestring .= date_format_date($date, 'custom', 'D, d M Y H:i:s O', $langcode);
|
|
1789 |
$datestring .= date_format_date($date, 'custom', 'D, d M Y H:i:s O', 'en');
|
|
1693 | 1790 |
break; |
1791 |
|
|
1694 | 1792 |
default: |
1695 | 1793 |
if (strpos('BdcgGhHiIjLmnNosStTuUwWYyz', $c) !== FALSE) { |
1696 | 1794 |
$datestring .= $date->format($c); |
... | ... | |
1739 | 1837 |
* (optional) Optionally force time to a specific timezone, defaults to user |
1740 | 1838 |
* timezone, if set, otherwise site timezone. Defaults to NULL. |
1741 | 1839 |
* |
1742 |
* @param boolean $reset [optional]
|
|
1743 |
* Static cache reset
|
|
1840 |
* @param bool $reset
|
|
1841 |
* (optional) Static cache reset.
|
|
1744 | 1842 |
* |
1745 | 1843 |
* @return object |
1746 | 1844 |
* The current time as a date object. |
... | ... | |
1831 | 1929 |
* @param mixed $date |
1832 | 1930 |
* (optional) The current date object, or a date string. Defaults to NULL. |
1833 | 1931 |
* |
1834 |
* @return integer
|
|
1932 |
* @return int |
|
1835 | 1933 |
* The number of days in the year. |
1836 | 1934 |
*/ |
1837 | 1935 |
function date_days_in_year($date = NULL) { |
... | ... | |
1860 | 1958 |
* @param mixed $date |
1861 | 1959 |
* (optional) The current date object, or a date string. Defaults to NULL. |
1862 | 1960 |
* |
1863 |
* @return integer
|
|
1961 |
* @return int |
|
1864 | 1962 |
* The number of ISO weeks in a year. |
1865 | 1963 |
*/ |
1866 | 1964 |
function date_iso_weeks_in_year($date = NULL) { |
... | ... | |
1952 | 2050 |
|
1953 | 2051 |
// Move forwards to the last day of the week. |
1954 | 2052 |
$max_date = clone($min_date); |
1955 |
date_modify($max_date, '+7 days');
|
|
2053 |
date_modify($max_date, '+6 days');
|
|
1956 | 2054 |
|
1957 | 2055 |
if (date_format($min_date, 'Y') != $year) { |
1958 | 2056 |
$min_date = new DateObject($year . '-01-01 00:00:00'); |
... | ... | |
1986 | 2084 |
|
1987 | 2085 |
// Move forwards to the last day of the week. |
1988 | 2086 |
$max_date = clone($min_date); |
1989 |
date_modify($max_date, '+7 days');
|
|
2087 |
date_modify($max_date, '+6 days');
|
|
1990 | 2088 |
return array($min_date, $max_date); |
1991 | 2089 |
} |
1992 | 2090 |
|
... | ... | |
2094 | 2192 |
if (!is_array($granularity)) { |
2095 | 2193 |
$granularity = array(); |
2096 | 2194 |
} |
2097 |
return (bool) count(array_intersect($granularity, array('hour', 'minute', 'second'))); |
|
2195 |
$options = array('hour', 'minute', 'second'); |
|
2196 |
return (bool) count(array_intersect($granularity, $options)); |
|
2098 | 2197 |
} |
2099 | 2198 |
|
2100 | 2199 |
/** |
... | ... | |
2110 | 2209 |
if (!is_array($granularity)) { |
2111 | 2210 |
$granularity = array(); |
2112 | 2211 |
} |
2113 |
return (bool) count(array_intersect($granularity, array('year', 'month', 'day'))); |
|
2212 |
$options = array('year', 'month', 'day'); |
|
2213 |
return (bool) count(array_intersect($granularity, $options)); |
|
2114 | 2214 |
} |
2115 | 2215 |
|
2116 | 2216 |
/** |
... | ... | |
2128 | 2228 |
switch ($part) { |
2129 | 2229 |
case 'date': |
2130 | 2230 |
return date_limit_format($format, array('year', 'month', 'day')); |
2231 |
|
|
2131 | 2232 |
case 'time': |
2132 | 2233 |
return date_limit_format($format, array('hour', 'minute', 'second')); |
2234 |
|
|
2133 | 2235 |
default: |
2134 | 2236 |
return date_limit_format($format, array($part)); |
2135 | 2237 |
} |
... | ... | |
2157 | 2259 |
$drupal_static_fast['formats'] = &drupal_static(__FUNCTION__); |
2158 | 2260 |
} |
2159 | 2261 |
$formats = &$drupal_static_fast['formats']; |
2160 |
$format_granularity_cid = $format .'|'. implode(',', $granularity);
|
|
2262 |
$format_granularity_cid = $format . '|' . implode(',', $granularity);
|
|
2161 | 2263 |
if (isset($formats[$format_granularity_cid])) { |
2162 | 2264 |
return $formats[$format_granularity_cid]; |
2163 | 2265 |
} |
... | ... | |
2191 | 2293 |
case 'year': |
2192 | 2294 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[Yy])'; |
2193 | 2295 |
break; |
2296 |
|
|
2194 | 2297 |
case 'day': |
2195 | 2298 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[l|D|d|dS|j|jS|N|w|W|z]{1,2})'; |
2196 | 2299 |
break; |
2300 |
|
|
2197 | 2301 |
case 'month': |
2198 | 2302 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[FMmn])'; |
2199 | 2303 |
break; |
2304 |
|
|
2200 | 2305 |
case 'hour': |
2201 | 2306 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[HhGg])'; |
2202 | 2307 |
break; |
2308 |
|
|
2203 | 2309 |
case 'minute': |
2204 | 2310 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[i])'; |
2205 | 2311 |
break; |
2312 |
|
|
2206 | 2313 |
case 'second': |
2207 | 2314 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[s])'; |
2208 | 2315 |
break; |
2316 |
|
|
2209 | 2317 |
case 'timezone': |
2210 | 2318 |
$regex[] = '([\-/\.,:]?\s?(?<!\\\\)[TOZPe])'; |
2211 | 2319 |
break; |
... | ... | |
2278 | 2386 |
case 'j': |
2279 | 2387 |
$order[] = 'day'; |
2280 | 2388 |
break; |
2389 |
|
|
2281 | 2390 |
case 'F': |
2282 | 2391 |
case 'M': |
2283 | 2392 |
case 'm': |
2284 | 2393 |
case 'n': |
2285 | 2394 |
$order[] = 'month'; |
2286 | 2395 |
break; |
2396 |
|
|
2287 | 2397 |
case 'Y': |
2288 | 2398 |
case 'y': |
2289 | 2399 |
$order[] = 'year'; |
2290 | 2400 |
break; |
2401 |
|
|
2291 | 2402 |
case 'g': |
2292 | 2403 |
case 'G': |
2293 | 2404 |
case 'h': |
2294 | 2405 |
case 'H': |
2295 | 2406 |
$order[] = 'hour'; |
2296 | 2407 |
break; |
2408 |
|
|
2297 | 2409 |
case 'i': |
2298 | 2410 |
$order[] = 'minute'; |
2299 | 2411 |
break; |
2412 |
|
|
2300 | 2413 |
case 's': |
2301 | 2414 |
$order[] = 'second'; |
2302 | 2415 |
break; |
... | ... | |
2315 | 2428 |
* A reduced set of granularitiy elements. |
2316 | 2429 |
*/ |
2317 | 2430 |
function date_nongranularity($granularity) { |
2318 |
return array_diff(array('year', 'month', 'day', 'hour', 'minute', 'second', 'timezone'), (array) $granularity); |
|
2431 |
$options = array( |
|
2432 |
'year', |
|
2433 |
'month', |
|
2434 |
'day', |
|
2435 |
'hour', |
|
2436 |
'minute', |
|
2437 |
'second', |
|
2438 |
'timezone', |
|
2439 |
); |
|
2440 |
return array_diff($options, (array) $granularity); |
|
2319 | 2441 |
} |
2320 | 2442 |
|
2321 | 2443 |
/** |
... | ... | |
2335 | 2457 |
'path' => "$path/theme", |
2336 | 2458 |
); |
2337 | 2459 |
return array( |
2338 |
'date_nav_title' => $base + array('variables' => array('granularity' => NULL, 'view' => NULL, 'link' => NULL, 'format' => NULL)), |
|
2460 |
'date_nav_title' => $base + array( |
|
2461 |
'variables' => array( |
|
2462 |
'granularity' => NULL, 'view' => NULL, 'link' => NULL, 'format' => NULL |
|
2463 |
), |
|
2464 |
), |
|
2339 | 2465 |
'date_timezone' => $base + array('render element' => 'element'), |
2340 | 2466 |
'date_select' => $base + array('render element' => 'element'), |
2341 | 2467 |
'date_text' => $base + array('render element' => 'element'), |
... | ... | |
2355 | 2481 |
'date_part_label_time' => $base + array('variables' => array('date_part' => NULL, 'element' => NULL)), |
2356 | 2482 |
'date_views_filter_form' => $base + array('template' => 'date-views-filter-form', 'render element' => 'form'), |
2357 | 2483 |
'date_calendar_day' => $base + array('variables' => array('date' => NULL)), |
2358 |
'date_time_ago' => $base + array('variables' => array('start_date' => NULL, 'end_date' => NULL, 'interval' => NULL)), |
|
2484 |
'date_time_ago' => $base + array( |
|
2485 |
'variables' => array( |
|
2486 |
'start_date' => NULL, 'end_date' => NULL, 'interval' => NULL |
|
2487 |
), |
|
2488 |
), |
|
2359 | 2489 |
); |
2360 | 2490 |
} |
2361 | 2491 |
|
... | ... | |
2375 | 2505 |
case 'date': |
2376 | 2506 |
$timezone = !empty($timezone) ? $timezone : date_default_timezone(); |
2377 | 2507 |
break; |
2508 |
|
|
2378 | 2509 |
case 'utc': |
2379 | 2510 |
$timezone = 'UTC'; |
2380 | 2511 |
break; |
2512 |
|
|
2381 | 2513 |
default: |
2382 | 2514 |
$timezone = date_default_timezone(); |
2383 | 2515 |
} |
... | ... | |
2404 | 2536 |
// These handling modes all convert to UTC before storing in the DB. |
2405 | 2537 |
$timezone = 'UTC'; |
2406 | 2538 |
break; |
2539 |
|
|
2407 | 2540 |
case ('date'): |
2408 | 2541 |
if ($timezone == NULL) { |
2409 | 2542 |
// This shouldn't happen, since it's meaning is undefined. But we need |
... | ... | |
2411 | 2544 |
$timezone = date_default_timezone(); |
2412 | 2545 |
} |
2413 | 2546 |
break; |
2547 |
|
|
2414 | 2548 |
case ('none'): |
2415 | 2549 |
default: |
2416 | 2550 |
$timezone = date_default_timezone(); |
... | ... | |
2465 | 2599 |
* TRUE if the date range is valid, FALSE otherwise. |
2466 | 2600 |
*/ |
2467 | 2601 |
function date_range_valid($string) { |
2468 |
$matches = preg_match('@^(\-[0-9]+|[0-9]{4}):([\+|\-][0-9]+|[0-9]{4})$@', $string);
|
|
2602 |
$matches = preg_match('@^([\+\-][0-9]+|[0-9]{4}):([\+\-][0-9]+|[0-9]{4})$@', $string);
|
|
2469 | 2603 |
return $matches < 1 ? FALSE : TRUE; |
2470 | 2604 |
} |
2471 | 2605 |
|
2472 | 2606 |
/** |
2473 |
* Splits a string like -3:+3 or 2001:2010 into an array of min and max years.
|
|
2607 |
* Splits a string like -3:+3 or 2001:2010 into an array of start and end years.
|
|
2474 | 2608 |
* |
2475 | 2609 |
* Center the range around the current year, if any, but expand it far |
2476 | 2610 |
* enough so it will pick up the year value in the field in case |
... | ... | |
2482 | 2616 |
* (optional) A date object. Defaults to NULL. |
2483 | 2617 |
* |
2484 | 2618 |
* @return array |
2485 |
* A numerically indexed array, containing a minimum and maximum year.
|
|
2619 |
* A numerically indexed array, containing a start and end year.
|
|
2486 | 2620 |
*/ |
2487 | 2621 |
function date_range_years($string, $date = NULL) { |
2488 | 2622 |
$this_year = date_format(date_now(), 'Y'); |
2489 |
list($min_year, $max_year) = explode(':', $string);
|
|
2623 |
list($start_year, $end_year) = explode(':', $string);
|
|
2490 | 2624 |
|
2491 | 2625 |
// Valid patterns would be -5:+5, 0:+1, 2008:2010. |
2492 |
$plus_pattern = '@[\+|\-][0-9]{1,4}@';
|
|
2626 |
$plus_pattern = '@[\+\-][0-9]{1,4}@'; |
|
2493 | 2627 |
$year_pattern = '@^[0-9]{4}@'; |
2494 |
if (!preg_match($year_pattern, $min_year, $matches)) {
|
|
2495 |
if (preg_match($plus_pattern, $min_year, $matches)) {
|
|
2496 |
$min_year = $this_year + $matches[0];
|
|
2628 |
if (!preg_match($year_pattern, $start_year, $matches)) {
|
|
2629 |
if (preg_match($plus_pattern, $start_year, $matches)) {
|
|
2630 |
$start_year = $this_year + $matches[0];
|
|
2497 | 2631 |
} |
2498 | 2632 |
else { |
2499 |
$min_year = $this_year;
|
|
2633 |
$start_year = $this_year;
|
|
2500 | 2634 |
} |
2501 | 2635 |
} |
2502 |
if (!preg_match($year_pattern, $max_year, $matches)) {
|
|
2503 |
if (preg_match($plus_pattern, $max_year, $matches)) {
|
|
2504 |
$max_year = $this_year + $matches[0];
|
|
2636 |
if (!preg_match($year_pattern, $end_year, $matches)) {
|
|
2637 |
if (preg_match($plus_pattern, $end_year, $matches)) {
|
|
2638 |
$end_year = $this_year + $matches[0];
|
|
2505 | 2639 |
} |
2506 | 2640 |
else { |
2507 |
$max_year = $this_year;
|
|
2641 |
$end_year = $this_year;
|
|
2508 | 2642 |
} |
2509 | 2643 |
} |
2510 |
// We expect the $min year to be less than the $max year. |
|
2511 |
// Some custom values for -99:+99 might not obey that. |
|
2512 |
if ($min_year > $max_year) { |
|
2513 |
$temp = $max_year; |
|
2514 |
$max_year = $min_year; |
|
2515 |
$min_year = $temp; |
|
2516 |
} |
|
2517 | 2644 |
// If there is a current value, stretch the range to include it. |
2518 | 2645 |
$value_year = is_object($date) ? $date->format('Y') : ''; |
2519 | 2646 |
if (!empty($value_year)) { |
2520 |
$min_year = min($value_year, $min_year); |
|
2521 |
$max_year = max($value_year, $max_year); |
|
2647 |
if ($start_year <= $end_year) { |
|
2648 |
$start_year = min($value_year, $start_year); |
|
2649 |
$end_year = max($value_year, $end_year); |
|
2650 |
} |
|
2651 |
else { |
|
2652 |
$start_year = max($value_year, $start_year); |
|
2653 |
$end_year = min($value_year, $end_year); |
|
2654 |
} |
|
2522 | 2655 |
} |
2523 |
return array($min_year, $max_year);
|
|
2656 |
return array($start_year, $end_year);
|
|
2524 | 2657 |
} |
2525 | 2658 |
|
2526 | 2659 |
/** |
... | ... | |
2680 | 2813 |
|| ($hour2 == 23 && in_array($min2, array($max_minutes, 59)) && in_array($sec2, array($max_seconds, 59))) |
2681 | 2814 |
|| ($hour1 == 0 && $hour2 == 0 && $min1 == 0 && $min2 == 0 && $sec1 == 0 && $sec2 == 0); |
2682 | 2815 |
break; |
2816 |
|
|
2683 | 2817 |
case 'minute': |
2684 | 2818 |
$min_match = $time1 == '00:00:00' |
2685 | 2819 |
|| ($hour1 == 0 && $min1 == 0); |
... | ... | |
2687 | 2821 |
|| ($hour2 == 23 && in_array($min2, array($max_minutes, 59))) |
2688 | 2822 |
|| ($hour1 == 0 && $hour2 == 0 && $min1 == 0 && $min2 == 0); |
2689 | 2823 |
break; |
2824 |
|
|
2690 | 2825 |
case 'hour': |
2691 | 2826 |
$min_match = $time1 == '00:00:00' |
2692 | 2827 |
|| ($hour1 == 0); |
... | ... | |
2694 | 2829 |
|| ($hour2 == 23) |
2695 | 2830 |
|| ($hour1 == 0 && $hour2 == 0); |
2696 | 2831 |
break; |
2832 |
|
|
2697 | 2833 |
default: |
2698 | 2834 |
$min_match = TRUE; |
2699 | 2835 |
$max_match = FALSE; |
... | ... | |
2754 | 2890 |
} |
2755 | 2891 |
|
2756 | 2892 |
/** |
2757 |
* This function will replace ISO values that have the pattern 9999-00-00T00:00:00 |
|
2758 |
* with a pattern like 9999-01-01T00:00:00, to match the behavior of non-ISO |
|
2759 |
* dates and ensure that date objects created from this value contain a valid month |
|
2760 |
* and day. Without this fix, the ISO date '2020-00-00T00:00:00' would be created as |
|
2893 |
* Replace specific ISO values using patterns. |
|
2894 |
* |
|
2895 |
* Function will replace ISO values that have the pattern 9999-00-00T00:00:00 |
|
2896 |
* with a pattern like 9999-01-01T00:00:00, to match the behavior of non-ISO dates |
|
2897 |
* and ensure that date objects created from this value contain a valid month |
|
2898 |
* and day. |
|
2899 |
* Without this fix, the ISO date '2020-00-00T00:00:00' would be created as |
|
2761 | 2900 |
* November 30, 2019 (the previous day in the previous month). |
2762 | 2901 |
* |
2763 | 2902 |
* @param string $iso_string |
2764 | 2903 |
* An ISO string that needs to be made into a complete, valid date. |
2765 | 2904 |
* |
2905 |
* @return mixed|string |
|
2906 |
* replaced value, or incoming value. |
|
2907 |
* |
|
2766 | 2908 |
* @TODO Expand on this to work with all sorts of partial ISO dates. |
2767 | 2909 |
*/ |
2768 | 2910 |
function date_make_iso_valid($iso_string) { |
Formats disponibles : Unified diff
Weekly update of contrib modules