From 19ca5286352a6b28e09de402824ceb5a8718a513 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 11 Aug 2019 21:52:54 +0200 Subject: [PATCH] Follow up for issue #2697 - Time zone incorrectly calculated in ticket list. --- app/controllers/time_accountings_controller.rb | 5 +++-- spec/requests/time_accounting_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/time_accountings_controller.rb b/app/controllers/time_accountings_controller.rb index 2d0102f52..0860b0edd 100644 --- a/app/controllers/time_accountings_controller.rb +++ b/app/controllers/time_accountings_controller.rb @@ -466,8 +466,9 @@ class TimeAccountingsController < ApplicationController if timezone.present? offset = time.in_time_zone(timezone).utc_offset - time -= offset + time += offset end - time.utc.iso8601.to_s.sub(/Z$/, '') + local_time = time.utc.iso8601.to_s.sub(/Z$/, '') + local_time.sub(/T/, ' ') end end diff --git a/spec/requests/time_accounting_spec.rb b/spec/requests/time_accounting_spec.rb index 74cde3809..87d69297a 100644 --- a/spec/requests/time_accounting_spec.rb +++ b/spec/requests/time_accounting_spec.rb @@ -61,5 +61,9 @@ RSpec.describe 'Time Accounting API endpoints', type: :request do expect(response['Content-Type']).to eq('application/vnd.ms-excel') end end + + it 'does convert UTC timestamp to local system based timestamp' do + expect(TimeAccountingsController.new.instance_eval { time_in_localtime_for_excel(Time.parse('2019-08-08T01:00:05Z').in_time_zone, 'Europe/Berlin') }).to eq('2019-08-08 03:00:05') + end end end