Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Server Time

by Bod (Parson)
on Apr 07, 2024 at 10:56 UTC ( [id://11158726]=perlquestion: print w/replies, xml ) Need Help??

Bod has asked for the wisdom of the Perl Monks concerning the following question:

We've started the process of moving hosting server to a cheap VPS - just non-essential (read "hobby") sites for now whilst we get to grips with it and I learn how to manage a server...

All is going relatively well so far, but I've found an anomaly with time settings. Can anyone explain what is going on?

The 'old' server observes DST whereas the 'new' server doesn't. If I run timedatectl on the 'new' server it tells me it is set to UTC. I don't have access to run the same command on the 'old' server.

Here in the UK we are now on BST (GMT+1) so things that are time dependent (like Google Calendar feeds) that have been moved over are all 1 hour out. If I get the time from the MariaDB database SELECT NOW() I get GMT, as expected.

However, I have a bit of test code left in a page that only I use. It's a bit of JavaScript document.write(document.lastModified); which shows the time in BST. Doen't that time get passed in the HTTP headers from the Perl generated web page? Perl is, of course, also reporting GMT.

The obvious solution seems to be to change the server time from UTC to GMT.
Will that then observe UK DST?
Are there any reasons not to change the server to GMT bearing in mind that the entire codebase was written on a server that observes DST?

Update: - the "obvious" option to set would be 'Europe/London' but that is not included in timedatectl list-timezones

Replies are listed 'Best First'.
Re: Server Time [OT]
by hippo (Archbishop) on Apr 07, 2024 at 13:42 UTC
    However, I have a bit of test code left in a page that only I use. It's a bit of JavaScript document.write(document.lastModified); which shows the time in BST. Doen't that time get passed in the HTTP headers from the Perl generated web page?

    Nope, Javascript runs on the client side, not the server. The timezone there will be the timezone of your browser/WM/DE/OS on the local machine.

    Are there any reasons not to change the server to GMT bearing in mind that the entire codebase was written on a server that observes DST?

    The reason is that this will have no observable effect. For most practical purposes GMT and UTC are the same. Neither has anything to do with daylight savings adjustments.

    the "obvious" option to set would be 'Europe/London' but that is not included in timedatectl list-timezones

    Yes, that would be ideal. You will need to convince your OS that such a zone exists. Since you haven't mentioned the distro it's hard to give any further detailed advice at this stage.

    None of this is specific to Perl, BTW. You might consider making your application code independent of the O/S timezone - then this problem just vanishes.


    🦛

      You will need to convince your OS that such a zone exists

      Thank you hippo - that was the nugget of information I needed to solve the problem 😊

      Since you haven't mentioned the distro it's hard to give any further detailed advice at this stage.

      It's Debian 12 with Plesk Obsidian installed.

      I had in my head that the client side time was generated by a Perl Template but when I checked, it was actually Javascript.

Re: Server Time
by FreeBeerReekingMonk (Deacon) on Apr 08, 2024 at 20:37 UTC
    Ignore what you get with list-timezones, try:

    timedatectl set-timezone GB

    http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc

    [fbrm@confetti ~]$ timedatectl set-timezone GB [fbrm@confetti ~]$ timedatectl Local time: Sun 2024-04-07 02:48:17 BST Universal time: Sun 2024-04-07 01:48:17 UTC RTC time: Sun 2024-04-07 01:39:13 Time zone: GB (BST, +0100) System clock synchronized: no NTP service: active RTC in local TZ: no [fbrm@confetti ~]$ timedatectl list-timezones |grep -i -e GB -e BST [fbrm@confetti ~]$

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11158726]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-06-16 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.