Rails: Ensure datetime uses system time - ruby-on-rails-3

In our rails app, the timezone is set to UTC in our environment file. This doesn't cause any problems when running on our production or staging servers. However, none of our local development machines are set to UTC in the system clock, and this is causing some test failures when comparing dates. This is because Rails is using UTC when we call DateTime.now, where-as our MySQL database is using the system time (CST in my case).
Is there a way to ensure that in certain cases, DateTime.now does NOT use the UTC timezone? I guess what I'm asking for is a pure SQL way of updating date fields, which bypasses the Rails engine.

Actually you should be able to tell rails to use local settings only for development and other environments like test by adding this to corresponding config/environments file :
config.time_zone = "Eastern Time (US & Canada)" #Change this
config.active_record.time_zone_aware_attributes = false
config.active_record.default_timezone = :local
That worked for me, but I switched everything including production to local time. But I don;t see why this approach wouldn't work per environment!

Related

If application is deployed in one timezone, how does using 'timestamp with time zone' works? - Psql

I have a web application in java that is deployed using tomcat on a linux server.
My database is postgres.
I have a functionality in the application where users can upload attachments/file. I save the file information in data base(file name, file upload time and so on). I save the file upload time using 'timestamp without a time zone'.
1) On reading this link, i was thinking is it a good practice for me to use 'timestamp without a time zone'? My application does not care about converting from one time zone to another. For me, it does not matter where the user is located.
2) Suppose i switch to 'timestamp with a timezone', on file upload by a user, the server only has its own time. How will it convert it to different time zones(users time zone)?

Plone backup time stamps don't match system

I am working on a development Plone 4.3.3 site with Zope 2.13.22 on Debian and noticed when I ran my backup using collective.recipe.backup that the backup time in the file name is 6 hours ahead of my system.
Example:
Backup name = 2014-08-06-17-08-15.fsz
System time (and write time according to properties) = 2014-08-06 11:08:15
I have checked multiple areas of Plone and they all match my system time.
My buildout.cfg contains the correct Time Zone information.
Any ideas as to what might be causing this or how to correct it? Thank you in advance.
IIRC, this is how the backup script works. Time values are always rendered in UTC, not server local time. This allows for unambiguous ordering of backup files.
If you look at the source of the repozo script used for backup you can see that the date portion of the filename always uses time.gmtime() so this is not something you can change.

WebSphere on AIX not taking system time

I have WebSphere 8 running on AIX and am currently experimenting with date simulation. For this purpose I use a software package called Time Machine from SolutionSoft.
The idea with Time Machine is that it replaces the system time API so that a user can specify any date, a frozen date and even the cadence.
Now, this is all very well and AIX and for instance date and "touch -m" both work as expected. When it comes to WAS8 there is quite a different story.
From what I can tell keeps WAS picking up the real time and not the system time, and this is a bother as you can realise. I have not found a way to make WAS aware of the simulated time - I have tried restarting the WAS-processes to no avail.
Anybody know how the combination WAS/AIX is handling time and, more specifically, how I can persuade WAS to pick up the simulated time?
The answer is to first make Time Machine aware of the JRE that comes with WAS as this is not done automatically. This is done with the tminstall command:
tminstall -j <path to JVM directory>
Once done, it is possible to manipulate the WAS time using the tmuser command. For example
tmuser -a -u wasuser -x 122323592015
to set the time to almost midnight, the night before Christmas 2015.

Rails - how to run method only first time, when user come to my page

I have lots of data in database and I wanna make a statistics from them. Lots of data = thousands rows in table, and I wanna get the daily, weekly, monthly (for every month) stats... just detailed statistics.
The problem is, that the getting these data takes a time (and not little).
So, I think what would be the fastest, clearest and just most effective way to get it...
My first idea - when the user come to my app, in the ApplicationController method I'll fetch from DB stats, save the objects I got into the session's variable and then I will use these variables as a source. Then when I would need somewhere in the app print out the stats, I just use this loaded data.
The question is: is this a good idea? Or, exist any better way?
Instead of storing DB stats in session variable. You can store in memcached
Rails has excellent built-in support for caching
http://memcached.org/
https://github.com/mperham/dalli
Another approach. You can cache parts of pages in per-user basis this way:
- cache [#user, :stat] do # or [#user, :stat, :daily]
statistic for the user #user
If some user's associated records affect his statistic then use:
# SomeModel.rb
belongs_to :user, touch: true
This way your user's updated_at will be updated when related model's objects are changed and user's cache will be automatically treated as outdated and block inside - cache ... do will be executed. Make sure that no (or minimum) db hits occur outside this block (e.g.: do not use Model1.where(conditions).all in your controller -- this way you will be making no db-requests, just constructing them).
To enable caching in development mode go to your config/environments/development.rb and change to true parameter config.action_controller.perform_caching and restart your app.

OpenERP strange date time issue

I am using OpenERP version 6.1 and OpenERP web client. The OpenERP server is installed in my laptop hence both server and the client on the same machine.
The issue I am facing is that it looks like OpenERP treats my local time as current UTC time.
My time zone in Windows is set to UTC+5:30 hours (Asia/Colombo) and the current time is 11:00 AM. When I see the current time from OpenERP using,
'date_created': lambda *a: datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
It shows me 03/29/2012 16:30:24 instead of correct time 11:00 AM. My observation is that OpenERP get the current time and add 5 hours 30 minutes to current time and shows me. So, OpenERP assumes my current local time as the current UTC time.
I must install the software at clients site but without this fixed, I cannot install.
The OpenERP v6.1 Release Notes state that now the server and database work exclusively with UTC dates, ignoring the OS timezone settings.
The timezone conversion is made dynamically by the client:
the Web client uses the browser setting (which usually matches the client machine settings)
the GTK client uses the setting in the user preferences.
There is one golden rule for datetime fields in 6.1 addons code:
"ALWAYS work in UTC - compute in UTC - save in UTC"
The UTC values will be properly converted to local time when the result is
diplayed in a client-side form.