lib/nanoc/helpers/blogging.rb in nanoc-4.0.2 vs lib/nanoc/helpers/blogging.rb in nanoc-4.1.0a1
- old
+ new
@@ -375,19 +375,27 @@
formatted_date = attribute_to_time(item[:created_at]).__nanoc_to_iso8601_date
'tag:' + hostname + ',' + formatted_date + ':' + base_dir + (item.path || item.identifier.to_s)
end
- # Converts the given attribute (which can be a string, a Time or a Date)
- # into a Time.
+ # Converts the given attribute (which can be a string, a Time, a Date or a
+ # DateTime) into a Time. When given a Date instance or a string, the
+ # argument is assumed to be in the local timezone.
#
- # @param [String, Time, Date] time Something that contains time
+ # @param [String, Time, Date, DateTime] time Something that contains time
# information but is not necessarily a Time instance yet
#
# @return [Time] The Time instance corresponding to the given input
- def attribute_to_time(time)
- time = Time.local(time.year, time.month, time.day) if time.is_a?(Date)
- time = Time.parse(time) if time.is_a?(String)
- time
+ def attribute_to_time(arg)
+ case arg
+ when DateTime
+ arg.to_time
+ when Date
+ Time.local(arg.year, arg.month, arg.day)
+ when String
+ Time.parse(arg)
+ else
+ arg
+ end
end
end
end