chell
chell

Reputation: 7866

Assign date from one attribute to other causes invalid date error

I am assigning the date from one attribute in an object to another attribute in the same object.

I do this as a call back before I save the object

before_save :set_delivery, :on => :create

def set_delivery

self.deliver_on = self.birthday.change(:year => Time.now.year)

end

both are of type Date in sqlite3 database.

This works, as in it writes the new information to the database. However if I try the following in the console or in a test it fails

    @attr = {
             :bp_name       => "Example User",
             :birthday      => '1992-02-29',
             :template_id   => 1
              }

Board.create(@attr)

produces the following error:

ArgumentError: invalid date

anyone know why or how to fix this problem?

Upvotes: 0

Views: 157

Answers (1)

Arkan
Arkan

Reputation: 6236

This is because the date you're trying to change is bissextile.

That means that that the following date 2011-02-29 doesn't exist.

Thus you have the following exeption: ArgumentError: invalid date

Upvotes: 1

Related Questions