Skip to content

Commit

Permalink
Merge pull request #394 from airbrake/perf-stats-timezone
Browse files Browse the repository at this point in the history
Maintain UTC offset when truncating
  • Loading branch information
kyrylo authored Feb 5, 2019
2 parents 27e49f6 + 2a1e8ab commit 4efbaee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/airbrake-ruby/time_truncate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ module TimeTruncate
# @param [Time] time
# @return [String]
def self.utc_truncate_minutes(time)
time_array = time.to_a
time_array[0] = 0
tm = Time.utc(*time_array)
tm = time.getutc

Time.new(
tm.year, tm.month, tm.day, tm.hour, tm.min, 0, tm.utc_offset || 0
).to_datetime.rfc3339
Time.utc(tm.year, tm.month, tm.day, tm.hour, tm.min).to_datetime.rfc3339
end
end
end
5 changes: 5 additions & 0 deletions spec/time_truncate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
time = Time.new(2018, 1, 1, 0, 0, 20, 0)
expect(subject.utc_truncate_minutes(time)).to eq('2018-01-01T00:00:00+00:00')
end

it "converts time with zone to UTC" do
time = Time.new(2018, 1, 1, 0, 0, 20, '-05:00')
expect(subject.utc_truncate_minutes(time)).to eq('2018-01-01T05:00:00+00:00')
end
end
end

0 comments on commit 4efbaee

Please sign in to comment.