Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct time zone of API dates #3090

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/serializers/event_schedule_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class EventScheduleSerializer < ActiveModel::Serializer
attributes :date, :room

def date
t = object.start_time
t.blank? ? '' : %( #{I18n.l t, format: :short}#{t.formatted_offset(false)} )
object.start_time&.change(zone: object.event.program.conference.timezone)
end

def room
Expand Down
3 changes: 1 addition & 2 deletions app/serializers/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class EventSerializer < ActiveModel::Serializer
attributes :guid, :title, :length, :scheduled_date, :language, :abstract, :speaker_ids, :type, :room, :track

def scheduled_date
t = object.time
t.blank? ? '' : %( #{I18n.l t, format: :short}#{t.formatted_offset(false)} )
object.time&.change(zone: object.program.conference.timezone)
end

def speaker_ids
Expand Down
26 changes: 26 additions & 0 deletions spec/serializers/event_schedule_serializer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'spec_helper'

describe EventScheduleSerializer, type: :serializer do
let(:start) { DateTime.new(2000, 1, 2, 3, 4, 5) }
let(:timezone) { 'Etc/GMT+11' }
let(:conference) do
create(:conference, start_date: start.to_date,
start_hour: start.hour,
timezone: timezone)
end
let(:program) { create(:program, conference: conference) }
let(:event) { create(:event, program: program) }
let(:event_schedule) { create(:event_schedule, event: event, start_time: start) }
let(:serializer) { described_class.new(event_schedule) }

it 'sets date and room' do
expected_json = {
date: '2000-01-02T03:04:05.000-11:00',
room: event_schedule.room.guid
}.to_json

expect(serializer.to_json).to eq expected_json
end
end
12 changes: 9 additions & 3 deletions spec/serializers/event_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

require 'spec_helper'
describe EventSerializer, type: :serializer do
let(:event) { create(:event, title: 'Some Talk', abstract: 'Lorem ipsum dolor sit amet') }
let(:conference) { create(:conference, timezone: 'UTC') }
let(:program) { create(:program, conference: conference) }
let(:event) do
create(:event, program: program,
title: 'Some Talk',
abstract: 'Lorem ipsum dolor sit amet')
end
let(:serializer) { EventSerializer.new(event) }

context 'event does not have date, room and tracks assigned' do
Expand All @@ -11,7 +17,7 @@
guid: event.guid,
title: 'Some Talk',
length: 30,
scheduled_date: '',
scheduled_date: nil,
language: nil,
abstract: 'Lorem ipsum dolor sit amet',
speaker_ids: event.speaker_ids,
Expand Down Expand Up @@ -41,7 +47,7 @@
guid: event.guid,
title: 'Some Talk',
length: 30,
scheduled_date: ' 2014-03-04T09:00:00+0000 ',
scheduled_date: '2014-03-04T09:00:00.000Z',
language: 'English',
abstract: 'Lorem ipsum dolor sit amet',
speaker_ids: [speaker.id],
Expand Down