From: joannechester Date: Mon, 17 Aug 2015 14:49:37 +0000 (+1000) Subject: week-relative-to-site-setting X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a3d92acba6b7fe6c262949b3378c2fa594d4919b;p=civicrm-core.git week-relative-to-site-setting --- diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index 31c6c95763..c257ba4a0e 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1460,12 +1460,20 @@ class CRM_Utils_Date { break; case 'week': + $weekFirst = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'weekBegins', NULL, 0);; + $thisDay = $now['wday']; + if ($weekFirst > $thisDay){ + $diffDay = $thisDay - $weekFirst + 7; + } + else { + $diffDay = $thisDay - $weekFirst; + } switch ($relativeTerm) { case 'this': $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']), $from); + $from = self::intervalAdd('day', -1 * ($diffDay), $from); $to = self::intervalAdd('day', 6, $from); break; @@ -1473,7 +1481,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']) - 7, $from); + $from = self::intervalAdd('day', -1 * ($diffDay) - 7, $from); $to = self::intervalAdd('day', 6, $from); break; @@ -1481,7 +1489,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']) - 14, $from); + $from = self::intervalAdd('day', -1 * ($diffDay) - 14, $from); $to = self::intervalAdd('day', 6, $from); break; @@ -1489,7 +1497,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']) - 14, $from); + $from = self::intervalAdd('day', -1 * ($diffDay) - 14, $from); $to = self::intervalAdd('day', 13, $from); break; @@ -1497,7 +1505,7 @@ class CRM_Utils_Date { $to['d'] = $now['mday']; $to['M'] = $now['mon']; $to['Y'] = $now['year']; - $to = self::intervalAdd('day', -1 * ($now['wday']) - 1, $to); + $to = self::intervalAdd('day', -1 * ($diffDay) - 1, $to); unset($from); break; @@ -1505,7 +1513,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']), $from); + $from = self::intervalAdd('day', -1 * ($diffDay), $from); unset($to); break; @@ -1513,7 +1521,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']) - 1, $from); + $from = self::intervalAdd('day', -1 * ($diffDay) - 1, $from); unset($to); break; @@ -1531,7 +1539,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']), $from); + $from = self::intervalAdd('day', -1 * ($diffDay), $from); $to['d'] = $now['mday']; $to['M'] = $now['mon']; $to['Y'] = $now['year']; @@ -1544,7 +1552,7 @@ class CRM_Utils_Date { $to['M'] = $now['mon']; $to['Y'] = $now['year']; //CRM-14550 QA Fix - $to = self::intervalAdd('day', -1 * ($now['wday']) + 6, $to); + $to = self::intervalAdd('day', -1 * ($diffDay) + 6, $to); unset($from); break; @@ -1552,7 +1560,7 @@ class CRM_Utils_Date { $from['d'] = $now['mday']; $from['M'] = $now['mon']; $from['Y'] = $now['year']; - $from = self::intervalAdd('day', -1 * ($now['wday']) + 7, $from); + $from = self::intervalAdd('day', -1 * ($diffDay) + 7, $from); $to = self::intervalAdd('day', 6, $from); break;