CRM-16478 Initial changes to remove custom error template path
[civicrm-core.git] / CRM / Utils / Date.php
index 726d79c32da61e440dc94171ad2668af1f1460e5..31c6c95763e57ec2294a0dd4d984358947b1cdd6 100644 (file)
@@ -3,7 +3,7 @@
   +--------------------------------------------------------------------+
   | CiviCRM version 4.6                                                |
   +--------------------------------------------------------------------+
-  | Copyright CiviCRM LLC (c) 2004-2014                                |
+  | Copyright CiviCRM LLC (c) 2004-2015                                |
   +--------------------------------------------------------------------+
   | This file is a part of CiviCRM.                                    |
   |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -168,43 +168,59 @@ class CRM_Utils_Date {
   /**
    * Return abbreviated weekday names according to the locale.
    *
+   * Array will be in localized order according to 'weekBegins' setting,
+   * but array keys will always match to:
+   * 0 => Sun
+   * 1 => Mon
+   * etc.
+   *
    * @return array
    *   0-based array with abbreviated weekday names
    *
    */
-  public static function &getAbbrWeekdayNames() {
-    static $abbrWeekdayNames;
-    if (!isset($abbrWeekdayNames)) {
+  public static function getAbbrWeekdayNames() {
+    static $days = array();
+    if (!$days) {
+      // First day of the week
+      $firstDay = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'weekBegins', NULL, 0);
 
       // set LC_TIME and build the arrays from locale-provided names
       // June 1st, 1970 was a Monday
       CRM_Core_I18n::setLcTime();
-      for ($i = 0; $i < 7; $i++) {
-        $abbrWeekdayNames[$i] = strftime('%a', mktime(0, 0, 0, 6, $i, 1970));
+      for ($i = $firstDay; count($days) < 7; $i = $i > 6 ? 0 : $i + 1) {
+        $days[$i] = strftime('%a', mktime(0, 0, 0, 6, $i, 1970));
       }
     }
-    return $abbrWeekdayNames;
+    return $days;
   }
 
   /**
    * Return full weekday names according to the locale.
    *
+   * Array will be in localized order according to 'weekBegins' setting,
+   * but array keys will always match to:
+   * 0 => Sunday
+   * 1 => Monday
+   * etc.
+   *
    * @return array
    *   0-based array with full weekday names
    *
    */
-  public static function &getFullWeekdayNames() {
-    static $fullWeekdayNames;
-    if (!isset($fullWeekdayNames)) {
+  public static function getFullWeekdayNames() {
+    static $days = array();
+    if (!$days) {
+      // First day of the week
+      $firstDay = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'weekBegins', NULL, 0);
 
       // set LC_TIME and build the arrays from locale-provided names
       // June 1st, 1970 was a Monday
       CRM_Core_I18n::setLcTime();
-      for ($i = 0; $i < 7; $i++) {
-        $fullWeekdayNames[$i] = strftime('%A', mktime(0, 0, 0, 6, $i, 1970));
+      for ($i = $firstDay; count($days) < 7; $i = $i > 6 ? 0 : $i + 1) {
+        $days[$i] = strftime('%A', mktime(0, 0, 0, 6, $i, 1970));
       }
     }
-    return $fullWeekdayNames;
+    return $days;
   }
 
   /**
@@ -727,7 +743,7 @@ class CRM_Utils_Date {
    *                             format is 2007-12-21 )
    *
    * @return string
-   *   Return the customized todays date (Y-m-d)
+   *   Return the customized today's date (Y-m-d)
    */
   public static function getToday($dayParams = NULL, $format = "Y-m-d") {
     if (is_null($dayParams) || empty($dayParams)) {
@@ -1395,7 +1411,7 @@ class CRM_Utils_Date {
             $to['Y'] = $now['year'];
             $to['H'] = 23;
             $to['i'] = $to['s'] = 59;
-            $from = self::intervalAdd('month', -1, $to);
+            $from = self::intervalAdd('day', -30, $to);
             $from = self::intervalAdd('second', 1, $from);
             break;