datamapper / dm-types

DataMapper plugin providing extra data types
http://datamapper.org/
MIT License
55 stars 80 forks source link

Make EpochTime considerably less broken ;) #40

Closed d11wtq closed 13 years ago

d11wtq commented 13 years ago

Ok, this one is what you want. I've made sure there's solid test coverage on this, but a review would be appreciated, if you can see any edge cases.

The current EpochTime is completely broken, as demonstrated in the comments of my previous pull request. Let me know if you have any questions.

What this fixes:

  1. #typecast correctly converts to a Time, just like #load does when the object is fresh.
  2. Correctly accepts strings just like DateTime/Time, and cast them to real Time objects.
  3. Correctly accepts integers as input (UNIX time), unlike DateTime/Time, due to the fact that's what it models.
  4. Like Integer, accepts a numeric string as input, and assumes it's a UNIX timestamp.
dkubb commented 13 years ago

@solnic can you review/comment on this?

solnic commented 13 years ago

@dkubb @d11wtq this looks good although it does make me sad we need to do such workarounds. I'm gonna merge it in now since I can't tell you at this very moment when I will have time to finish Property API with dump_as/load_as settings.

It's better to have this fix now anyway, thanks for the patch!