mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
19 lines
478 B
Ruby
19 lines
478 B
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
module Timestamps
|
||
|
|
def self.parse_timestamp(timestamp)
|
||
|
|
begin
|
||
|
|
# if the timestamp is in ISO 8601 format, try to parse it
|
||
|
|
DateTime.parse(timestamp).to_time.to_i
|
||
|
|
rescue
|
||
|
|
if timestamp.to_s.length > 10
|
||
|
|
# If the timestamp is in milliseconds, convert to seconds
|
||
|
|
timestamp.to_i / 1000
|
||
|
|
else
|
||
|
|
# If the timestamp is in seconds, return it without change
|
||
|
|
timestamp.to_i
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|