[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 committed by CactusPuppy
parent 03b12eafb0
commit 6777ffb0bb
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
6 changed files with 25 additions and 9 deletions

View file

@ -6,6 +6,7 @@ $( document ).ready(function() {
var calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: fullcalData.data('schedulerLicenseKey'),
nowIndicator: true,
now: fullcalData.data('now'),
expandRows: true,
allDaySlot: false,
slotMinTime: fullcalData.data('startHour') + ':00:00',
@ -14,7 +15,7 @@ $( document ).ready(function() {
start: fullcalData.data('startDate'),
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'),
initialView: 'resourceTimeGridDay',
resources: fullcalData.data('rooms'),

View file

@ -94,6 +94,7 @@ class SchedulesController < ApplicationController
@rooms = FullCalendarFormatter.rooms_to_resources(@conference.venue.rooms) if @conference.venue
@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]
end

View file

@ -133,6 +133,14 @@ class EventSchedule < ApplicationRecord
other.schedule_id == schedule_id
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
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)
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

View file

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

View file

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