Skip to content

Instantly share code, notes, and snippets.

@jbarona
Created August 24, 2012 01:23
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jbarona/3444459 to your computer and use it in GitHub Desktop.
Save jbarona/3444459 to your computer and use it in GitHub Desktop.
Timestamp fun
# no config
Time.now is localtime
1.second.from_now is UTC
Timestamp stored in UTC
AR not translated
Time.now: Fri Aug 24 10:22:25 +0930 2012
1.second.from_now 2012-08-24 00:52:26 UTC
Application submitted_at before save: 2012-08-24 00:52:25 UTC
Application submitted_at after save: 2012-08-24 00:52:25 UTC
Application submitted_at after reload: 2012-08-24 00:52:25 UTC
Time in database: 24/08/2012 00:52
# config.time_zone = 'Adelaide'
Time.now is local
1.second.from_now is local
Timestamp stored in UTC
AR Translated
Time.now: Fri Aug 24 10:23:16 +0930 2012
1.second.from_now 2012-08-24 10:23:17 +0930
Application submitted_at before save: 2012-08-24 10:23:16 +0930
Application submitted_at after save: 2012-08-24 10:23:16 +0930
Application submitted_at after reload: 2012-08-24 10:23:16 +0930
Time in database: 24/08/2012 00:53
# config config.time_zone = 'Adelaide' AND config.active_record.default_timezone = 'Adelaide'
Time.now is localtime
1.second.from_now is localtime
Timestamp stored in UTC
AR reload adds +930 offset
Time.now: Fri Aug 24 10:24:35 +0930 2012
1.second.from_now 2012-08-24 10:24:36 +0930
Application submitted_at before save: 2012-08-24 10:24:35 +0930
Application submitted_at after save: 2012-08-24 10:24:35 +0930
Application submitted_at after reload: 2012-08-24 19:54:35 +0930
Time in database: 24/08/2012 10:24
# config config.active_record.default_timezone = 'Adelaide'
Time.now is localtime
1.second.from_now is UTC
Timestamp stored in localtime
AR Prior to save is UTC
AR after reload is localtime (but thinks it's UTC)
Time.now: Fri Aug 24 10:25:26 +0930 2012
1.second.from_now 2012-08-24 00:55:27 UTC
Application submitted_at before save: 2012-08-24 00:55:26 UTC
Application submitted_at after save: 2012-08-24 00:55:26 UTC
Application submitted_at after reload: 2012-08-24 10:25:26 UTC
Time in database: 24/08/2012 10:25
# RYAN'S WISDOM FTW!!!!!!!!!!!!
# config config.time_zone = 'Adelaide' AND config.active_record.default_timezone = :local
Time.now: Fri Aug 24 11:27:57 +0930 2012
1.second.from_now 2012-08-24 11:27:58 +0930
Application submitted_at before save: 2012-08-24 11:27:57 +0930
Application submitted_at after save: 2012-08-24 11:27:57 +0930
Application submitted_at after reload: 2012-08-24 11:27:57 +0930
Time in database: 24/08/2012 11:27
@hunainkapadia
Copy link

thanks for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment