From 3fda2e49a07bc4920520a4e1cb04b0a8864ff6b4 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 29 Jun 2025 14:07:15 -0700 Subject: [PATCH] Change times to Time instances, not Unix timestamps --- lib/instapaper/bookmark.rb | 4 ++-- lib/instapaper/highlight.rb | 2 +- lib/instapaper/types.rb | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/instapaper/bookmark.rb b/lib/instapaper/bookmark.rb index 1e5c432..f9c07f6 100644 --- a/lib/instapaper/bookmark.rb +++ b/lib/instapaper/bookmark.rb @@ -13,8 +13,8 @@ module Instapaper attribute? :description, Types::String attribute? :instapaper_hash, Types::String attribute? :private_source, Types::String - attribute? :progress_timestamp, Types::Integer.optional - attribute? :time, Types::Integer.optional + attribute? :progress_timestamp, Types::UnixTime + attribute? :time, Types::UnixTime attribute? :progress, Types::StringOrInteger attribute? :starred, Types::StringOrInteger end diff --git a/lib/instapaper/highlight.rb b/lib/instapaper/highlight.rb index 2f82762..09bb1a9 100644 --- a/lib/instapaper/highlight.rb +++ b/lib/instapaper/highlight.rb @@ -11,6 +11,6 @@ module Instapaper attribute :bookmark_id, Types::Integer attribute :text, Types::String attribute :position, Types::Integer - attribute :time, Types::Integer.optional + attribute :time, Types::UnixTime end end diff --git a/lib/instapaper/types.rb b/lib/instapaper/types.rb index 2781b5c..ce65c4b 100644 --- a/lib/instapaper/types.rb +++ b/lib/instapaper/types.rb @@ -18,5 +18,17 @@ module Instapaper !!value end end + + # Converts Unix timestamps to Time objects + UnixTime = Types::Time.constructor do |value| + case value + when ::Time + value + when nil + nil + else + ::Time.at(value.to_i) + end + end end end