Skip to content

Commit

Permalink
Reimplement DateTime#to_time since we do not always have activesuppor…
Browse files Browse the repository at this point in the history
…t around
  • Loading branch information
Rich Meyers committed Mar 14, 2012
1 parent d4549fb commit 1860ce6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/integrity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ def self.app

Integrity::App
end

# DateTime#to_time copied from activesupport
def self.datetime_to_time(datetime)
if datetime.offset == 0
::Time.utc(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec)
else
raise ArgumentError, "Datetime with an offset (#{datetime.offset}) cannot be converted to Time"
end
end
end
3 changes: 2 additions & 1 deletion lib/integrity/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def human_status

def human_duration
return if pending? || building?
ChronicDuration.output((completed_at.to_time.to_i - started_at.to_time.to_i), :format => :micro)
delta = Integrity.datetime_to_time(completed_at).to_i - Integrity.datetime_to_time(started_at).to_i
ChronicDuration.output(delta, :format => :micro)
end

end
Expand Down

0 comments on commit 1860ce6

Please sign in to comment.