/** * An alias for php's date function that makes weekdays and months language dependant. * * @return string A formatted date. * @param string $format The wanted format. * @param int[optional] $timestamp A UNIX-timestamp representing the date that should be formatted. * @param string[optional] $language The language to use (available languages can be found in SpoonLocale). * @param bool[optional] $GMT Should we consider this timestamp to be GMT/UTC? */ public static function getDate($format, $timestamp = null, $language = 'en', $GMT = false) { // redefine arguments $format = (string) $format; $timestamp = $timestamp === null ? time() : (int) $timestamp; $language = SpoonFilter::getValue($language, SpoonLocale::getAvailableLanguages(), 'en'); // create date $date = !$GMT ? date($format, $timestamp) : gmdate($format, $timestamp); // only for non-english versions if ($language != 'en') { // weekdays (short & long) $date = str_replace(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), SpoonLocale::getWeekDays($language), $date); $date = str_replace(array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'), SpoonLocale::getWeekDays($language, true), $date); // months (short & long) $date = str_replace(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), SpoonLocale::getMonths($language), $date); $date = str_replace(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), SpoonLocale::getMonths($language, true), $date); } return $date; }
/** * Adds months and days from spoonLocale to the json * * @param array $json * @param string $language */ protected function addSpoonLocale(&$json, $language) { // get months $monthsLong = \SpoonLocale::getMonths($language, false); $monthsShort = \SpoonLocale::getMonths($language, true); // get days $daysLong = \SpoonLocale::getWeekDays($language, false, 'sunday'); $daysShort = \SpoonLocale::getWeekDays($language, true, 'sunday'); // build labels foreach ($monthsLong as $key => $value) { $json['loc']['MonthLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($monthsShort as $key => $value) { $json['loc']['MonthShort' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysLong as $key => $value) { $json['loc']['DayLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysShort as $key => $value) { $json['loc']['DayShort' . \SpoonFilter::ucfirst($key)] = $value; } }
/** * Parse the locale (things like months, days, ...) */ private function parseLocale() { // init vars $localeToAssign = array(); // get months $monthsLong = \SpoonLocale::getMonths(BL::getInterfaceLanguage(), false); $monthsShort = \SpoonLocale::getMonths(BL::getInterfaceLanguage(), true); // get days $daysLong = \SpoonLocale::getWeekDays(BL::getInterfaceLanguage(), false, 'sunday'); $daysShort = \SpoonLocale::getWeekDays(BL::getInterfaceLanguage(), true, 'sunday'); // build labels foreach ($monthsLong as $key => $value) { $localeToAssign['locMonthLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($monthsShort as $key => $value) { $localeToAssign['locMonthShort' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysLong as $key => $value) { $localeToAssign['locDayLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysShort as $key => $value) { $localeToAssign['locDayShort' . \SpoonFilter::ucfirst($key)] = $value; } // assign $this->assignArray($localeToAssign); }
/** * Parse the locale (things like months, days, ...) */ private function parseLocale() { // init vars $locale = array(); // get months $monthsLong = SpoonLocale::getMonths(FRONTEND_LANGUAGE, false); $monthsShort = SpoonLocale::getMonths(FRONTEND_LANGUAGE, true); // get days $daysLong = SpoonLocale::getWeekDays(FRONTEND_LANGUAGE, false, 'sunday'); $daysShort = SpoonLocale::getWeekDays(FRONTEND_LANGUAGE, true, 'sunday'); // build labels foreach ($monthsLong as $key => $value) { $locale['locMonthLong' . SpoonFilter::ucfirst($key)] = $value; } foreach ($monthsShort as $key => $value) { $locale['locMonthShort' . SpoonFilter::ucfirst($key)] = $value; } foreach ($daysLong as $key => $value) { $locale['locDayLong' . SpoonFilter::ucfirst($key)] = $value; } foreach ($daysShort as $key => $value) { $locale['locDayShort' . SpoonFilter::ucfirst($key)] = $value; } // assign $this->assignArray($locale); }