Add timezone to date & time on the board

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
User avatar
P_I
Registered User
Posts: 998
Joined: Tue Mar 01, 2011 8:35 pm
Location: Calgary
Contact:

Re: Add timezone to date & time on the board

Post by P_I »

EA117 wrote:
Mon Jan 13, 2020 6:58 pm
John connor wrote:
Mon Jan 13, 2020 5:45 am
...how do I modify the core to denote the time zone like MDT at the end of It is currently Sat Jan 11, 2020 10:30 pm?
If you only want to do it for guests, and only for the "It is currently..." display, it's an easy change in your style. Which you could maintain as just another site-specific style modification.
Why edit core files when it can be done in ACP?
P_I wrote:
Mon Jan 13, 2020 3:28 pm
The board's default time display format is set in ACP->General->Board settings, in the Date format: field. Using the information from PHP's date() function, the Timezone abbreviation is denoted by the format character 'T'.

So change the Board settings to a custom format of

Code: Select all

M jS, ’y, H:i T
The custom format shown above is the default setting (based on QuickInstall tool) with the addition of the T parameter.
Normal people… believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. – Scott Adams

User avatar
warmweer
Registered User
Posts: 3501
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: Add timezone to date & time on the board

Post by warmweer »

P_I wrote:
Mon Jan 13, 2020 7:16 pm
Why edit core files when it can be done in ACP?
Thanks to the replies in this topic, I remembered why it was a custom edit on my board (unfortunately removed in my haste "thanks" to this topic)
The problem with the ACP setting is that it affects the whole board, thus including post_times. Having CET or UTC whatever added to every datetime shown on the indexpage (and others) and that is just plain page-fill and useless. (read EA117's post).
I wanted an indication of the timezone only for the current time display (which is why it was such a simple edit), not last visit, not post_time, topic_time, edited time, etc...
So I'll quickly re-apply my custom edit.
Brexit and Trump are old news and currently I have no inspiration for a new signature.
Ow, wait: 3.3 has been released.

User avatar
P_I
Registered User
Posts: 998
Joined: Tue Mar 01, 2011 8:35 pm
Location: Calgary
Contact:

Re: Add timezone to date & time on the board

Post by P_I »

warmweer wrote:
Mon Jan 13, 2020 7:58 pm
The problem with the ACP setting is that it affects the whole board, thus including post_times. Having CET or UTC whatever added to every datetime shown on the indexpage (and others) and that is just plain page-fill and useless. (read EA117's post).
I wanted an indication of the timezone only for the current time display (which is why it was such a simple edit), not last visit, not post_time, topic_time, edited time, etc...
Understood and I must admit I'd missed that impact of making the ACP change.
Normal people… believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. – Scott Adams

User avatar
John connor
Registered User
Posts: 2408
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Add timezone to date & time on the board

Post by John connor »

EA117 wrote:
Mon Jan 13, 2020 6:58 pm
If I've misread your intention and you really want all times displayed this way (individual post times, etc.) then there would be a different change than the one I've just described.
No, your first code snippet there is all I want. I use the custom code extension. Is it possible to add code in that extension so the code follows with board updates rather than having to prep even more of my download prior to uploading the new updated board to the FTP? I already have several core code and style changes noted down and it's such a pain to have to do all that prior to uploading the new package. But I can always jot down this style modification in my notes.

User avatar
EA117
Registered User
Posts: 1253
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Add timezone to date & time on the board

Post by EA117 »

John connor wrote:
Tue Jan 14, 2020 4:36 am
I use the custom code extension. Is it possible to add code in that extension so the code follows with board updates rather than having to prep even more of my download prior to uploading the new updated board to the FTP?
Can you give a link to what the "custom code extension" is? I'm not familiar with that, and searching the CDB didn't show an obvious reference to what you're referring to there.

User avatar
John connor
Registered User
Posts: 2408
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Add timezone to date & time on the board

Post by John connor »

It was actually the first hit on a board-wide search. viewtopic.php?t=2275361

So it uses templates for lack of the better word since I'm a code dummy. In there I could use a header or footer, etc. This would stick on board upgrades rather than modifying the core of a style and having to do that with each update. Not sure if this is entirely possible though. If not, no worries, I'll just jot down the code change in my notes for reference like all the other changes I have. :lol:

User avatar
John connor
Registered User
Posts: 2408
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Add timezone to date & time on the board

Post by John connor »

In the date & time setting in the ACP (I think board settings), I tried adding an ,e at the end of that code there what ever you call it and thought perhaps that'd pull it off, but after clearing the cache no dice.

User avatar
AmigoJack
Registered User
Posts: 5680
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Add timezone to date & time on the board

Post by AmigoJack »

John connor wrote:
Tue Jan 14, 2020 7:56 am
In the date & time setting in the ACP (I think board settings), I tried adding an ,e at the end of that code there what ever you call it and thought perhaps that'd pull it off, but after clearing the cache no dice.
If after all these years this is still the precision you're working with then good luck. Changing board settings is unbound to any cache. And if the expected outcome does not occur then reduce it to a vanilla case: does it also not work as expected in an unmodified installation without any extensions?
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

User avatar
John connor
Registered User
Posts: 2408
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Add timezone to date & time on the board

Post by John connor »

I guess you didn't read Warmweer's post now did you.

User avatar
warmweer
Registered User
Posts: 3501
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: Add timezone to date & time on the board

Post by warmweer »

John connor wrote:
Tue Jan 14, 2020 7:56 am
In the date & time setting in the ACP (I think board settings), I tried adding an ,e at the end of that code there what ever you call it and thought perhaps that'd pull it off, but after clearing the cache no dice.
The Board settings (ACP) wil affect the guest view, not your (logged in as) user view.
You need to edit your board preferences in UCP.
Brexit and Trump are old news and currently I have no inspiration for a new signature.
Ow, wait: 3.3 has been released.

User avatar
EA117
Registered User
Posts: 1253
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Add timezone to date & time on the board

Post by EA117 »

John connor wrote:
Tue Jan 14, 2020 4:36 am
No, your first code snippet there is all I want.
John connor wrote:
Tue Jan 14, 2020 7:55 am
It was actually the first hit on a board-wide search. viewtopic.php?t=2275361
Oh, duh. Don't know why I was assuming it was a released extension.

By "your first code snippet" I'm taking that to mean that you're only trying to solve this for guests, only for the "It is currently..." time display, and the style-based approach was sufficient.

Using just template events via the Custom Code extension, the easiest way to solve it is probably with CSS. e.g. Create or add to the overall header style event:
ACP > Extensions > Custom Code > Edit :: overall_header_stylesheets_after.html

Code: Select all

{#- Make the guest time display always have MDT after it -#}
<style>
.right.responsive-center.time::after {
	content: " MDT"
}
</style>
I haven't actually downloaded Aero to confirm that "everything with all of class right, class responsive-center, and class time" is selective enough to hit only the "It is currently..." time display. But it does "at minimum" hit the display we want in Aero, and appears to be selective enough in prosilver to only affect the desired "Guest user" case. If you find any other time displays being affected, we can tweak it further.

User avatar
John connor
Registered User
Posts: 2408
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Add timezone to date & time on the board

Post by John connor »

Okay, thanks. I'll give this a try on my test domain and see what happens with Aero, Win 10 and the Prosilver styles.

User avatar
John connor
Registered User
Posts: 2408
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Add timezone to date & time on the board

Post by John connor »

Okay, the code works for the verbiage of: Last visit was: Fri Jan 10, 2020 10:17 pm MDT

But it does not work for the verbiage of: It is currently Wed Jan 15, 2020 2:21 am Which is what I'm after.

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 2456
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Add timezone to date & time on the board

Post by kinerity »

I think we've moved way past an idea, so I've moved this to phpBB Custom Coding.
Kailey Truscott - Community Team

User avatar
EA117
Registered User
Posts: 1253
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Add timezone to date & time on the board

Post by EA117 »

John connor wrote:
Wed Jan 15, 2020 9:24 am
Okay, the code works for the verbiage of: Last visit was: Fri Jan 10, 2020 10:17 pm MDT

But it does not work for the verbiage of: It is currently Wed Jan 15, 2020 2:21 am Which is what I'm after.
True enough, that is the time that gets "thrown to the right side of the page" when someone is logged in, and so "Last visit was...." is getting the CSS modification. That was not intended.

For the scenario actually discussed -- guest users, for which the style-based solution would have worked, and only for the "It is currently..." display -- this same CSS modification successfully targets the "It is currently..." display in that scenario.

What you're seeing is a problem though, regardless. We cannot allow CSS to append " MDT" to a logged-on user's time display, because a logged-on user's selected time zone is not necessarily MDT. The intention of both this and the style-based modification was that we should only target guest users, where the board's default "MDT" time zone configuration is in play. But the CSS I provided is failing to limit the modification to guest users.

To solve the scenario that was being targeted, try using this updated CSS in the Custom Code extension:

ACP > Extensions > Custom Code > Edit :: overall_header_stylesheets_after.html

Code: Select all

{#- Make the guest time display always have MDT after it -#}
{%- if not S_USER_LOGGED_IN -%}
<style>
.right.responsive-center.time::after {
	content: " MDT"
}
</style>
{%- endif -%}


Edit: If your thinking now is that you do want this to affect logged-on users, and perhaps even to affect both the "It is currently..." and "Last visit was:" displays, I don't see a way to achieve any of that without an actual core code change. Or someone smarter than me and/or more familiar with Custom Code extension would have to say how.

We're "close" by having access to /phpbb/user's timezone member (a PHP DateTimeZone object), and can actually reference that during a template event. But that doesn't actually let us output an abbreviation like "MDT" or "CST". At best maybe "America/Los Angles" and names like that; although I didn't get PHP 7.2.x to successfully do that yet from just a template event, either.

The only "clear" path forward I can see to achieve that is adjusting the format_date() parameters; to use PHP date()'s "T" format character, as was done in the earlier PHP examples. And it isn't something a template event alone can achieve, to my knowledge.



kinerity wrote:
Wed Jan 15, 2020 5:54 pm
I think we've moved way past an idea, so I've moved this to phpBB Custom Coding.
Fair enough. I might have split it at the point where John Conner asked "fine, what are the core code changes I would need to make then" after there was a lack of support for the Idea. Since there is still an Idea which can continue being discussed, and voted up or down, separate from the "how can I achieve it without it being adopted by phpBB" discussion topic which is also happening.

But either way, I think most of us will survive.... 😜

Post Reply

Return to “phpBB Custom Coding”