@@ -146,33 +146,52 @@ public function formatPrice($price, $includeContainer = true)
146146 /**
147147 * Format date using current locale options and time zone.
148148 *
149- * @param string|Zend_Date|null $date If empty, return current datetime.
149+ * @param string|Zend_Date|int| null $date If empty, return current local datetime.
150150 * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
151151 * @param bool $showTime Whether to include time
152152 * @param bool $useTimezone Convert to local datetime?
153153 * @return string
154154 */
155155 public function formatDate ($ date = null , $ format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT , $ showTime = false , $ useTimezone = true )
156156 {
157+ return $ this ->formatTimezoneDate ($ date , $ format , $ showTime );
158+ }
159+
160+ /**
161+ * Format date using current locale options and time zone.
162+ *
163+ * @param string|Zend_Date|null $date If empty, return current datetime.
164+ * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
165+ * @param bool $showTime Whether to include time
166+ * @param bool $useTimezone Convert to local datetime?
167+ * @return string
168+ */
169+ public function formatTimezoneDate (
170+ $ date = null ,
171+ string $ format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT ,
172+ bool $ showTime = false ,
173+ bool $ useTimezone = true
174+ ) {
157175 if (!in_array ($ format , $ this ->_allowedFormats , true )) {
158176 return $ date ;
159177 }
178+
179+ if ($ showTime ) {
180+ $ format = Mage::app ()->getLocale ()->getDateTimeFormat ($ format );
181+ } else {
182+ $ format = Mage::app ()->getLocale ()->getDateFormat ($ format );
183+ }
184+
185+ $ locale = Mage::app ()->getLocale ();
160186 if (empty ($ date )) {
161- $ date = Mage:: app ()-> getLocale () ->date (Mage::getSingleton ('core/date ' )->gmtTimestamp (), null , null , $ useTimezone );
187+ $ date = $ locale ->date (Mage::getSingleton ('core/date ' )->gmtTimestamp (), null , null , $ useTimezone );
162188 } elseif (is_int ($ date )) {
163- $ date = Mage:: app ()-> getLocale () ->date ($ date , null , null , $ useTimezone );
189+ $ date = $ locale ->date ($ date , null , null , $ useTimezone );
164190 } elseif (!$ date instanceof Zend_Date) {
165- if ($ time = strtotime ($ date )) {
166- $ date = Mage::app ()->getLocale ()->date ($ time , null , null , $ useTimezone );
167- } else {
168- return '' ;
169- }
191+ return '' ;
170192 }
171193
172- $ format = $ showTime
173- ? Mage::app ()->getLocale ()->getDateTimeFormat ($ format )
174- : Mage::app ()->getLocale ()->getDateFormat ($ format );
175-
194+ $ format = $ showTime ? $ locale ->getDateTimeFormat ($ format ) : $ locale ->getDateFormat ($ format );
176195 return $ date ->toString ($ format );
177196 }
178197
0 commit comments