mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
18 lines
407 B
Ruby
18 lines
407 B
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
module SafeTimestampParser
|
||
|
|
extend ActiveSupport::Concern
|
||
|
|
|
||
|
|
private
|
||
|
|
|
||
|
|
def safe_timestamp(date_string)
|
||
|
|
parsed_time = Time.zone.parse(date_string)
|
||
|
|
min_timestamp = Time.zone.parse('1970-01-01').to_i
|
||
|
|
max_timestamp = Time.zone.parse('2100-01-01').to_i
|
||
|
|
|
||
|
|
parsed_time.to_i.clamp(min_timestamp, max_timestamp)
|
||
|
|
rescue ArgumentError
|
||
|
|
Time.zone.now.to_i
|
||
|
|
end
|
||
|
|
end
|