sxross / MotionModel

Simple Model and Validation Mixins for RubyMotion
MIT License
192 stars 67 forks source link

Is it possible to capture created_at timestamp vs just date? #87

Closed dchersey closed 10 years ago

dchersey commented 10 years ago

The documentation states that the created_at & updated_at fields must be of type date. As such, it only captures the day of the create or update. This is odd, as usually you want to use this more precisely.

I also don't see a separate type for time or datetime ... so I guess I can just store time as an integer using Time.to_i .... am I missing something?

sxross commented 10 years ago

If you look at model.rb, you'll see this code:

    # Set created_at and updated_at fields
    def set_auto_date_field(field_name)
      method = "#{field_name}="
      self.send(method, Time.now) if self.respond_to?(method)
    end

This relies on you having a field named created_at or updated_at. If you create them as type :date you may not be getting the time component. Otherwise, I don't see how you are losing that. Can you create a failing spec?

dchersey commented 10 years ago

Never mind … I just realized that my brain was conflating ruby (with separate Date, Time and DateTime classes) and rubymotion (with only NSDate which combines all 3).
That's what I get for working on 2 projects at once :)

This issue first surfaced when I was using formotion to show the created_at and it defaults to only showing/picking Date. I then looked at the model declaration, saw type :date and proceeded to assume that's all I had.

Thanks for your quick response!

On Oct 16, 2013, at 12:52 PM, "s.ross" notifications@github.com wrote:

If you look at model.rb, you'll see this code:

# Set created_at and updated_at fields
def set_auto_date_field(field_name)
  method = "#{field_name}="
  self.send(method, Time.now) if self.respond_to?(method)
end

This relies on you having a field named created_at or updated_at. If you create them as type :date you may not be getting the time component. Otherwise, I don't see how you are losing that. Can you create a failing spec?

— Reply to this email directly or view it on GitHub.

sxross commented 10 years ago

No problem. Enjoy using MM!