Rails isn't applying daylight saving time - ruby-on-rails

My server's clock is set to London time (I'm currently living in the GMT+0 zone). The output of timedatectl status gives me this:
Local time: Mon 2016-05-23 08:13:06 BST Universal time: Mon 2016-05-23 07:13:06 UTC
RTC time: Mon 2016-05-23 07:13:06
Timezone: Europe/London (BST, +0100)
NTP enabled: yes NTP synchronized: no RTC in local TZ: no
DST active: yes Last DST change: DST began at
Sun 2016-03-27 00:59:59 GMT
Sun 2016-03-27 02:00:00 BST Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2016-10-30 01:59:59 BST
Sun 2016-10-30 01:00:00 GMT
And in my application.rb file I set the timezone:
config.time_zone = 'London'
Locally, it works right:
Time.now.dst?
# true
Time.now.hour
# 8
But in production it doesn't seem that DST is on.
Time.now.dst?
# false
Time.now.hour
# 7
I am not sure if it's a Rails thing or a server misconfiguration, but for me it seems right.

If this application is running within a docker container, the timezone of the host server may not be applied to the containers. You can probably set the TZ environment variable to whatever timezone you'd like and ruby will pick it up.
I highly recommend not using non-UTC timezone for your application/database, as it will almost certainly cause problems down the line.
Full disclosure: I am one of the dokku maintainers.

Related

How to fix difference of hours in timezone settings [ gnome timer ]

It is generally known that Bangkok have UTC+7.
But unfortunately my gnome timer shows UTC+4 for Bangkok
When I checking it by console I see
timedatectl status
Local time: śro 2023-02-08 10:59:07 +07
Universal time: śro 2023-02-08 03:59:07 UTC
RTC time: śro 2023-02-08 03:59:07
Time zone: Asia/Bangkok (+07, +0700)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
So problem is probably with gnome timer.
I found issue describing this problem but it is closed. And 7 open issues connected with time zone for gnome clock.

highcharts-export-server always produces blank PNG

I'm trying to use highcharts-export-server in command-line/batch mode. I've installed the latest version (2.0.28). I'm running Windows 10 with Node 12.
I'm running it from the command line using the following command:
highcharts-export-server --nologo 1 --logLevel 4 --options chart.json --outfile chart.png --type png --width 500
The console output says:
starting highcharts export server v2.0.28...
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] attaching exit listeners to the process..
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] Pool started:
maxWorkers: 1
initialWorkers: 1
workLimit: 60
listening to process exit: true
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] phantom 1 - spawning worker
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] starting export
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] attempting to export from raw input
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] phantom - received work, finding available worker
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] phantom - found available worker
Fri Sep 25 2020 15:07:48 GMT+0100 (British Summer Time) [verbose] phantom 1 - starting work
Fri Sep 25 2020 15:07:52 GMT+0100 (British Summer Time) [notice] phantom worker 1 finished work ??? in 3562 ms
Fri Sep 25 2020 15:07:52 GMT+0100 (British Summer Time) [notice] phantom worker 1 - process was closed
Fri Sep 25 2020 15:07:52 GMT+0100 (British Summer Time) [notice] terminating, killing all running phantom processes
...but although a chart.png file is created and has the correct width, it's blank (transparent):
This is the content of the chart.json file, which I took from one of the examples on the Highcharts website:
{
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
}, {
name: 'John',
data: [5, 7, 3]
}]
}
Note: I'll mention that when I first tried to install highcharts-export-server I hit a different problem which was that I couldn't run it at all (it failed with uncaughtException: TypeError: "file" argument must be a non-empty string). After some googling I found some blog posts suggesting that I needed to install PhantomJS first, and to use the --unsafe-perm option. So, the commands I actually used to install it was:
npm install phantomjs --unsafe-perm
npm install highcharts-export-server --unsafe-perm
Oh, and it wasn't until some time later that I realised I might have to install Highcharts itself :-) So I did that too (npm install highcharts), but it didn't actually seem to make a difference.
In case this helps anyone else, here is the full conversation about this issue on the Highcharts Forum.
In summary, it turned out that the NPM package was improperly installed (due to a firewall issue).
This wasn't apparent from the installation logs, but the effect was that in the node_modules/highcharts/export-server/phantom/export.html file there was a script block that should have contained minified JavaScript but that actually contained only lines saying undefined;.
The fix in my case (to work around the firewall issue) was to specify an http URL for the CDN when installing Highcharts Export Server, rather than the default URL which uses https. Once I'd done that, the export.html did contain the minified JS code, and the tool worked correctly.

Time.zone.now & current machine time

Seems Time.zonew.now depends on the machine current time. It's weird for me.
application.rb
config.time_zone = 'Central Time (US & Canada)'
I made the experiment.
real current time time in CST time zone
5:54 AM
STEP 1) I have forced current machine time to 7:37pm.
system time
drobazko#drobazko:~/www$ date
Mon Aug 17 19:37:35 EDT 2015
rails c
1.9.3-p484 :001 > Time.zone
=> (GMT-06:00) Central Time (US & Canada)
1.9.3-p484 :002 > Time.zone.now
=> Mon, 17 Aug 2015 18:40:15 CDT -05:00
STEP 2) I have forced current machine time to 3:17pm.
real current time time in CST
5:54 AM
system time
drobazko#drobazko:~/www$ date
Mon Aug 17 15:17:09 EDT 2015
rails c
1.9.3-p484 :001 > Time.zone
=> (GMT-06:00) Central Time (US & Canada)
1.9.3-p484 :002 > Time.zone.now
=> Mon, 17 Aug 2015 14:18:39 CDT -05:00
Question: why Time.zone.now doesn't give me real current CST time about 5am?
You can find the solution here: http://www.timeanddate.com/time/zones/cst
In Summer: CDT and Winter: CST. At the moment, we are in Summer :)
Time.now method returns system time, so Time.zone.now also returns system time but in the application's time zone.

How can I switch my Rails App timezone to PST?

I've tried
config.time.in_time_zone("Pacific Time (US & Canada)")
as well as
config.time_zone("PST")
and both caused errors and caused the heroku app to crash. What is the proper way to switch my app to PST time?
Thanks!!
Place the following in your config/application.rb and restart rails server:
config.time_zone = 'Pacific Time (US & Canada)'
Here is the description from Rails Guides Configuring Rails Application:
config.time_zone sets the default time zone for the application and
enables time zone awareness for Active Record.
Then the usage for in_time_zone:
> Date.today
=> Thu, 13 Mar 2014
> Time.zone
=> (GMT-08:00) Pacific Time (US & Canada)
> Date.today.to_time.in_time_zone
=> Wed, 12 Mar 2014 21:00:00 PDT -07:00
To output a time in different time zone:
> Date.today.to_time.in_time_zone('Eastern Time (US & Canada)')
=> Wed, 13 Mar 2014 00:00:00 EDT -04:00

Two Rails servers with the same Time.zone, same server timezone, but getting different results from Date.to_time

I am running Rails on two machines, but getting different results from to_time method. I only checked the system timezone and Time.zone configuration, am I missing anything? Thanks
Server 1
user#Server1:/var/www/app$ date
Wed Oct 23 23:56:35 MDT 2013
user#Server1:/var/www/app$ cat /etc/timezone
America/Denver
user#Server1:/var/www/app$ bundle exec rails c production
irb(main):011:0> Time.zone
=> (GMT+00:00) UTC
irb(main):012:0> Date.parse("10/24/2013").to_time
=> 2013-10-24 00:00:00 +0000
Server 2
user#Server2:/var/www/app$ date
Thu Oct 24 00:03:28 MDT 2013
user#Server2:/var/www/app$ cat /etc/timezone
America/Denver
user#Server2:/var/www/app$ bundle exec rails c production
irb(main):002:0> Time.zone
=> (GMT+00:00) UTC
irb(main):003:0> Date.parse("10/24/2013").to_time
=> 2013-10-24 00:00:00 -0600
Time#local_time (called by ActiveSupport in the implementation of Date#to_time) respects the TZ environment variable for which timezone should be used for the "local" time.
Ensure that the environment is the same between the two servers.

Resources