/** * Support all JevDate::strftime() parameter for Window systems * * @param string $format * @param int $timestamp * @return string formated string */ function jev_strftime($format = '', $timestamp = null) { if (!$timestamp) { $timestamp = time(); } // Replace names by own translation to get rid of improper os system library if (strpos($format, '%a') !== false) { $format = str_replace('%a', JEVHelper::getShortDayName(date('w', $timestamp)), $format); } if (strpos($format, '%A') !== false) { $format = str_replace('%A', JEVHelper::getDayName(date('w', $timestamp)), $format); } if (strpos($format, '%b') !== false) { $format = str_replace('%b', JEVHelper::getShortMonthName(date('n', $timestamp)), $format); } if (strpos($format, '%B') !== false) { $format = str_replace('%B', JEVHelper::getMonthName(date('n', $timestamp)), $format); } if (JUtility::isWinOS()) { if (!class_exists('JEV_CompatWin')) { require_once dirname(__FILE__) . '/compatwin.php'; } return JEV_CompatWin::win_strftime($format, $timestamp); } else { return JevDate::strftime($format, $timestamp); } }
/** * Gets the date in a specific format * * Returns a string formatted according to the given format. Month and weekday names and * other language dependent strings respect the current locale * * @param string $format The date format specification string (see {@link PHP_MANUAL#strftime}) * @return a date in a specific format */ function toFormat($format = '%Y-%m-%d %H:%M:%S') { $date = $this->_date !== false ? strftime($format, $this->_date + $this->_offset) : null; // for Windows there is a need to convert the OS date string to utf-8. if (JUtility::isWinOS() && function_exists('iconv')) { $lang =& JFactory::getLanguage(); return iconv($lang->getWinCP(), 'UTF-8', $date); } return $date; }
/** * Testing isWinOS(). * * @param bool return value from mock * * @return void * * @dataProvider casesWinOS */ public function testIsWinOS($expResult) { $mockApplication = $this->getMock('JAplication', array('isWinOS')); $mockApplication->expects($this->once())->method('isWinOS')->will($this->returnValue($expResult)); JFactory::$application = $mockApplication; $this->assertThat(JUtility::isWinOS(), $this->equalTo($expResult)); }
function getTime($date, $h = -1, $m = -1) { $cfg =& JEVConfig::getInstance(); static $format_type; if (!isset($format_type)) { $cfg =& JEVConfig::getInstance(); $format_type = $cfg->get('com_dateformat'); } // if date format is from langauge file then do this first if ($format_type == 3) { if ($h >= 0 && $m >= 0) { $time = JevDate::mktime($h, $m); return JEV_CommonFunctions::jev_strftime(JText::_("TIME_FORMAT"), $time); } else { return JEV_CommonFunctions::jev_strftime(JText::_("TIME_FORMAT"), $date); } } if ($cfg->get('com_calUseStdTime') == '0') { if ($h >= 0 && $m >= 0) { return sprintf('%02d:%02d', $h, $m); } else { return JevDate::strftime("%H:%M", $date); } } else { if (JUtility::isWinOS()) { return JevDate::strftime("%#I:%M%p", $date); } else { return strtolower(JevDate::strftime("%I:%M%p", $date)); } } }