datamapper / dm-types

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

EpochFloatTime #3

Open SJD opened 13 years ago

SJD commented 13 years ago

It would be nice to have a more precise EpochTime type. I'm a Ruby newbie, but this seems to work for me;

class EpochFloatTime < Float

        def load(value)
            case value
                when ::Float, ::Integer
                    ::Time.at(value)
                else value
            end
        end

        def dump(value)
            case value
                when ::Float, ::Integer, ::Time then value.to_f
                when ::DateTime then value.to_time.to_f
            end
        end
    end
tpitale commented 8 years ago

Could you send a PR, and we can review that. Thanks @SJD!