einzige/date_time_attribute

Is there a way to reset the attributes?

Closed this issue · 4 comments

It looks like there is no way to reset the attribute. For example:

task.due_at_date = '2001-02-03'
task.due_at_time = '10:00pm'
task.due_at                      # => 2001-02-03 22:00:00 +0700

Now I want to set due_at to nil, but setting due_at_date and due_at_time to nil doesn't work.

I tried to work around that by manually setting due_at to nil before every assignment, but when setting due_at_date to nil, the original date is restored!

task.due_at_date = '2001-02-03'
task.due_at_time = '10:00pm'
task.due_at                      # => 2001-02-03 22:00:00 +0700
task.due_at = nil
task.due_at                      # => nil
task.due_at_date = nil
task.due_at                      # => 2001-02-03 22:00:00 +0700

Is there any official way to properly reset a datetime attribute?

Hey Daniel, good catch. Will fix that.

@daniel-rikowski As a quick workaround you can reset all attributes:

task.due_at_date = nil
task.due_at_time = nil
task.due_at = nil

general due_at field should be set to nil after due_at_date and due_at_time

bundled 0.0.5

Thank you very much, it works now, at least with plain Ruby attributes. Unfortunately Rails attributes don't work anymore, see #2.