@@ -146,33 +146,52 @@ public function formatPrice($price, $includeContainer = true)
146
146
/**
147
147
* Format date using current locale options and time zone.
148
148
*
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.
150
150
* @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
151
151
* @param bool $showTime Whether to include time
152
152
* @param bool $useTimezone Convert to local datetime?
153
153
* @return string
154
154
*/
155
155
public function formatDate ($ date = null , $ format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT , $ showTime = false , $ useTimezone = true )
156
156
{
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
+ ) {
157
175
if (!in_array ($ format , $ this ->_allowedFormats , true )) {
158
176
return $ date ;
159
177
}
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 ();
160
186
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 );
162
188
} elseif (is_int ($ date )) {
163
- $ date = Mage:: app ()-> getLocale () ->date ($ date , null , null , $ useTimezone );
189
+ $ date = $ locale ->date ($ date , null , null , $ useTimezone );
164
190
} 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 '' ;
170
192
}
171
193
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 );
176
195
return $ date ->toString ($ format );
177
196
}
178
197
0 commit comments