Add in unit test of searching when price field value label has changed
[civicrm-core.git] / CRM / Utils / Date.php
index 913c930a4559b67c7b8d0ce3cb2c8b5876b25419..fa96fca47fa1a0394a2bd4cd7b6c781a3101d498 100644 (file)
@@ -763,7 +763,6 @@ class CRM_Utils_Date {
     }
   }
 
-
   /**
    * @param null $timeStamp
    *
@@ -901,7 +900,7 @@ class CRM_Utils_Date {
    * @return int
    *   array $results contains years or months
    */
-  static public function calculateAge($birthDate) {
+  public static function calculateAge($birthDate) {
     $results = [];
     $formatedBirthDate = CRM_Utils_Date::customFormat($birthDate, '%Y-%m-%d');
 
@@ -1858,9 +1857,9 @@ class CRM_Utils_Date {
     }
 
     foreach ([
-               'from',
-               'to',
-             ] as $item) {
+      'from',
+      'to',
+    ] as $item) {
       if (!empty($$item)) {
         $dateRange[$item] = self::format($$item);
       }
@@ -1961,7 +1960,6 @@ class CRM_Utils_Date {
     return $field;
   }
 
-
   /**
    * Get the fields required for the 'extra' parameter when adding a datepicker.
    *
@@ -2170,7 +2168,6 @@ class CRM_Utils_Date {
     return $month;
   }
 
-
   /**
    * Convert a relative date format to an api field.
    *
@@ -2207,4 +2204,17 @@ class CRM_Utils_Date {
     }
   }
 
+  /**
+   * Print out a date object in specified format in local timezone
+   *
+   * @param DateTimeObject $dateObject
+   * @param string $format
+   * @return string
+   */
+  public static function convertDateToLocalTime($dateObject, $format = 'YmdHis') {
+    $systemTimeZone = new DateTimeZone(CRM_Core_Config::singleton()->userSystem->getTimeZoneString());
+    $dateObject->setTimezone($systemTimeZone);
+    return $dateObject->format($format);
+  }
+
 }