1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

(bug) date shift in event creation/update

This commit is contained in:
Sylvain 2023-02-14 16:47:06 +01:00
parent 04f933f94d
commit eba0c99ae5
4 changed files with 58 additions and 3 deletions

View File

@ -3,6 +3,7 @@
- Use Time instead of DateTime objects - Use Time instead of DateTime objects
- Fix a bug: wrong times in admin/event monitoring - Fix a bug: wrong times in admin/event monitoring
- Fix a bug: daylight saving time is ignored and result in wrong dates and/or times when dealing around the DST day - Fix a bug: daylight saving time is ignored and result in wrong dates and/or times when dealing around the DST day
- Fix a bug: date shift in event creation/update
- Fix a bug: unable to run `rails db:seed` when first setup Fab-manager - Fix a bug: unable to run `rails db:seed` when first setup Fab-manager
## v5.6.11 2023 February 07 ## v5.6.11 2023 February 07

View File

@ -5,7 +5,7 @@ class Availabilities::CreateAvailabilitiesService
def create(availability, occurrences) def create(availability, occurrences)
occurrences = [] if occurrences.nil? occurrences = [] if occurrences.nil?
availability.update_attributes(occurrence_id: availability.id) availability.update(occurrence_id: availability.id)
create_slots(availability) create_slots(availability)
occurrences.each do |o| occurrences.each do |o|

View File

@ -33,8 +33,8 @@ class EventService
end end
def date_range(starting, ending, all_day) def date_range(starting, ending, all_day)
start_date = Date.parse(starting[:date]) start_date = Time.zone.parse(starting[:date])
end_date = Date.parse(ending[:date]) end_date = Time.zone.parse(ending[:date])
start_time = starting[:time] ? Time.zone.parse(starting[:time]) : nil start_time = starting[:time] ? Time.zone.parse(starting[:time]) : nil
end_time = ending[:time] ? Time.zone.parse(ending[:time]) : nil end_time = ending[:time] ? Time.zone.parse(ending[:time]) : nil
if all_day || start_time.nil? || end_time.nil? if all_day || start_time.nil? || end_time.nil?

View File

@ -0,0 +1,54 @@
# frozen_string_literal: true
require 'test_helper'
module Events; end
class Events::TimezoneTest < ActionDispatch::IntegrationTest
setup do
admin = User.with_role(:admin).first
login_as(admin, scope: :user)
end
test 'create an event from a negative timezone' do
# Create a new event
post '/api/events',
params: {
event: {
title: 'Street child skateboard',
description: '<p>Build your own skateboard for children to ride in the street</p>',
category_id: 2,
start_date: '2023-06-14T20:00:00.000-04:00',
end_date: '2023-06-14T20:00:00.000-04:00',
start_time: '09:48',
end_time: '11:48',
recurrence: 'none',
recurrence_end_at: '',
nb_total_places: 'NaN',
amount: '35',
advanced_accounting_attributes: {
code: '',
analytical_section: ''
},
event_image_attributes: {
attachment: fixture_file_upload('/files/event/Skateboard.jpg')
}
}
}.to_json,
headers: default_headers
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the event was created correctly
event = json_response(response.body)
e = Event.find_by(id: event[:id])
assert_not_nil e, 'Event was not created in database'
assert_equal '2023-06-15', e.availability.start_at.to_date.iso8601
assert_equal '2023-06-15', e.availability.end_at.to_date.iso8601
assert_equal '09:48', e.availability.start_at.strftime('%R')
assert_equal '11:48', e.availability.end_at.strftime('%R')
end
end