diff options
-rw-r--r-- | application/Utils.php | 8 | ||||
-rw-r--r-- | index.php | 1 | ||||
-rw-r--r-- | tests/languages/de/UtilsDeTest.php | 22 | ||||
-rw-r--r-- | tests/languages/en/UtilsEnTest.php | 22 | ||||
-rw-r--r-- | tests/languages/fr/UtilsFrTest.php | 20 | ||||
-rw-r--r-- | tpl/default/daily.html | 2 |
6 files changed, 66 insertions, 9 deletions
diff --git a/application/Utils.php b/application/Utils.php index 5c077450..d6e06610 100644 --- a/application/Utils.php +++ b/application/Utils.php | |||
@@ -321,24 +321,26 @@ function normalize_spaces($string) | |||
321 | * otherwise default format '%c' will be returned. | 321 | * otherwise default format '%c' will be returned. |
322 | * | 322 | * |
323 | * @param DateTime $date to format. | 323 | * @param DateTime $date to format. |
324 | * @param bool $time Displays time if true. | ||
324 | * @param bool $intl Use international format if true. | 325 | * @param bool $intl Use international format if true. |
325 | * | 326 | * |
326 | * @return bool|string Formatted date, or false if the input is invalid. | 327 | * @return bool|string Formatted date, or false if the input is invalid. |
327 | */ | 328 | */ |
328 | function format_date($date, $intl = true) | 329 | function format_date($date, $time = true, $intl = true) |
329 | { | 330 | { |
330 | if (! $date instanceof DateTime) { | 331 | if (! $date instanceof DateTime) { |
331 | return false; | 332 | return false; |
332 | } | 333 | } |
333 | 334 | ||
334 | if (! $intl || ! class_exists('IntlDateFormatter')) { | 335 | if (! $intl || ! class_exists('IntlDateFormatter')) { |
335 | return strftime('%c', $date->getTimestamp()); | 336 | $format = $time ? '%c' : '%x'; |
337 | return strftime($format, $date->getTimestamp()); | ||
336 | } | 338 | } |
337 | 339 | ||
338 | $formatter = new IntlDateFormatter( | 340 | $formatter = new IntlDateFormatter( |
339 | setlocale(LC_TIME, 0), | 341 | setlocale(LC_TIME, 0), |
340 | IntlDateFormatter::LONG, | 342 | IntlDateFormatter::LONG, |
341 | IntlDateFormatter::LONG | 343 | $time ? IntlDateFormatter::LONG : IntlDateFormatter::NONE |
342 | ); | 344 | ); |
343 | 345 | ||
344 | return $formatter->format($date); | 346 | return $formatter->format($date); |
@@ -699,6 +699,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) | |||
699 | 'linksToDisplay' => $linksToDisplay, | 699 | 'linksToDisplay' => $linksToDisplay, |
700 | 'cols' => $columns, | 700 | 'cols' => $columns, |
701 | 'day' => $dayDate->getTimestamp(), | 701 | 'day' => $dayDate->getTimestamp(), |
702 | 'dayDate' => $dayDate, | ||
702 | 'previousday' => $previousday, | 703 | 'previousday' => $previousday, |
703 | 'nextday' => $nextday, | 704 | 'nextday' => $nextday, |
704 | ); | 705 | ); |
diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php index 545fa572..6c9c9adc 100644 --- a/tests/languages/de/UtilsDeTest.php +++ b/tests/languages/de/UtilsDeTest.php | |||
@@ -11,7 +11,16 @@ class UtilsDeTest extends UtilsTest | |||
11 | public function testDateFormat() | 11 | public function testDateFormat() |
12 | { | 12 | { |
13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | 13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); |
14 | $this->assertRegExp('/1. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true)); | 14 | $this->assertRegExp('/1\. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true, true)); |
15 | } | ||
16 | |||
17 | /** | ||
18 | * Test date_format() without time. | ||
19 | */ | ||
20 | public function testDateFormatNoTime() | ||
21 | { | ||
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
23 | $this->assertRegExp('/1\. Januar 2017/', format_date($date, false,true)); | ||
15 | } | 24 | } |
16 | 25 | ||
17 | /** | 26 | /** |
@@ -20,7 +29,16 @@ class UtilsDeTest extends UtilsTest | |||
20 | public function testDateFormatDefault() | 29 | public function testDateFormatDefault() |
21 | { | 30 | { |
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | 31 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); |
23 | $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); | 32 | $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, true, false)); |
33 | } | ||
34 | |||
35 | /** | ||
36 | * Test date_format() using builtin PHP function strftime without time. | ||
37 | */ | ||
38 | public function testDateFormatDefaultNoTime() | ||
39 | { | ||
40 | $date = DateTime::createFromFormat('Ymd_His', '20170201_101112'); | ||
41 | $this->assertEquals('01.02.2017', format_date($date, false, false)); | ||
24 | } | 42 | } |
25 | 43 | ||
26 | /** | 44 | /** |
diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php index 7c829ac7..d8680b2b 100644 --- a/tests/languages/en/UtilsEnTest.php +++ b/tests/languages/en/UtilsEnTest.php | |||
@@ -11,7 +11,16 @@ class UtilsEnTest extends UtilsTest | |||
11 | public function testDateFormat() | 11 | public function testDateFormat() |
12 | { | 12 | { |
13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | 13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); |
14 | $this->assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true)); | 14 | $this->assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true, true)); |
15 | } | ||
16 | |||
17 | /** | ||
18 | * Test date_format() without time. | ||
19 | */ | ||
20 | public function testDateFormatNoTime() | ||
21 | { | ||
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
23 | $this->assertRegExp('/January 1, 2017/', format_date($date, false, true)); | ||
15 | } | 24 | } |
16 | 25 | ||
17 | /** | 26 | /** |
@@ -20,7 +29,16 @@ class UtilsEnTest extends UtilsTest | |||
20 | public function testDateFormatDefault() | 29 | public function testDateFormatDefault() |
21 | { | 30 | { |
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | 31 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); |
23 | $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); | 32 | $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, true, false)); |
33 | } | ||
34 | |||
35 | /** | ||
36 | * Test date_format() using builtin PHP function strftime without time. | ||
37 | */ | ||
38 | public function testDateFormatDefaultNoTime() | ||
39 | { | ||
40 | $date = DateTime::createFromFormat('Ymd_His', '20170201_101112'); | ||
41 | $this->assertEquals('02/01/2017', format_date($date, false, false)); | ||
24 | } | 42 | } |
25 | 43 | ||
26 | /** | 44 | /** |
diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php index 45996ee2..0d50a878 100644 --- a/tests/languages/fr/UtilsFrTest.php +++ b/tests/languages/fr/UtilsFrTest.php | |||
@@ -15,12 +15,30 @@ class UtilsFrTest extends UtilsTest | |||
15 | } | 15 | } |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * Test date_format() without time. | ||
19 | */ | ||
20 | public function testDateFormatNoTime() | ||
21 | { | ||
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
23 | $this->assertRegExp('/1 janvier 2017/', format_date($date, false, true)); | ||
24 | } | ||
25 | |||
26 | /** | ||
18 | * Test date_format() using builtin PHP function strftime. | 27 | * Test date_format() using builtin PHP function strftime. |
19 | */ | 28 | */ |
20 | public function testDateFormatDefault() | 29 | public function testDateFormatDefault() |
21 | { | 30 | { |
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | 31 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); |
23 | $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); | 32 | $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, true, false)); |
33 | } | ||
34 | |||
35 | /** | ||
36 | * Test date_format() using builtin PHP function strftime without time. | ||
37 | */ | ||
38 | public function testDateFormatDefaultNoTime() | ||
39 | { | ||
40 | $date = DateTime::createFromFormat('Ymd_His', '20170201_101112'); | ||
41 | $this->assertEquals('01/02/2017', format_date($date, false, false)); | ||
24 | } | 42 | } |
25 | 43 | ||
26 | /** | 44 | /** |
diff --git a/tpl/default/daily.html b/tpl/default/daily.html index d8c91078..29d845d5 100644 --- a/tpl/default/daily.html +++ b/tpl/default/daily.html | |||
@@ -44,7 +44,7 @@ | |||
44 | </div> | 44 | </div> |
45 | </div> | 45 | </div> |
46 | <div> | 46 | <div> |
47 | <h3 class="window-subtitle">{function="strftime('%A %d, %B %Y', $day)"}</h3> | 47 | <h3 class="window-subtitle">{function="format_date($dayDate, false)"}</h3> |
48 | 48 | ||
49 | <div id="plugin_zone_about_daily" class="plugin_zone"> | 49 | <div id="plugin_zone_about_daily" class="plugin_zone"> |
50 | {loop="$daily_about_plugin"} | 50 | {loop="$daily_about_plugin"} |