Time.new does not work as I would expect
- by Marius Pop
I am trying to generate some seed material.
seed_array.each do |seed|
Task.create(date: Date.new(2012,06,seed[1]), start_t: Time.new(2012,6,2,seed[2],seed[3]), end_t: Time.new(2012,6,2,seed[2] + 2,seed[3]), title: "#{seed[0]}")
end
Ultimately I will put random hours, minutes, seconds. The problem that I am facing is that instead of creating a time with the 2012-06-02 date it creates a time with a different date: 2000-01-01.
I tested Time.new(2012,6,2,2,20,45) in rails console and it works as expected. When I am trying to seed my database however some voodo magic happens and I don't get the date I want.
Any inputs are appreciated. Thank you!
Update1:
*
[1m[36m (0.0ms)[0m [1mbegin transaction[0m [1m[35mSQL
(0.5ms)[0m INSERT INTO "tasks" ("created_at", "date", "description",
"end_t", "group_id", "start_t", "title", "updated_at") VALUES (?, ?,
?, ?, ?, ?, ?, ?) [["created_at", Tue, 03 Jul 2012 02:15:34 UTC
+00:00], ["date", Thu, 07 Jun 2012], ["description", nil], ["end_t", 2012-06-02 10:02:00 -0400], ["group_id", nil], ["start_t", 2012-06-02
08:02:00 -0400], ["title", "99"], ["updated_at", Tue, 03 Jul 2012
02:15:34 UTC +00:00]] [1m[36m (2.3ms)[0m [1mcommit
transaction
*
This is a small sample of the log.
Update 2
Task id: 101, date: "2012-06-26", start_t: "2000-01-01 08:45:00", end_t: "2000-01-01 10:45:00", title: "1", description: nil, group_id: nil, created_at: "2012-07-03 02:15:33", updated_at: "2012-07-03 02:15:33"
This is what shows up in rails console.