+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
/**
* 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;
}
/**
* 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)) {
$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;