mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
* Use user timezone to show dates on maps * Limit timestamps to valid range to prevent database errors when users enter pre-epoch dates. * Limit timestamps to valid range to prevent database errors when users enter pre-epoch dates. * Fix tests failing due to new index on stats table * Fix failing specs
21 lines
502 B
Ruby
21 lines
502 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Timestamps
|
|
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)
|
|
rescue StandardError
|
|
result =
|
|
if timestamp.to_s.length > 10
|
|
timestamp.to_i / 1000
|
|
else
|
|
timestamp.to_i
|
|
end
|
|
|
|
result.clamp(min_timestamp, max_timestamp)
|
|
end
|
|
end
|