mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Limit timestamps to valid range to prevent database errors when users enter pre-epoch dates.
This commit is contained in:
parent
336c6667e6
commit
31edce0276
2 changed files with 6 additions and 6 deletions
|
|
@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
- Cities visited during a trip are now being calculated correctly. #547 #641
|
||||
- Points on the map are now show time in user's timezone. #580
|
||||
- Date range inputs now handle pre-epoch dates gracefully by clamping to valid PostgreSQL integer range (1970-2038), preventing database errors when users enter dates like year 1000.
|
||||
- Date range inputs now handle pre-epoch dates gracefully by clamping to valid PostgreSQL integer range. #685
|
||||
|
||||
|
||||
# [0.36.2] - 2025-12-06
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Timestamps
|
||||
MIN_TIMESTAMP = Time.zone.parse('1970-01-01').to_i
|
||||
MAX_TIMESTAMP = Time.zone.parse('2100-01-01').to_i
|
||||
|
||||
def self.parse_timestamp(timestamp)
|
||||
min_timestamp = Time.zone.parse('1970-01-01').to_i
|
||||
max_timestamp = Time.zone.parse('2100-01-01').to_i
|
||||
|
||||
parsed = DateTime.parse(timestamp).to_time.to_i
|
||||
|
||||
parsed.clamp(MIN_TIMESTAMP, MAX_TIMESTAMP)
|
||||
parsed.clamp(min_timestamp, max_timestamp)
|
||||
rescue StandardError
|
||||
result =
|
||||
if timestamp.to_s.length > 10
|
||||
|
|
@ -16,6 +16,6 @@ module Timestamps
|
|||
timestamp.to_i
|
||||
end
|
||||
|
||||
result.clamp(MIN_TIMESTAMP, MAX_TIMESTAMP)
|
||||
result.clamp(min_timestamp, max_timestamp)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue