Skip to content

Commit 7a78137

Browse files
Merge pull request #8366 from Sesquipedalian/3.0/time
Some minor improvements to SMF\Time
2 parents cd2d0b9 + 6716cac commit 7a78137

File tree

8 files changed

+246
-101
lines changed

8 files changed

+246
-101
lines changed

Languages/en_US/General.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@
591591

592592
$txt['today'] = '<strong>Today</strong> at ';
593593
$txt['yesterday'] = '<strong>Yesterday</strong> at ';
594+
$txt['tomorrow'] = '<strong>Tomorrow</strong> at ';
594595
$txt['new_poll'] = 'New poll';
595596
$txt['poll_question'] = 'Question';
596597
$txt['poll_vote'] = 'Submit Vote';

Languages/en_US/Help.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@
228228
$helptxt['titlesEnable'] = 'Switching Custom Titles on will allow members with the relevant permission to create a special title for themselves.
229229
This will be shown underneath the name.<br><em>For example:</em><br>Jeff<br>Cool Guy';
230230
$helptxt['onlineEnable'] = 'This will show an image to indicate whether the member is online or offline';
231-
$helptxt['todayMod'] = 'This will show &quot;Today&quot; or &quot;Yesterday&quot; instead of the date.<br><br>
231+
$helptxt['todayMod'] = 'This will show &quot;Yesterday&quot;, &quot;Today&quot;, or &quot;Tomorrow&quot; instead of the date.<br><br>
232232
<strong>Examples:</strong><br><br>
233233
<ul class="normallist">
234234
<li>
235235
<strong>Disabled</strong><br>
236236
October 3, 2009 at 12:59:18 am</li>
237237
<li><strong>Only Today</strong><br>
238238
Today at 12:59:18 am</li>
239-
<li><strong>Today &amp; Yesterday</strong><br>
239+
<li><strong>Yesterday, Today, &amp; Tomorrow</strong><br>
240240
Yesterday at 09:36:55 pm</li>
241241
</ul>';
242242
$helptxt['disableCustomPerPage'] = 'Check this setting to stop users from customizing the amount of messages and topics to display per page on the Message Index and Topic Display page respectively.';

Languages/en_US/ManageSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
$txt['todayMod'] = 'Enable shorthand date display';
9797
$txt['today_disabled'] = 'Disabled';
9898
$txt['today_only'] = 'Only Today';
99-
$txt['yesterday_today'] = 'Today &amp; Yesterday';
99+
$txt['yesterday_today'] = 'Yesterday, Today, &amp; Tomorrow';
100100
$txt['onlineEnable'] = 'Show online/offline status in posts and PMs';
101101
$txt['defaultMaxMembers'] = 'Members per page in member list';
102102
$txt['timeLoadPageEnable'] = 'Display time taken to create every page';

Sources/Actions/Admin/Bans.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ public function log(): void
947947
],
948948
'data' => [
949949
'function' => function ($rowData) {
950-
return Time::timeformat($rowData['log_time']);
950+
return Time::stringFromUnix($rowData['log_time']);
951951
},
952952
],
953953
'sort' => [

Sources/Actions/Calendar.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function show(): void
171171

172172
// Need a start date for all views
173173
if (!empty($_REQUEST['start_date'])) {
174-
$start_parsed = date_parse(str_replace(',', '', self::convertDateToEnglish($_REQUEST['start_date'])));
174+
$start_parsed = date_parse(str_replace(',', '', Time::convertToEnglish($_REQUEST['start_date'])));
175175

176176
if (empty($start_parsed['error_count']) && empty($start_parsed['warning_count'])) {
177177
$_REQUEST['year'] = $start_parsed['year'];
@@ -187,7 +187,7 @@ public function show(): void
187187

188188
// Need an end date for the list view
189189
if (!empty($_REQUEST['end_date'])) {
190-
$end_parsed = date_parse(str_replace(',', '', self::convertDateToEnglish($_REQUEST['end_date'])));
190+
$end_parsed = date_parse(str_replace(',', '', Time::convertToEnglish($_REQUEST['end_date'])));
191191

192192
if (empty($end_parsed['error_count']) && empty($end_parsed['warning_count'])) {
193193
$_REQUEST['end_year'] = $end_parsed['year'];
@@ -1486,7 +1486,7 @@ public static function validateEventPost(): void
14861486
if (!isset($_POST['deleteevent'])) {
14871487
// The 2.1 way
14881488
if (isset($_POST['start_date'])) {
1489-
$d = date_parse(str_replace(',', '', self::convertDateToEnglish($_POST['start_date'])));
1489+
$d = date_parse(str_replace(',', '', Time::convertToEnglish($_POST['start_date'])));
14901490

14911491
if (!empty($d['error_count']) || !empty($d['warning_count'])) {
14921492
ErrorHandler::fatalLang('invalid_date', false);
@@ -1500,7 +1500,7 @@ public static function validateEventPost(): void
15001500
ErrorHandler::fatalLang('event_month_missing', false);
15011501
}
15021502
} elseif (isset($_POST['start_datetime'])) {
1503-
$d = date_parse(str_replace(',', '', self::convertDateToEnglish($_POST['start_datetime'])));
1503+
$d = date_parse(str_replace(',', '', Time::convertToEnglish($_POST['start_datetime'])));
15041504

15051505
if (!empty($d['error_count']) || !empty($d['warning_count'])) {
15061506
ErrorHandler::fatalLang('invalid_date', false);
@@ -1624,50 +1624,6 @@ public static function removeHolidays(array $holiday_ids): void
16241624
}
16251625
}
16261626

1627-
/**
1628-
* Helper function to convert date string to english
1629-
* so that date_parse can parse the date
1630-
*
1631-
* @param string $date A localized date string
1632-
* @return string English date string
1633-
*/
1634-
public static function convertDateToEnglish(string $date): string
1635-
{
1636-
if (User::$me->language == 'english') {
1637-
return $date;
1638-
}
1639-
1640-
$replacements = array_combine(array_map('strtolower', Lang::$txt['months_titles']), [
1641-
'January', 'February', 'March', 'April', 'May', 'June',
1642-
'July', 'August', 'September', 'October', 'November', 'December',
1643-
]);
1644-
$replacements += array_combine(array_map('strtolower', Lang::$txt['months_short']), [
1645-
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
1646-
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
1647-
]);
1648-
$replacements += array_combine(array_map('strtolower', Lang::$txt['days']), [
1649-
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
1650-
]);
1651-
$replacements += array_combine(array_map('strtolower', Lang::$txt['days_short']), [
1652-
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
1653-
]);
1654-
// Find all possible variants of AM and PM for this language.
1655-
$replacements[strtolower(Lang::$txt['time_am'])] = 'AM';
1656-
$replacements[strtolower(Lang::$txt['time_pm'])] = 'PM';
1657-
1658-
if (($am = Time::strftime('%p', strtotime('01:00:00'))) !== 'p' && $am !== false) {
1659-
$replacements[strtolower($am)] = 'AM';
1660-
$replacements[strtolower(Time::strftime('%p', strtotime('23:00:00')))] = 'PM';
1661-
}
1662-
1663-
if (($am = Time::strftime('%P', strtotime('01:00:00'))) !== 'P' && $am !== false) {
1664-
$replacements[strtolower($am)] = 'AM';
1665-
$replacements[strtolower(Time::strftime('%P', strtotime('23:00:00')))] = 'PM';
1666-
}
1667-
1668-
return strtr(strtolower($date), $replacements);
1669-
}
1670-
16711627
/******************
16721628
* Internal methods
16731629
******************/

Sources/Parsers/BBCodeParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class BBCodeParser extends Parser
626626
'parameters' => [
627627
'author' => ['match' => '([^<>]{1,192}?)'],
628628
'link' => ['match' => '(?:board=\d+;)?((?:topic|threadid)=[\dmsg#\./]{1,40}(?:;start=[\dmsg#\./]{1,40})?|msg=\d+?|action=profile;u=\d+)'],
629-
'date' => ['match' => '(\d+)', 'validate' => 'SMF\\Time::timeformat'],
629+
'date' => ['match' => '(\d+)', 'validate' => 'SMF\\Time::stringFromUnix'],
630630
],
631631
'before' => '<blockquote><cite><a href="{scripturl}?{link}">{txt_quote_from}: {author} {txt_search_on} {date}</a></cite>',
632632
'after' => '</blockquote>',

Sources/Subs-Compat.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,11 +1940,6 @@ function removeHolidays(array $holiday_ids): void
19401940
Actions\Calendar::removeHolidays($holiday_ids);
19411941
}
19421942

1943-
function convertDateToEnglish(string $date): string
1944-
{
1945-
return Actions\Calendar::convertDateToEnglish($date);
1946-
}
1947-
19481943
/**
19491944
* Begin
19501945
* Actions\CoppaForm
@@ -4764,13 +4759,24 @@ function get_date_or_time_format(string $type = '', string $format = '', ?bool $
47644759

47654760
function timeformat(int $log_time, bool|string $show_today = true, ?string $tzid = null): string
47664761
{
4767-
return SMF\Time::timeformat($log_time, $show_today, $tzid);
4762+
// For backward compatibility, replace empty values with the user's time
4763+
// zone and replace anything invalid with the forum's default time zone.
4764+
$tzid = empty($tzid) ? SMF\User::getTimezone() : (($tzid === 'forum' || @timezone_open((string) $tzid) === false) ? SMF\Config::$modSettings['default_timezone'] : $tzid);
4765+
4766+
$date = new SMF\Time('@' . $log_time, $tzid);
4767+
4768+
return is_bool($show_today) ? $date->format(null, $show_today) : $date->format($show_today);
4769+
}
4770+
4771+
function convertDateToEnglish(string $date): string
4772+
{
4773+
return SMF\Time::convertToEnglish($date);
47684774
}
47694775

47704776
/** @deprecated since 2.1 */
47714777
function forum_time(bool $use_user_offset = true, ?int $timestamp = null): int
47724778
{
4773-
return SMF\Time::forumTime($use_user_offset, $timestamp);
4779+
return !isset($timestamp) ? time() : (int) $timestamp;
47744780
}
47754781

47764782
/**

0 commit comments

Comments
 (0)