When should you use DateTime and when should you use Time?
The differences are subtle. You probably want to use Time
, except when you want to use DateTime
. See the attached article for details.
Related cards:
Why you can't use timezone codes like "PST" or "BST" for Time objects
Rails' ActiveSupport::TimeWithZone
objects have both a timezone code and offset, e.g. Thu, 28 Mar 2019 16:00:00 CET +01:00
. Ruby's stdlib TZInfo
also has time zones, but with different identifiers.
Unfortunately, not all timezone codes can b...
How Rails and MySQL are handling time zones
When working with times and dates in Rails applications, you need to deal with the following problem:
- In Rails,
Time
objects have a time zone. You can get the zone name by doingtime_object.zone
. - This zone is considered when doing time ca...
Beware when using ActiveSupport time and date calculation methods
The pitfall
Rails Active Support provides some helpful methods for calculating times and dates, like Duration#ago
or [Duration#from_now
](https://api.rubyonrail...
Why your Cucumber feature loses cookies when run under Selenium
When your Cucumber feature seems to forget cookies / sessions when you run it with Selenium check if the test travels in time like here:
Given the date is 2017-10-20
When I sign in
Then I should see "Welcome!"
What happens here i...
How to create giant memory leaks in AngularJS (and other client-side JavaScript)
This guide shows how to create an AngularJS application that consumes more and more memory until, eventually, the browser process crashes on your users.
Although this guide has been written for Angular 1 originally, most of the advice is relevant...
Your database tables should always have timestamps
Whenever you create a table from a database migration, remember to add updated_at
and created_at
timestamps to that table. Without those timestamps, investigating future bug reports will be hell. Always have timestamps.
Adding timestamps ...
Mocks and stubs in Test::Unit when you are used to RSpec
We are maintaining some vintage projects with tests written in Test::Unit instead of RSpec. Mocks and stubs are not features of Test::Unit, but you can use the Mocha gem to add those facilities.
The following is a q...
Use Time.current / Date.current / DateTime.current on projects that have a time zone
Basically, you now need to know if your project uses a "real" time zone or :local
, and if config.active_record.time_zone_aware_attributes
is set to false
or not.
- With time zones configured, always use
.current
forTime
,Date
, and `D...
The TCF 2.0 (Tranparency and Consent Framework) standard, and what you should know about it
The Interactive Advertising Bureau (IAB) is a European marketing association which has introduced a standard how advertising can be served to users in line with the General Data Protection Regulation (GDPR). This standard ...
Get the initial username which you used to login to your Linux system
If you need the initial user which you used to login to your Linux system or the time when you login you can do:
whoami
One purpose of this could be the .bashrc to show different Bash Prompts for root to different users:
if [ $(whoa...