[feat]Properly add timezone to events starttime and endtime; set now to be the time in conference timezone instead of the user s time zone in fullcalendar

This commit is contained in:
Jimmy 2021-05-01 01:37:52 +08:00
parent 66767c33a2
commit bc115d6f90
No known key found for this signature in database
GPG key ID: FAE75C760A4A5CC6
6 changed files with 25 additions and 9 deletions

View file

@ -6,6 +6,7 @@ $( document ).ready(function() {
var calendar = new FullCalendar.Calendar(calendarEl, { var calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: fullcalData.data('schedulerLicenseKey'), schedulerLicenseKey: fullcalData.data('schedulerLicenseKey'),
nowIndicator: true, nowIndicator: true,
now: fullcalData.data('now'),
expandRows: true, expandRows: true,
allDaySlot: false, allDaySlot: false,
slotMinTime: fullcalData.data('startHour') + ':00:00', slotMinTime: fullcalData.data('startHour') + ':00:00',
@ -14,7 +15,7 @@ $( document ).ready(function() {
start: fullcalData.data('startDate'), start: fullcalData.data('startDate'),
end: fullcalData.data('endDate') end: fullcalData.data('endDate')
}, },
timeZone: 'UTC', // TODO: Events are stored in conference's timezone implicitly (UTC+0) in the database timeZone: fullcalData.data('timezone'),
initialDate: fullcalData.data('day'), initialDate: fullcalData.data('day'),
initialView: 'resourceTimeGridDay', initialView: 'resourceTimeGridDay',
resources: fullcalData.data('rooms'), resources: fullcalData.data('rooms'),

View file

@ -94,6 +94,7 @@ class SchedulesController < ApplicationController
@rooms = FullCalendarFormatter.rooms_to_resources(@conference.venue.rooms) if @conference.venue @rooms = FullCalendarFormatter.rooms_to_resources(@conference.venue.rooms) if @conference.venue
@event_schedules = FullCalendarFormatter.event_schedules_to_resources(event_schedules) @event_schedules = FullCalendarFormatter.event_schedules_to_resources(event_schedules)
@now = Time.now.in_time_zone(@conference.timezone).strftime('%FT%T%:z')
@scheduler_license_key = Rails.configuration.fullcalendar[:license_key] @scheduler_license_key = Rails.configuration.fullcalendar[:license_key]
end end

View file

@ -133,6 +133,14 @@ class EventSchedule < ApplicationRecord
other.schedule_id == schedule_id other.schedule_id == schedule_id
end end
def start_time_in_conference_timezone
time_in_conference_timezone(start_time)
end
def end_time_in_conference_timezone
time_in_conference_timezone(end_time)
end
private private
def replaced_event_schedules def replaced_event_schedules
@ -187,4 +195,10 @@ class EventSchedule < ApplicationRecord
errors.add(:schedule, "must be one of #{event.track.name} track's schedules") unless event.track.schedules.include?(schedule) errors.add(:schedule, "must be one of #{event.track.name} track's schedules") unless event.track.schedules.include?(schedule)
end end
def time_in_conference_timezone(time)
time_in_tz = time.in_time_zone(timezone)
time_in_tz -= time_in_tz.utc_offset
time_in_tz
end
end end

View file

@ -29,8 +29,8 @@ class FullCalendarFormatter
{ {
id: event_schedule.event.guid, id: event_schedule.event.guid,
title: event_schedule.event.title, title: event_schedule.event.title,
start: event_schedule.start_time, start: event_schedule.start_time_in_conference_timezone,
end: event_schedule.end_time, end: event_schedule.end_time_in_conference_timezone,
resourceId: event_schedule.room.guid, resourceId: event_schedule.room.guid,
url: url, url: url,
borderColor: event_type_color, borderColor: event_type_color,

View file

@ -8,6 +8,6 @@
#vert-schedule-full-calendar #vert-schedule-full-calendar
#fullcalendar{ data: { rooms: @rooms, events: @event_schedules, day: @day, #fullcalendar{ data: { rooms: @rooms, events: @event_schedules, day: @day,
'start-hour': @conference.start_hour, 'end-hour': @conference.end_hour, 'start-hour': @conference.start_hour, 'end-hour': @conference.end_hour,
'start-date': @conference.start_date, 'start-date': @conference.start_date, 'end-date': @conference.end_date + 1.day,
'end-date': @conference.end_date + 1.day, 'timezone': @conference.timezone, 'now': @now,
'scheduler-license-key': @scheduler_license_key } } 'scheduler-license-key': @scheduler_license_key } }

View file

@ -45,8 +45,8 @@ describe FullCalendarFormatter do
{ {
id: event_schedule1.event.guid, id: event_schedule1.event.guid,
title: event_schedule1.event.title, title: event_schedule1.event.title,
start: event_schedule1.start_time, start: event_schedule1.start_time_in_conference_timezone,
end: event_schedule1.end_time, end: event_schedule1.end_time_in_conference_timezone,
resourceId: room1.guid, resourceId: room1.guid,
url: Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event1.id), url: Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event1.id),
borderColor: event1.event_type.color, borderColor: event1.event_type.color,
@ -56,8 +56,8 @@ describe FullCalendarFormatter do
{ {
id: event_schedule2.event.guid, id: event_schedule2.event.guid,
title: event_schedule2.event.title, title: event_schedule2.event.title,
start: event_schedule2.start_time, start: event_schedule2.start_time_in_conference_timezone,
end: event_schedule2.end_time, end: event_schedule2.end_time_in_conference_timezone,
resourceId: room2.guid, resourceId: room2.guid,
url: Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event2.id), url: Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event2.id),
borderColor: event2.event_type.color, borderColor: event2.event_type.color,