mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Fix time shift when creating visits manually
This commit is contained in:
parent
194f8c3c45
commit
a7b92c10f5
4 changed files with 32 additions and 6 deletions
|
|
@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
- Fixed a bug with stats sharing settings being not filled. #1826
|
- Fixed a bug with stats sharing settings being not filled. #1826
|
||||||
- Fixed a bug where user could not be deleted due to counter cache on points. #1818
|
- Fixed a bug where user could not be deleted due to counter cache on points. #1818
|
||||||
- Introduce apt-get upgrade before installing new packages in the docker image to prevent vulnerabilities. #1793
|
- Introduce apt-get upgrade before installing new packages in the docker image to prevent vulnerabilities. #1793
|
||||||
|
- Fixed time shift when creating visits manually. #1679
|
||||||
|
|
||||||
# [0.33.0] - 2025-09-29
|
# [0.33.0] - 2025-09-29
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -71,16 +71,16 @@ module Visits
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_visit(place)
|
def create_visit(place)
|
||||||
started_at = DateTime.parse(params[:started_at])
|
started_at = Time.zone.parse(params[:started_at])
|
||||||
ended_at = DateTime.parse(params[:ended_at])
|
ended_at = Time.zone.parse(params[:ended_at])
|
||||||
duration_minutes = (ended_at - started_at) * 24 * 60
|
duration_minutes = ((ended_at - started_at) / 60).to_i
|
||||||
|
|
||||||
@visit = user.visits.create!(
|
@visit = user.visits.create!(
|
||||||
name: params[:name],
|
name: params[:name],
|
||||||
place: place,
|
place: place,
|
||||||
started_at: started_at,
|
started_at: started_at,
|
||||||
ended_at: ended_at,
|
ended_at: ended_at,
|
||||||
duration: duration_minutes.to_i,
|
duration: duration_minutes,
|
||||||
status: :confirmed
|
status: :confirmed
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,31 @@ RSpec.describe Visits::Create do
|
||||||
expect(service.visit.duration).to eq(36 * 60) # 36 hours in minutes
|
expect(service.visit.duration).to eq(36 * 60) # 36 hours in minutes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when datetime-local input is provided without timezone' do
|
||||||
|
let(:params) do
|
||||||
|
valid_params.merge(
|
||||||
|
started_at: '2023-12-01T19:54',
|
||||||
|
ended_at: '2023-12-01T20:54'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
subject(:service) { described_class.new(user, params) }
|
||||||
|
|
||||||
|
it 'parses the datetime in the application timezone' do
|
||||||
|
service.call
|
||||||
|
visit = service.visit
|
||||||
|
|
||||||
|
expect(visit.started_at.hour).to eq(19)
|
||||||
|
expect(visit.started_at.min).to eq(54)
|
||||||
|
expect(visit.ended_at.hour).to eq(20)
|
||||||
|
expect(visit.ended_at.min).to eq(54)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'calculates correct duration' do
|
||||||
|
service.call
|
||||||
|
expect(service.visit.duration).to eq(60) # 1 hour in minutes
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue