3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
37 class CRM_Utils_Date
{
40 * Format a date by padding it with leading '0'.
44 * @param string $separator
45 * The seperator to use when formatting the date.
46 * @param int|string $invalidDate what to return if the date is invalid
49 * formatted string for date
51 public static function format($date, $separator = '', $invalidDate = 0) {
52 if (is_numeric($date) &&
53 ((strlen($date) == 8) ||
(strlen($date) == 14))
58 if (!is_array($date) ||
59 CRM_Utils_System
::isNull($date) ||
65 $date['Y'] = (int ) $date['Y'];
66 if ($date['Y'] < 1000 ||
$date['Y'] > 2999) {
70 if (array_key_exists('m', $date)) {
71 $date['M'] = $date['m'];
73 elseif (array_key_exists('F', $date)) {
74 $date['M'] = $date['F'];
77 if (!empty($date['M'])) {
78 $date['M'] = (int ) $date['M'];
79 if ($date['M'] < 1 ||
$date['M'] > 12) {
87 if (!empty($date['d'])) {
88 $date['d'] = (int ) $date['d'];
94 if (!checkdate($date['M'], $date['d'], $date['Y'])) {
98 $date['M'] = sprintf('%02d', $date['M']);
99 $date['d'] = sprintf('%02d', $date['d']);
102 if (CRM_Utils_Array
::value('H', $date) != NULL ||
103 CRM_Utils_Array
::value('h', $date) != NULL ||
104 CRM_Utils_Array
::value('i', $date) != NULL ||
105 CRM_Utils_Array
::value('s', $date) != NULL
107 // we have time too..
108 if (!empty($date['h'])) {
109 if (CRM_Utils_Array
::value('A', $date) == 'PM' or CRM_Utils_Array
::value('a', $date) == 'pm') {
110 if ($date['h'] != 12) {
111 $date['h'] = $date['h'] +
12;
114 if ((CRM_Utils_Array
::value('A', $date) == 'AM' or CRM_Utils_Array
::value('a', $date) == 'am') &&
115 CRM_Utils_Array
::value('h', $date) == 12
120 $date['h'] = (int ) $date['h'];
126 // in 24-hour format the hour is under the 'H' key
127 if (!empty($date['H'])) {
128 $date['H'] = (int) $date['H'];
134 if (!empty($date['i'])) {
135 $date['i'] = (int ) $date['i'];
141 if ($date['h'] == 0 && $date['H'] != 0) {
142 $date['h'] = $date['H'];
145 if (!empty($date['s'])) {
146 $date['s'] = (int ) $date['s'];
152 $date['h'] = sprintf('%02d', $date['h']);
153 $date['i'] = sprintf('%02d', $date['i']);
154 $date['s'] = sprintf('%02d', $date['s']);
159 $time .= $date['h'] . $separator . $date['i'] . $separator . $date['s'];
162 return $date['Y'] . $separator . $date['M'] . $separator . $date['d'] . $time;
166 * Return abbreviated weekday names according to the locale.
168 * Array will be in localized order according to 'weekBegins' setting,
169 * but array keys will always match to:
175 * 0-based array with abbreviated weekday names
178 public static function getAbbrWeekdayNames() {
179 static $days = array();
181 // First day of the week
182 $firstDay = Civi
::settings()->get('weekBegins');
184 // set LC_TIME and build the arrays from locale-provided names
185 // June 1st, 1970 was a Monday
186 CRM_Core_I18n
::setLcTime();
187 for ($i = $firstDay; count($days) < 7; $i = $i > 5 ?
0 : $i +
1) {
188 $days[$i] = strftime('%a', mktime(0, 0, 0, 6, $i, 1970));
195 * Return full weekday names according to the locale.
197 * Array will be in localized order according to 'weekBegins' setting,
198 * but array keys will always match to:
204 * 0-based array with full weekday names
207 public static function getFullWeekdayNames() {
208 static $days = array();
210 // First day of the week
211 $firstDay = Civi
::settings()->get('weekBegins');
213 // set LC_TIME and build the arrays from locale-provided names
214 // June 1st, 1970 was a Monday
215 CRM_Core_I18n
::setLcTime();
216 for ($i = $firstDay; count($days) < 7; $i = $i > 5 ?
0 : $i +
1) {
217 $days[$i] = strftime('%A', mktime(0, 0, 0, 6, $i, 1970));
224 * Return abbreviated month names according to the locale.
229 * 1-based array with abbreviated month names
232 public static function &getAbbrMonthNames($month = FALSE) {
233 static $abbrMonthNames;
234 if (!isset($abbrMonthNames)) {
236 // set LC_TIME and build the arrays from locale-provided names
237 CRM_Core_I18n
::setLcTime();
238 for ($i = 1; $i <= 12; $i++
) {
239 $abbrMonthNames[$i] = strftime('%b', mktime(0, 0, 0, $i, 10, 1970));
243 return $abbrMonthNames[$month];
245 return $abbrMonthNames;
249 * Return full month names according to the locale.
252 * 1-based array with full month names
255 public static function &getFullMonthNames() {
256 static $fullMonthNames;
257 if (!isset($fullMonthNames)) {
259 // set LC_TIME and build the arrays from locale-provided names
260 CRM_Core_I18n
::setLcTime();
261 for ($i = 1; $i <= 12; $i++
) {
262 $fullMonthNames[$i] = strftime('%B', mktime(0, 0, 0, $i, 10, 1970));
265 return $fullMonthNames;
273 public static function unixTime($string) {
274 if (empty($string)) {
277 $parsedDate = date_parse($string);
278 return mktime(CRM_Utils_Array
::value('hour', $parsedDate),
279 CRM_Utils_Array
::value('minute', $parsedDate),
281 CRM_Utils_Array
::value('month', $parsedDate),
282 CRM_Utils_Array
::value('day', $parsedDate),
283 CRM_Utils_Array
::value('year', $parsedDate)
288 * Create a date and time string in a provided format.
290 * %b - abbreviated month name ('Jan'..'Dec')
291 * %B - full month name ('January'..'December')
292 * %d - day of the month as a decimal number, 0-padded ('01'..'31')
293 * %e - day of the month as a decimal number, blank-padded (' 1'..'31')
294 * %E - day of the month as a decimal number ('1'..'31')
295 * %f - English ordinal suffix for the day of the month ('st', 'nd', 'rd', 'th')
296 * %H - hour in 24-hour format, 0-padded ('00'..'23')
297 * %I - hour in 12-hour format, 0-padded ('01'..'12')
298 * %k - hour in 24-hour format, blank-padded (' 0'..'23')
299 * %l - hour in 12-hour format, blank-padded (' 1'..'12')
300 * %m - month as a decimal number, 0-padded ('01'..'12')
301 * %M - minute, 0-padded ('00'..'60')
302 * %p - lowercase ante/post meridiem ('am', 'pm')
303 * %P - uppercase ante/post meridiem ('AM', 'PM')
304 * %Y - year as a decimal number including the century ('2005')
306 * @param string $dateString
307 * Date and time in 'YYYY-MM-DD hh:mm:ss' format.
308 * @param string $format
310 * @param array $dateParts
311 * An array with the desired date parts.
314 * the $format-formatted $date
316 public static function customFormat($dateString, $format = NULL, $dateParts = NULL) {
317 // 1-based (January) month names arrays
318 $abbrMonths = self
::getAbbrMonthNames();
319 $fullMonths = self
::getFullMonthNames();
322 $config = CRM_Core_Config
::singleton();
325 if (array_intersect(array('h', 'H'), $dateParts)) {
326 $format = $config->dateformatDatetime
;
328 elseif (array_intersect(array('d', 'j'), $dateParts)) {
329 $format = $config->dateformatFull
;
331 elseif (array_intersect(array('m', 'M'), $dateParts)) {
332 $format = $config->dateformatPartial
;
335 $format = $config->dateformatYear
;
339 if (strpos($dateString, '-')) {
340 $month = (int) substr($dateString, 5, 2);
341 $day = (int) substr($dateString, 8, 2);
344 $month = (int) substr($dateString, 4, 2);
345 $day = (int) substr($dateString, 6, 2);
348 if (strlen($dateString) > 10) {
349 $format = $config->dateformatDatetime
;
352 $format = $config->dateformatFull
;
354 elseif ($month > 0) {
355 $format = $config->dateformatPartial
;
358 $format = $config->dateformatYear
;
363 if (!CRM_Utils_System
::isNull($dateString)) {
364 if (strpos($dateString, '-')) {
365 $year = (int) substr($dateString, 0, 4);
366 $month = (int) substr($dateString, 5, 2);
367 $day = (int) substr($dateString, 8, 2);
369 $hour24 = (int) substr($dateString, 11, 2);
370 $minute = (int) substr($dateString, 14, 2);
373 $year = (int) substr($dateString, 0, 4);
374 $month = (int) substr($dateString, 4, 2);
375 $day = (int) substr($dateString, 6, 2);
377 $hour24 = (int) substr($dateString, 8, 2);
378 $minute = (int) substr($dateString, 10, 2);
381 if ($day %
10 == 1 and $day != 11) {
384 elseif ($day %
10 == 2 and $day != 12) {
387 elseif ($day %
10 == 3 and $day != 13) {
408 $hour12 = $hour24 - 12;
414 '%b' => CRM_Utils_Array
::value($month, $abbrMonths),
415 '%B' => CRM_Utils_Array
::value($month, $fullMonths),
416 '%d' => $day > 9 ?
$day : '0' . $day,
417 '%e' => $day > 9 ?
$day : ' ' . $day,
420 '%H' => $hour24 > 9 ?
$hour24 : '0' . $hour24,
421 '%h' => $hour12 > 9 ?
$hour12 : '0' . $hour12,
422 '%I' => $hour12 > 9 ?
$hour12 : '0' . $hour12,
423 '%k' => $hour24 > 9 ?
$hour24 : ' ' . $hour24,
424 '%l' => $hour12 > 9 ?
$hour12 : ' ' . $hour12,
425 '%m' => $month > 9 ?
$month : '0' . $month,
426 '%M' => $minute > 9 ?
$minute : '0' . $minute,
427 '%i' => $minute > 9 ?
$minute : '0' . $minute,
428 '%p' => strtolower($type),
434 return strtr($format, $date);
442 * Converts the date/datetime from MySQL format to ISO format
444 * @param string $mysql
445 * Date/datetime in MySQL format.
448 * date/datetime in ISO format
450 public static function mysqlToIso($mysql) {
451 $year = substr($mysql, 0, 4);
452 $month = substr($mysql, 4, 2);
453 $day = substr($mysql, 6, 2);
454 $hour = substr($mysql, 8, 2);
455 $minute = substr($mysql, 10, 2);
456 $second = substr($mysql, 12, 2);
482 * Converts the date/datetime from ISO format to MySQL format
483 * Note that until CRM-14986/ 4.4.7 this was required whenever the pattern $dao->find(TRUE): $dao->save(); was
484 * used to update an object with a date field was used. The DAO now checks for a '-' in date field strings
485 * & runs this function if the - appears - meaning it is likely redundant in the form & BAO layers
488 * Date/datetime in ISO format.
491 * date/datetime in MySQL format
493 public static function isoToMysql($iso) {
494 $dropArray = array('-' => '', ':' => '', ' ' => '');
495 return strtr($iso, $dropArray);
499 * Converts the any given date to default date format.
501 * @param array $params
502 * Has given date-format.
503 * @param int $dateType
505 * @param string $dateParam
510 public static function convertToDefaultDate(&$params, $dateType, $dateParam) {
512 $cen = substr($now['year'], 0, 2);
516 if (!empty($params[$dateParam])) {
517 // suppress hh:mm or hh:mm:ss if it exists CRM-7957
518 $value = preg_replace("/(\s(([01]\d)|[2][0-3])(:([0-5]\d)){1,2})$/", "", $params[$dateParam]);
523 if (!preg_match('/^\d\d\d\d-?(\d|\d\d)-?(\d|\d\d)$/', $value)) {
529 if (!preg_match('/^(\d|\d\d)[-\/](\d|\d\d)[-\/]\d\d$/', $value)) {
535 if (!preg_match('/^(\d|\d\d)[-\/](\d|\d\d)[-\/]\d\d\d\d$/', $value)) {
541 if (!preg_match('/^[A-Za-z]*.[ \t]?\d\d\,[ \t]?\d\d\d\d$/', $value)) {
547 if (!preg_match('/^\d\d-[A-Za-z]{3}.*-\d\d$/', $value) && !preg_match('/^\d\d[-\/]\d\d[-\/]\d\d$/', $value)) {
553 if (!preg_match('/^(\d|\d\d)[-\/](\d|\d\d)[-\/]\d\d\d\d/', $value)) {
559 if ($dateType == 1) {
560 $formattedDate = explode("-", $value);
561 if (count($formattedDate) == 3) {
562 $year = (int) $formattedDate[0];
563 $month = (int) $formattedDate[1];
564 $day = (int) $formattedDate[2];
566 elseif (count($formattedDate) == 1 && (strlen($value) == 8)) {
574 if ($dateType == 2 ||
$dateType == 4) {
575 $formattedDate = explode("/", $value);
576 if (count($formattedDate) != 3) {
577 $formattedDate = explode("-", $value);
579 if (count($formattedDate) == 3) {
580 $year = (int) $formattedDate[2];
581 $month = (int) $formattedDate[0];
582 $day = (int) $formattedDate[1];
588 if ($dateType == 8) {
589 $dateArray = explode(' ', $value);
591 $dateArray[1] = (int) substr($dateArray[1], 0, 2);
594 $fullMonths = self
::getFullMonthNames();
595 foreach ($fullMonths as $key => $val) {
596 if (strtolower($dateArray[0]) == strtolower($val)) {
602 $abbrMonths = self
::getAbbrMonthNames();
603 foreach ($abbrMonths as $key => $val) {
604 if (strtolower(trim($dateArray[0], ".")) == strtolower($val)) {
610 $year = (int) $dateArray[2];
611 $day = (int) $dateArray[1];
612 $month = (int) $monthInt;
614 if ($dateType == 16) {
615 $dateArray = explode('-', $value);
616 if (count($dateArray) != 3) {
617 $dateArray = explode('/', $value);
620 if (count($dateArray) == 3) {
622 $fullMonths = self
::getFullMonthNames();
623 foreach ($fullMonths as $key => $val) {
624 if (strtolower($dateArray[1]) == strtolower($val)) {
630 $abbrMonths = self
::getAbbrMonthNames();
631 foreach ($abbrMonths as $key => $val) {
632 if (strtolower(trim($dateArray[1], ".")) == strtolower($val)) {
639 $monthInt = $dateArray[1];
642 $year = (int) $dateArray[2];
643 $day = (int) $dateArray[0];
644 $month = (int) $monthInt;
650 if ($dateType == 32) {
651 $formattedDate = explode("/", $value);
652 if (count($formattedDate) == 3) {
653 $year = (int) $formattedDate[2];
654 $month = (int) $formattedDate[1];
655 $day = (int) $formattedDate[0];
662 $month = ($month < 10) ?
"0" . "$month" : $month;
663 $day = ($day < 10) ?
"0" . "$day" : $day;
665 $year = (int ) $year;
666 // simple heuristic to determine what century to use
667 // 00 - 20 is always 2000 - 2020
668 // 21 - 99 is always 1921 - 1999
670 $year = (strlen($year) == 1) ?
$cen . '0' . $year : $cen . $year;
672 elseif ($year < 100) {
673 $year = $prevCen . $year;
676 if ($params[$dateParam]) {
677 $params[$dateParam] = "$year$month$day";
679 // if month is invalid return as error
680 if ($month !== '00' && $month <= 12) {
691 public static function isDate(&$date) {
692 if (CRM_Utils_System
::isNull($date)) {
699 * @param null $timeStamp
701 * @return bool|string
703 public static function currentDBDate($timeStamp = NULL) {
704 return $timeStamp ?
date('YmdHis', $timeStamp) : date('YmdHis');
713 public static function overdue($date, $now = NULL) {
714 $mysqlDate = self
::isoToMysql($date);
716 $now = self
::currentDBDate();
719 $now = self
::isoToMysql($now);
722 return ($mysqlDate >= $now) ?
FALSE : TRUE;
726 * Get customized today.
728 * This function is used for getting customized today. To get
729 * actuall today pass 'dayParams' as null. or else pass the day,
730 * month, year values as array values
731 * Example: $dayParams = array(
732 * 'day' => '25', 'month' => '10',
733 * 'year' => '2007' );
735 * @param array $dayParams of the day, month, year.
736 * Array of the day, month, year.
738 * @param string $format
739 * Expected date format( default.
740 * format is 2007-12-21 )
743 * Return the customized today's date (Y-m-d)
745 public static function getToday($dayParams = NULL, $format = "Y-m-d") {
746 if (is_null($dayParams) ||
empty($dayParams)) {
747 $today = date($format);
750 $today = date($format, mktime(0, 0, 0,
761 * Find whether today's date lies in
764 * @param date $startDate
765 * Start date for the range.
766 * @param date $endDate
767 * End date for the range.
770 * true if today's date is in the given date range
772 public static function getRange($startDate, $endDate) {
773 $today = date("Y-m-d");
774 $mysqlStartDate = self
::isoToMysql($startDate);
775 $mysqlEndDate = self
::isoToMysql($endDate);
776 $mysqlToday = self
::isoToMysql($today);
778 if ((isset($mysqlStartDate) && isset($mysqlEndDate)) && (($mysqlToday >= $mysqlStartDate) && ($mysqlToday <= $mysqlEndDate))) {
781 elseif ((isset($mysqlStartDate) && !isset($mysqlEndDate)) && (($mysqlToday >= $mysqlStartDate))) {
784 elseif ((!isset($mysqlStartDate) && isset($mysqlEndDate)) && (($mysqlToday <= $mysqlEndDate))) {
791 * Get start date and end from
792 * the given relative term and unit
794 * @param date $relative
801 * start date, end date
803 public static function getFromTo($relative, $from, $to) {
805 list($term, $unit) = explode('.', $relative);
806 $dateRange = self
::relativeToAbsolute($term, $unit);
807 $from = $dateRange['from'];
808 //Take only Date Part, Sometime Time part is also present in 'to'
809 $to = substr($dateRange['to'], 0, 8);
812 $from = self
::processDate($from);
813 $to = self
::processDate($to, '235959');
815 return array($from, $to);
819 * Calculate Age in Years if greater than one year else in months.
821 * @param date $birthDate
825 * array $results contains years or months
827 static public function calculateAge($birthDate) {
829 $formatedBirthDate = CRM_Utils_Date
::customFormat($birthDate, '%Y-%m-%d');
831 $bDate = explode('-', $formatedBirthDate);
832 $birthYear = $bDate[0];
833 $birthMonth = $bDate[1];
834 $birthDay = $bDate[2];
835 $year_diff = date("Y") - $birthYear;
837 // don't calculate age CRM-3143
838 if ($birthYear == '1902') {
842 switch ($year_diff) {
844 $month = (12 - $birthMonth) +
date("m");
846 if (date("d") < $birthDay) {
849 $results['months'] = $month;
851 elseif ($month == 12 && (date("d") < $birthDay)) {
852 $results['months'] = $month - 1;
855 $results['years'] = $year_diff;
860 $month = date("m") - $birthMonth;
861 $results['months'] = $month;
865 $results['years'] = $year_diff;
866 if ((date("m") < $birthMonth) ||
(date("m") == $birthMonth) && (date("d") < $birthDay)) {
875 * Calculate next payment date according to provided unit & interval
877 * @param string $unit
878 * Frequency unit like year,month, week etc.
880 * @param int $interval
881 * Frequency interval.
884 * Start date of pledge.
886 * @param bool $dontCareTime
889 * contains new date with added interval
891 public static function intervalAdd($unit, $interval, $date, $dontCareTime = FALSE) {
892 if (is_array($date)) {
893 $hour = CRM_Utils_Array
::value('H', $date);
894 $minute = CRM_Utils_Array
::value('i', $date);
895 $second = CRM_Utils_Array
::value('s', $date);
896 $month = CRM_Utils_Array
::value('M', $date);
897 $day = CRM_Utils_Array
::value('d', $date);
898 $year = CRM_Utils_Array
::value('Y', $date);
901 extract(date_parse($date));
903 $date = mktime($hour, $minute, $second, $month, $day, $year);
906 $date = mktime($hour, $minute, $second, $month, $day, $year +
$interval);
910 $date = mktime($hour, $minute, $second, $month +
$interval, $day, $year);
914 $interval = $interval * 7;
915 $date = mktime($hour, $minute, $second, $month, $day +
$interval, $year);
919 $date = mktime($hour, $minute, $second, $month, $day +
$interval, $year);
923 $date = mktime($hour, $minute, $second +
$interval, $month, $day, $year);
927 $scheduleDate = explode("-", date("n-j-Y-H-i-s", $date));
930 $date['M'] = $scheduleDate[0];
931 $date['d'] = $scheduleDate[1];
932 $date['Y'] = $scheduleDate[2];
933 if ($dontCareTime == FALSE) {
934 $date['H'] = $scheduleDate[3];
935 $date['i'] = $scheduleDate[4];
936 $date['s'] = $scheduleDate[5];
942 * Check given format is valid for bith date.
943 * and retrun supportable birth date format w/ qf mapping.
946 * Given format ( eg 'M Y', 'Y M' ).
947 * return array of qfMapping and date parts for date format.
949 * @return array|null|string
951 public static function &checkBirthDateFormat($format = NULL) {
952 $birthDateFormat = NULL;
954 $birthDateFormat = self
::getDateFormat('birth');
957 $supportableFormats = array(
958 'mm/dd' => '%B %E%f',
959 'dd-mm' => '%E%f %B',
963 'dd/mm/yy' => '%E%f %B %Y',
966 if (array_key_exists($birthDateFormat, $supportableFormats)) {
967 $birthDateFormat = array('qfMapping' => $supportableFormats[$birthDateFormat]);
970 return $birthDateFormat;
974 * Resolves the given relative time interval into finite time limits.
976 * @param array $relativeTerm
977 * Relative time frame like this, previous, etc.
979 * Frequency unit like year, month, week etc.
982 * start date and end date for the relative time frame
984 public static function relativeToAbsolute($relativeTerm, $unit) {
986 $from = $to = $dateRange = array();
987 $from['H'] = $from['i'] = $from['s'] = 0;
991 switch ($relativeTerm) {
993 $from['d'] = $from['M'] = 1;
996 $to['Y'] = $from['Y'] = $now['year'];
1000 $from['M'] = $from['d'] = 1;
1003 $to['Y'] = $from['Y'] = $now['year'] - 1;
1006 case 'previous_before':
1007 $from['M'] = $from['d'] = 1;
1010 $to['Y'] = $from['Y'] = $now['year'] - 2;
1014 $from['M'] = $from['d'] = 1;
1017 $from['Y'] = $now['year'] - 2;
1018 $to['Y'] = $now['year'] - 1;
1024 $to['Y'] = $now['year'] - 1;
1029 $from['M'] = $from['d'] = 1;
1030 $from['Y'] = $now['year'];
1034 case 'greater_previous':
1037 $from['Y'] = $now['year'] - 1;
1042 $to['d'] = $now['mday'];
1043 $to['M'] = $now['mon'];
1044 $to['Y'] = $now['year'];
1046 $to['i'] = $to['s'] = 59;
1047 $from = self
::intervalAdd('year', -1, $to);
1048 $from = self
::intervalAdd('second', 1, $from);
1052 $from['M'] = $from['d'] = 1;
1053 $from['Y'] = $now['year'];
1055 $to['i'] = $to['s'] = 59;
1056 $to['d'] = $now['mday'];
1057 $to['M'] = $now['mon'];
1058 $to['Y'] = $now['year'];
1062 $to['d'] = $now['mday'];
1063 $to['M'] = $now['mon'];
1064 $to['Y'] = $now['year'];
1066 $to['i'] = $to['s'] = 59;
1067 $from = self
::intervalAdd('year', -2, $to);
1068 $from = self
::intervalAdd('second', 1, $from);
1072 $to['d'] = $now['mday'];
1073 $to['M'] = $now['mon'];
1074 $to['Y'] = $now['year'];
1076 $to['i'] = $to['s'] = 59;
1077 $from = self
::intervalAdd('year', -3, $to);
1078 $from = self
::intervalAdd('second', 1, $from);
1084 $to['Y'] = $now['year'];
1089 $from['M'] = $from['d'] = 1;
1092 $to['Y'] = $from['Y'] = $now['year'] +
1;
1096 $from['d'] = $now['mday'];
1097 $from['M'] = $now['mon'];
1098 $from['Y'] = $now['year'];
1099 $to['d'] = $now['mday'] - 1;
1100 $to['M'] = $now['mon'];
1101 $to['Y'] = $now['year'] +
1;
1107 $config = CRM_Core_Config
::singleton();
1108 $from['d'] = $config->fiscalYearStart
['d'];
1109 $from['M'] = $config->fiscalYearStart
['M'];
1110 $fYear = self
::calculateFiscalYear($from['d'], $from['M']);
1111 switch ($relativeTerm) {
1113 $from['Y'] = $fYear;
1114 $fiscalYear = mktime(0, 0, 0, $from['M'], $from['d'] - 1, $from['Y'] +
1);
1115 $fiscalEnd = explode('-', date("Y-m-d", $fiscalYear));
1117 $to['d'] = $fiscalEnd['2'];
1118 $to['M'] = $fiscalEnd['1'];
1119 $to['Y'] = $fiscalEnd['0'];
1123 $from['Y'] = $fYear - 1;
1124 $fiscalYear = mktime(0, 0, 0, $from['M'], $from['d'] - 1, $from['Y'] +
1);
1125 $fiscalEnd = explode('-', date("Y-m-d", $fiscalYear));
1126 $to['d'] = $fiscalEnd['2'];
1127 $to['M'] = $fiscalEnd['1'];
1128 $to['Y'] = $fiscalEnd['0'];
1132 $from['Y'] = $fYear +
1;
1133 $fiscalYear = mktime(0, 0, 0, $from['M'], $from['d'] - 1, $from['Y'] +
1);
1134 $fiscalEnd = explode('-', date("Y-m-d", $fiscalYear));
1135 $to['d'] = $fiscalEnd['2'];
1136 $to['M'] = $fiscalEnd['1'];
1137 $to['Y'] = $fiscalEnd['0'];
1143 switch ($relativeTerm) {
1146 $quarter = ceil($now['mon'] / 3);
1148 $from['M'] = (3 * $quarter) - 2;
1149 $to['M'] = 3 * $quarter;
1150 $to['Y'] = $from['Y'] = $now['year'];
1151 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $now['year']));
1156 $quarter = ceil($now['mon'] / 3);
1157 $quarter = $quarter - $difference;
1159 if ($quarter <= 0) {
1164 $from['M'] = (3 * $quarter) - 2;
1165 $to['M'] = 3 * $quarter;
1166 $to['Y'] = $from['Y'] = $now['year'] - $subtractYear;
1167 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1170 case 'previous_before':
1172 $quarter = ceil($now['mon'] / 3);
1173 $quarter = $quarter - $difference;
1175 if ($quarter <= 0) {
1180 $from['M'] = (3 * $quarter) - 2;
1181 $to['M'] = 3 * $quarter;
1182 $to['Y'] = $from['Y'] = $now['year'] - $subtractYear;
1183 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1188 $quarter = ceil($now['mon'] / 3);
1189 $current_quarter = $quarter;
1190 $quarter = $quarter - $difference;
1192 if ($quarter <= 0) {
1197 $from['M'] = (3 * $quarter) - 2;
1198 switch ($current_quarter) {
1200 $to['M'] = (4 * $quarter);
1204 $to['M'] = (4 * $quarter) +
3;
1208 $to['M'] = (4 * $quarter) +
2;
1212 $to['M'] = (4 * $quarter) +
1;
1215 $to['Y'] = $from['Y'] = $now['year'] - $subtractYear;
1216 if ($to['M'] > 12) {
1217 $to['M'] = 3 * ($quarter - 3);
1218 $to['Y'] = $now['year'];
1220 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1224 $quarter = ceil($now['mon'] / 3) - 1;
1226 if ($quarter <= 0) {
1230 $to['M'] = 3 * $quarter;
1231 $to['Y'] = $from['Y'] = $now['year'] - $subtractYear;
1232 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1237 $quarter = ceil($now['mon'] / 3);
1239 $from['M'] = (3 * $quarter) - 2;
1240 $from['Y'] = $now['year'];
1244 case 'greater_previous':
1245 $quarter = ceil($now['mon'] / 3) - 1;
1247 if ($quarter <= 0) {
1251 $from['M'] = 3 * $quarter;
1252 $from['Y'] = $from['Y'] = $now['year'] - $subtractYear;
1253 $from['d'] = date('t', mktime(0, 0, 0, $from['M'], 1, $from['Y']));
1258 $to['d'] = $now['mday'];
1259 $to['M'] = $now['mon'];
1260 $to['Y'] = $now['year'];
1262 $to['i'] = $to['s'] = 59;
1263 $from = self
::intervalAdd('day', -90, $to);
1264 $from = self
::intervalAdd('second', 1, $from);
1268 $quarter = ceil($now['mon'] / 3);
1270 $from['M'] = (3 * $quarter) - 2;
1271 $from['Y'] = $now['year'];
1272 $to['d'] = $now['mday'];
1273 $to['M'] = $now['mon'];
1274 $to['Y'] = $now['year'];
1276 $to['i'] = $to['s'] = 59;
1280 $quarter = ceil($now['mon'] / 3);
1281 $to['M'] = 3 * $quarter;
1282 $to['Y'] = $now['year'];
1283 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $now['year']));
1290 $quarter = ceil($now['mon'] / 3);
1291 $quarter = $quarter - $difference;
1294 $now['year'] = $now['year'] +
1;
1297 if ($quarter <= 0) {
1302 $from['M'] = (3 * $quarter) - 2;
1303 $to['M'] = 3 * $quarter;
1304 $to['Y'] = $from['Y'] = $now['year'] - $subtractYear;
1305 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1309 $from['d'] = $now['mday'];
1310 $from['M'] = $now['mon'];
1311 $from['Y'] = $now['year'];
1313 $from['i'] = $to['s'] = 00;
1314 $to = self
::intervalAdd('day', 90, $from);
1315 $to = self
::intervalAdd('second', -1, $to);
1321 switch ($relativeTerm) {
1324 $to['d'] = date('t', mktime(0, 0, 0, $now['mon'], 1, $now['year']));
1325 $from['M'] = $to['M'] = $now['mon'];
1326 $from['Y'] = $to['Y'] = $now['year'];
1331 if ($now['mon'] == 1) {
1332 $from['M'] = $to['M'] = 12;
1333 $from['Y'] = $to['Y'] = $now['year'] - 1;
1336 $from['M'] = $to['M'] = $now['mon'] - 1;
1337 $from['Y'] = $to['Y'] = $now['year'];
1339 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1342 case 'previous_before':
1344 if ($now['mon'] < 3) {
1345 $from['M'] = $to['M'] = 10 +
$now['mon'];
1346 $from['Y'] = $to['Y'] = $now['year'] - 1;
1349 $from['M'] = $to['M'] = $now['mon'] - 2;
1350 $from['Y'] = $to['Y'] = $now['year'];
1352 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1357 if ($now['mon'] < 3) {
1358 $from['M'] = 10 +
$now['mon'];
1359 $from['Y'] = $now['year'] - 1;
1362 $from['M'] = $now['mon'] - 2;
1363 $from['Y'] = $now['year'];
1366 if ($now['mon'] == 1) {
1368 $to['Y'] = $now['year'] - 1;
1371 $to['M'] = $now['mon'] - 1;
1372 $to['Y'] = $now['year'];
1375 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1379 // before end of past month
1380 if ($now['mon'] == 1) {
1382 $to['Y'] = $now['year'] - 1;
1385 $to['M'] = $now['mon'] - 1;
1386 $to['Y'] = $now['year'];
1389 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1395 $from['M'] = $now['mon'];;
1396 $from['Y'] = $now['year'];
1400 case 'greater_previous':
1401 // from end of past month
1402 if ($now['mon'] == 1) {
1404 $from['Y'] = $now['year'] - 1;
1407 $from['M'] = $now['mon'] - 1;
1408 $from['Y'] = $now['year'];
1411 $from['d'] = date('t', mktime(0, 0, 0, $from['M'], 1, $from['Y']));
1416 $to['d'] = $now['mday'];
1417 $to['M'] = $now['mon'];
1418 $to['Y'] = $now['year'];
1420 $to['i'] = $to['s'] = 59;
1421 $from = self
::intervalAdd('day', -60, $to);
1422 $from = self
::intervalAdd('second', 1, $from);
1426 $to['d'] = $now['mday'];
1427 $to['M'] = $now['mon'];
1428 $to['Y'] = $now['year'];
1430 $to['i'] = $to['s'] = 59;
1431 $from = self
::intervalAdd('day', -30, $to);
1432 $from = self
::intervalAdd('second', 1, $from);
1437 $from['M'] = $now['mon'];;
1438 $from['Y'] = $now['year'];
1439 $to['d'] = $now['mday'];
1440 $to['M'] = $now['mon'];
1441 $to['Y'] = $now['year'];
1443 $to['i'] = $to['s'] = 59;
1448 $to['Y'] = $now['year'];
1449 $to['M'] = $now['mon'];
1450 $to['d'] = date('t', mktime(0, 0, 0, $now['mon'], 1, $now['year']));
1456 if ($now['mon'] == 12) {
1457 $from['M'] = $to['M'] = 1;
1458 $from['Y'] = $to['Y'] = $now['year'] +
1;
1461 $from['M'] = $to['M'] = $now['mon'] +
1;
1462 $from['Y'] = $to['Y'] = $now['year'];
1464 $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y']));
1468 $from['d'] = $now['mday'];
1469 $from['M'] = $now['mon'];
1470 $from['Y'] = $now['year'];
1472 $from['i'] = $to['s'] = 00;
1473 $to = self
::intervalAdd('day', 30, $from);
1474 $to = self
::intervalAdd('second', -1, $to);
1478 $from['d'] = $now['mday'];
1479 $from['M'] = $now['mon'];
1480 $from['Y'] = $now['year'];
1482 $from['i'] = $to['s'] = 00;
1483 $to = self
::intervalAdd('day', 60, $from);
1484 $to = self
::intervalAdd('second', -1, $to);
1490 $weekFirst = Civi
::settings()->get('weekBegins');
1491 $thisDay = $now['wday'];
1492 if ($weekFirst > $thisDay) {
1493 $diffDay = $thisDay - $weekFirst +
7;
1496 $diffDay = $thisDay - $weekFirst;
1498 switch ($relativeTerm) {
1500 $from['d'] = $now['mday'];
1501 $from['M'] = $now['mon'];
1502 $from['Y'] = $now['year'];
1503 $from = self
::intervalAdd('day', -1 * ($diffDay), $from);
1504 $to = self
::intervalAdd('day', 6, $from);
1508 $from['d'] = $now['mday'];
1509 $from['M'] = $now['mon'];
1510 $from['Y'] = $now['year'];
1511 $from = self
::intervalAdd('day', -1 * ($diffDay) - 7, $from);
1512 $to = self
::intervalAdd('day', 6, $from);
1515 case 'previous_before':
1516 $from['d'] = $now['mday'];
1517 $from['M'] = $now['mon'];
1518 $from['Y'] = $now['year'];
1519 $from = self
::intervalAdd('day', -1 * ($diffDay) - 14, $from);
1520 $to = self
::intervalAdd('day', 6, $from);
1524 $from['d'] = $now['mday'];
1525 $from['M'] = $now['mon'];
1526 $from['Y'] = $now['year'];
1527 $from = self
::intervalAdd('day', -1 * ($diffDay) - 14, $from);
1528 $to = self
::intervalAdd('day', 13, $from);
1532 $to['d'] = $now['mday'];
1533 $to['M'] = $now['mon'];
1534 $to['Y'] = $now['year'];
1535 $to = self
::intervalAdd('day', -1 * ($diffDay) - 1, $to);
1540 $from['d'] = $now['mday'];
1541 $from['M'] = $now['mon'];
1542 $from['Y'] = $now['year'];
1543 $from = self
::intervalAdd('day', -1 * ($diffDay), $from);
1547 case 'greater_previous':
1548 $from['d'] = $now['mday'];
1549 $from['M'] = $now['mon'];
1550 $from['Y'] = $now['year'];
1551 $from = self
::intervalAdd('day', -1 * ($diffDay) - 1, $from);
1556 $to['d'] = $now['mday'];
1557 $to['M'] = $now['mon'];
1558 $to['Y'] = $now['year'];
1560 $to['i'] = $to['s'] = 59;
1561 $from = self
::intervalAdd('day', -7, $to);
1562 $from = self
::intervalAdd('second', 1, $from);
1566 $from['d'] = $now['mday'];
1567 $from['M'] = $now['mon'];
1568 $from['Y'] = $now['year'];
1569 $from = self
::intervalAdd('day', -1 * ($diffDay), $from);
1570 $to['d'] = $now['mday'];
1571 $to['M'] = $now['mon'];
1572 $to['Y'] = $now['year'];
1574 $to['i'] = $to['s'] = 59;
1578 $to['d'] = $now['mday'];
1579 $to['M'] = $now['mon'];
1580 $to['Y'] = $now['year'];
1582 $to = self
::intervalAdd('day', -1 * ($diffDay) +
6, $to);
1587 $from['d'] = $now['mday'];
1588 $from['M'] = $now['mon'];
1589 $from['Y'] = $now['year'];
1590 $from = self
::intervalAdd('day', -1 * ($diffDay) +
7, $from);
1591 $to = self
::intervalAdd('day', 6, $from);
1595 $from['d'] = $now['mday'];
1596 $from['M'] = $now['mon'];
1597 $from['Y'] = $now['year'];
1599 $from['i'] = $to['s'] = 00;
1600 $to = self
::intervalAdd('day', 7, $from);
1601 $to = self
::intervalAdd('second', -1, $to);
1607 switch ($relativeTerm) {
1609 $from['d'] = $to['d'] = $now['mday'];
1610 $from['M'] = $to['M'] = $now['mon'];
1611 $from['Y'] = $to['Y'] = $now['year'];
1615 $from['d'] = $now['mday'];
1616 $from['M'] = $now['mon'];
1617 $from['Y'] = $now['year'];
1618 $from = self
::intervalAdd('day', -1, $from);
1619 $to['d'] = $from['d'];
1620 $to['M'] = $from['M'];
1621 $to['Y'] = $from['Y'];
1624 case 'previous_before':
1625 $from['d'] = $now['mday'];
1626 $from['M'] = $now['mon'];
1627 $from['Y'] = $now['year'];
1628 $from = self
::intervalAdd('day', -2, $from);
1629 $to['d'] = $from['d'];
1630 $to['M'] = $from['M'];
1631 $to['Y'] = $from['Y'];
1635 $from['d'] = $to['d'] = $now['mday'];
1636 $from['M'] = $to['M'] = $now['mon'];
1637 $from['Y'] = $to['Y'] = $now['year'];
1638 $from = self
::intervalAdd('day', -2, $from);
1639 $to = self
::intervalAdd('day', -1, $to);
1643 $to['d'] = $now['mday'];
1644 $to['M'] = $now['mon'];
1645 $to['Y'] = $now['year'];
1650 $from['d'] = $now['mday'];
1651 $from['M'] = $now['mon'];;
1652 $from['Y'] = $now['year'];
1657 $to['d'] = $now['mday'];
1658 $to['M'] = $now['mon'];
1659 $to['Y'] = $now['year'];
1660 $to = self
::intervalAdd('day', 1, $to);
1661 $from['d'] = $to['d'];
1662 $from['M'] = $to['M'];
1663 $from['Y'] = $to['Y'];
1674 if (!empty($
$item)) {
1675 $dateRange[$item] = self
::format($
$item);
1678 $dateRange[$item] = NULL;
1685 * Calculate current fiscal year based on the fiscal month and day.
1687 * @param int $fyDate
1688 * Fiscal start date.
1690 * @param int $fyMonth
1691 * Fiscal Start Month.
1694 * $fy Current Fiscl Year
1696 public static function calculateFiscalYear($fyDate, $fyMonth) {
1697 $date = date("Y-m-d");
1698 $currentYear = date("Y");
1700 // recalculate the date because month 4::04 make the difference
1701 $fiscalYear = explode('-', date("Y-m-d", mktime(0, 0, 0, $fyMonth, $fyDate, $currentYear)));
1702 $fyDate = $fiscalYear[2];
1703 $fyMonth = $fiscalYear[1];
1704 $fyStartDate = date("Y-m-d", mktime(0, 0, 0, $fyMonth, $fyDate, $currentYear));
1706 if ($fyStartDate > $date) {
1707 $fy = intval(intval($currentYear) - 1);
1710 $fy = intval($currentYear);
1716 * Function to process date, convert to mysql format
1718 * @param string $date
1720 * @param string $time
1722 * @param bool|string $returnNullString 'null' needs to be returned
1723 * so that db oject will set null in db
1724 * @param string $format
1725 * Expected return date format.( default is mysql ).
1728 * date format that is excepted by mysql
1730 public static function processDate($date, $time = NULL, $returnNullString = FALSE, $format = 'YmdHis') {
1733 if ($returnNullString) {
1734 $mysqlDate = 'null';
1738 $mysqlDate = date($format, strtotime($date . ' ' . $time));
1745 * Convert a Civi-special date string to a standard php date string.
1747 * For historical reasons CiviCRM has it's own (possibly Smarty derived)
1748 * format for defined date strings. This renders something php can use.
1750 * @param string $dateFormatString
1752 * These map to the values used in the date_format field in civicrm_custom_field.date_format.
1755 * A proper php strotime formatted equivalent of the string.
1756 * eg m/d/y for the above.
1758 * http://php.net/manual/en/function.strtotime.php
1760 public static function getPhpDateFormatFromInputStyleDateFormat($dateFormatString) {
1761 $formats = CRM_Core_SelectValues
::datePluginToPHPFormats();
1762 return $formats[$dateFormatString];
1766 * Add the metadata about a date field to the field.
1768 * This metadata will work with the call $form->add('datepicker', ...
1770 * @param array $fieldMetaData
1771 * @param array $field
1775 public static function addDateMetadataToField($fieldMetaData, $field) {
1776 if (isset($fieldMetaData['html'])) {
1777 $field['html_type'] = $fieldMetaData['html']['type'];
1778 if ($field['html_type'] === 'Select Date') {
1779 if (!isset($field['date_format'])) {
1780 $dateAttributes = CRM_Core_SelectValues
::date($fieldMetaData['html']['formatType'], NULL, NULL, NULL, 'Input');
1781 $field['start_date_years'] = $dateAttributes['minYear'];
1782 $field['end_date_years'] = $dateAttributes['maxYear'];
1783 $field['date_format'] = $dateAttributes['format'];
1784 $field['is_datetime_field'] = TRUE;
1785 $field['time_format'] = $dateAttributes['time'];
1786 $field['php_datetime_format'] = CRM_Utils_Date
::getPhpDateFormatFromInputStyleDateFormat($field['date_format']);
1787 if ($field['time_format']) {
1788 $field['php_datetime_format'] .= ' H-i-s';
1791 $field['datepicker']['extra'] = self
::getDatePickerExtra($field);
1792 $field['datepicker']['attributes'] = self
::getDatePickerAttributes($field);
1800 * Get the fields required for the 'extra' parameter when adding a datepicker.
1802 * @param array $field
1806 public static function getDatePickerExtra($field) {
1808 if (isset($field['date_format'])) {
1809 $extra['date'] = $field['date_format'];
1810 $extra['time'] = $field['time_format'];
1812 $thisYear = date('Y');
1813 if (isset($field['start_date_years'])) {
1814 $extra['minDate'] = date('Y-m-d', strtotime('-' . ($thisYear - $field['start_date_years']) . ' years'));
1816 if (isset($field['end_date_years'])) {
1817 $extra['maxDate'] = date('Y-m-d', strtotime('-' . ($thisYear - $field['end_date_years']) . ' years'));
1823 * Get the attributes parameters required for datepicker.
1825 * @param array $field
1829 * Array ready to pass to $this->addForm('datepicker' as attributes.
1831 public static function getDatePickerAttributes(&$field) {
1832 $attributes = array();
1833 $dateAttributes = array(
1834 'start_date_years' => 'minYear',
1835 'end_date_years' => 'maxYear',
1836 'date_format' => 'format',
1838 foreach ($dateAttributes as $dateAttribute => $mapTo) {
1839 if (isset($field[$dateAttribute])) {
1840 $attributes[$mapTo] = $field[$dateAttribute];
1847 * Function to convert mysql to date plugin format.
1849 * @param string $mysqlDate
1852 * @param null $formatType
1853 * @param null $format
1854 * @param null $timeFormat
1859 public static function setDateDefaults($mysqlDate = NULL, $formatType = NULL, $format = NULL, $timeFormat = NULL) {
1860 // if date is not passed assume it as today
1862 $mysqlDate = date('Y-m-d G:i:s');
1865 $config = CRM_Core_Config
::singleton();
1867 // get actual format
1868 $params = array('name' => $formatType);
1870 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_PreferencesDate', $params, $values);
1872 if ($values['date_format']) {
1873 $format = $values['date_format'];
1876 if (isset($values['time_format'])) {
1877 $timeFormat = $values['time_format'];
1881 // now we set display date using js, hence we should always setdefault
1882 // 'm/d/Y' format. So that submitted value is alwats mm/dd/YY format
1883 // note that for date display we dynamically create text field
1886 $format = $config->dateInputFormat;
1889 // get actual format
1890 $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats( );
1891 $dateFormat = CRM_Utils_Array::value( $format, $actualPHPFormats );
1894 $dateFormat = 'm/d/Y';
1895 $date = date($dateFormat, strtotime($mysqlDate));
1898 $timeFormat = $config->timeInputFormat
;
1901 $actualTimeFormat = "g:iA";
1902 $appendZeroLength = 7;
1903 if ($timeFormat > 1) {
1904 $actualTimeFormat = "G:i";
1905 $appendZeroLength = 5;
1908 $time = date($actualTimeFormat, strtotime($mysqlDate));
1910 // need to append zero for hours < 10
1911 if (strlen($time) < $appendZeroLength) {
1912 $time = '0' . $time;
1915 return array($date, $time);
1919 * Function get date format.
1921 * @param string $formatType
1922 * Date name e.g. birth.
1926 public static function getDateFormat($formatType = NULL) {
1929 $format = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_PreferencesDate',
1930 $formatType, 'date_format', 'name'
1935 $config = CRM_Core_Config
::singleton();
1936 $format = $config->dateInputFormat
;
1945 * @return null|string
1947 public static function formatDate($date, $dateType) {
1948 $formattedDate = NULL;
1950 return $formattedDate;
1953 // 1. first convert date to default format.
1954 // 2. append time to default formatted date (might be removed during format)
1955 // 3. validate date / date time.
1956 // 4. If date and time then convert to default date time format.
1959 $dateParams = array($dateKey => $date);
1961 if (CRM_Utils_Date
::convertToDefaultDate($dateParams, $dateType, $dateKey)) {
1962 $dateVal = $dateParams[$dateKey];
1964 if ($dateType == 1) {
1966 if (preg_match("/(\s(([01]\d)|[2][0-3]):([0-5]\d))$/", $date, $matches)) {
1967 $ruleName = 'dateTime';
1968 if (strpos($date, '-') !== FALSE) {
1969 $dateVal .= array_shift($matches);
1975 $valid = CRM_Utils_Rule
::$ruleName($dateVal);
1978 // format date and time to default.
1979 if ($ruleName == 'dateTime') {
1980 $dateVal = CRM_Utils_Date
::customFormat(preg_replace("/(:|\s)?/", "", $dateVal), '%Y%m%d%H%i');
1981 // hack to add seconds
1984 $formattedDate = $dateVal;
1988 return $formattedDate;
1992 * Function to return days of the month.
1996 public static function getCalendarDayOfMonth() {
1998 for ($i = 1; $i <= 31; $i++
) {
2001 $month[$i] = $i . ' / Last day of month';