diff --git a/lib/Newsletter/Shortcodes/Categories/Date.php b/lib/Newsletter/Shortcodes/Categories/Date.php index 53821d8b0c..5e93137b4e 100644 --- a/lib/Newsletter/Shortcodes/Categories/Date.php +++ b/lib/Newsletter/Shortcodes/Categories/Date.php @@ -2,9 +2,9 @@ namespace MailPoet\Newsletter\Shortcodes\Categories; class Date { - static function process($action) { + static function process($format) { $date = new \DateTime('now'); - $actions = array( + $available_formats = array( 'd' => $date->format('d'), 'dordinal' => $date->format('dS'), 'dtext' => $date->format('l'), @@ -12,6 +12,11 @@ class Date { 'mtext' => $date->format('F'), 'y' => $date->format('Y') ); - return (isset($actions[$action])) ? $actions[$action] : false; + if(!empty($available_formats[$format])) { + return $available_formats[$format]; + } + return (preg_match('/^custom_(.*?)$/', $format, $custom_format)) ? + $date->format($custom_format[1]) : + false; } } \ No newline at end of file diff --git a/tests/unit/Newsletter/ShortcodesTest.php b/tests/unit/Newsletter/ShortcodesTest.php index 1377855c40..9723a15691 100644 --- a/tests/unit/Newsletter/ShortcodesTest.php +++ b/tests/unit/Newsletter/ShortcodesTest.php @@ -85,6 +85,8 @@ class ShortcodesTest extends MailPoetTest { expect(Date::process('m'))->equals($date->format('m')); expect(Date::process('mtext'))->equals($date->format('F')); expect(Date::process('y'))->equals($date->format('Y')); + // allow custom date formats (http://php.net/manual/en/function.date.php) + expect(Date::process('custom_U'))->equals($date->format('U')); } function testItCanProcessNewsletterShortcodes() {