Last active
June 22, 2022 00:40
-
-
Save wwalker/fc00059df67d66233160aa29522cb652 to your computer and use it in GitHub Desktop.
Time vs ActiveSupport::TimeWithZone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):028:0> cp.last.class | |
=> Time | |
irb(main):029:0> cp.last | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):030:0> c.next_run.class | |
=> NilClass | |
irb(main):031:0> c.next_run=cp.last | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):032:0> c.next_run.class | |
=> ActiveSupport::TimeWithZone | |
irb(main):033:0> c.next_run | |
=> Sat, 01 Jan 2000 21:30:00.000000000 UTC +00:00 | |
irb(main):034:0> c.next_run=cp.last | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):035:0> c.next_run | |
=> Sat, 01 Jan 2000 21:30:00.000000000 UTC +00:00 | |
irb(main):036:0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):063:0> c.next_run=cp.last.to_time | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):064:0> c.next_run | |
=> Sat, 01 Jan 2000 21:30:00.000000000 UTC +00:00 | |
irb(main):065:0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):066:0> x.class | |
=> Time | |
irb(main):067:0> x | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):068:0> c.next_run | |
=> Sat, 01 Jan 2000 21:30:00.000000000 UTC +00:00 | |
irb(main):069:0> c.next_run=x | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):070:0> c.next_run | |
=> Sat, 01 Jan 2000 21:30:00.000000000 UTC +00:00 | |
irb(main):071:0> ENV{TZ}='UTC' | |
/home/wwalker/.asdf/installs/ruby/3.1.2/lib/ruby/3.1.0/irb/workspace.rb:119:in `eval': (irb):71: syntax error, unexpected '=', expecting end-of-input (SyntaxError) | |
ENV{TZ}='UTC' | |
^ | |
irb(main):072:0> ENV['TZ']='UTC' | |
=> "UTC" | |
irb(main):073:0> x | |
=> 2022-06-21 15:30:00 -0500 | |
irb(main):074:0> x=Time.now | |
=> 2022-06-21 23:43:19.930931468 +0000 | |
irb(main):075:0> c.next_run=x | |
=> 2022-06-21 23:43:19.930931468 +0000 | |
irb(main):076:0> c.next_run | |
=> Sat, 01 Jan 2000 23:43:19.930931468 UTC +00:00 | |
irb(main):077:0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateCrons < ActiveRecord::Migration[7.0] | |
def change | |
create_table :crons do |t| | |
t.string :reminder_id | |
t.string :entry | |
t.time :last_run | |
t.time :next_run | |
t.time :deleted_at | |
t.string :timestamps | |
t.timestamps | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iirb(main):077:0> x=ActiveSupport::TimeWithZone.new(Time.now,Time.zone) | |
=> Wed, 22 Jun 2022 00:23:02.591031040 UTC +00:00 | |
irb(main):078:0> y=cp.last.to_time | |
=> 2022-06-21 19:30:00 +0000 | |
irb(main):079:0> x.class | |
=> ActiveSupport::TimeWithZone | |
irb(main):080:0> x | |
=> Wed, 22 Jun 2022 00:23:02.591031040 UTC +00:00 | |
irb(main):081:0> x=y | |
=> 2022-06-21 19:30:00 +0000 | |
irb(main):082:0> x | |
=> 2022-06-21 19:30:00 +0000 | |
irb(main):083:0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails c | |
Loading development environment (Rails 7.0.3) | |
irb(main):001:0> p ENV['TZ'] | |
"UTC" | |
=> "UTC" | |
irb(main):002:0> c=Cron.first! | |
(0.7ms) SELECT sqlite_version(*) | |
Cron Load (0.2ms) SELECT "crons".* FROM "crons" ORDER BY "crons"."id" ASC LIMIT ? [["LIMIT", 1]] | |
=> | |
#<Cron:0x00007f8bcbe68238 | |
... | |
irb(main):003:0> cp = CronParser.new(c.entry) | |
=> #<CronParser:0x00007f8bca6d0a08 @source="30 15,19,01 * * *", @time_source=Time> | |
irb(main):004:0> c.next_run=cp.last.to_time | |
=> 2022-06-21 19:30:00 +0000 | |
irb(main):005:0> c.next_run | |
=> Sat, 01 Jan 2000 19:30:00.000000000 UTC +00:00 | |
irb(main):006:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment