contentful / contentful_model

A lightweight wrapper around the Contentful api gem, to make it behave more like ActiveRecord
MIT License
44 stars 42 forks source link

to_s(:usec) time format not defined in Rails 4.2 #117

Closed shaug closed 6 years ago

shaug commented 6 years ago

https://github.com/contentful/contentful_model/blob/df8bd84b9fd0390797e79b4adf4137f0db445265/lib/contentful_model/base.rb#L24

The usec time format was introduced in Rails 5.

http://api.rubyonrails.org/v5.0/classes/Time.html

If 4.2 compatibility is desired, then this format will need to be defined as such:

Time::DATE_FORMATS[:usec] ||= '%Y%m%d%H%M%S%6N'

Likewise, if this library is intended to be Rails-agnostic, then it's probably preferred to use strftime:

TIME_FORMAT = '%Y%m%d%H%M%S%6N'.freeze
def cache_key(*timestamp_names)
  "#{self.class.to_s.underscore}/#{id}-#{updated_at.utc.strftime(TIME_FORMAT)}"
end
dlitvakb commented 6 years ago

Hey @shaug,

Thanks for this, I'll look into replacing the call with your suggestion.

Cheers

dlitvakb commented 6 years ago

This has just been released as 1.0.1.

Cheers