Add time published to Reddit comments

This commit is contained in:
Omar Roth 2018-08-13 10:30:27 -05:00
parent c776e1f82a
commit f3fde38137

View File

@ -6,12 +6,26 @@ class RedditThing
end end
class RedditComment class RedditComment
module TimeConverter
def self.from_json(value : JSON::PullParser) : Time
Time.epoch(value.read_float.to_i)
end
def self.to_json(value : Time, json : JSON::Builder)
json.number(value.epoch)
end
end
JSON.mapping({ JSON.mapping({
author: String, author: String,
body_html: String, body_html: String,
replies: RedditThing | String, replies: RedditThing | String,
score: Int32, score: Int32,
depth: Int32, depth: Int32,
created: {
type: Time,
converter: RedditComment::TimeConverter,
},
}) })
end end
@ -144,6 +158,7 @@ def template_reddit_comments(root)
<a href="javascript:void(0)" onclick="toggle(this)">[ - ]</a> <a href="javascript:void(0)" onclick="toggle(this)">[ - ]</a>
<i class="icon ion-ios-thumbs-up"></i> #{score} <i class="icon ion-ios-thumbs-up"></i> #{score}
<b><a href="https://www.reddit.com/user/#{author}">#{author}</a></b> <b><a href="https://www.reddit.com/user/#{author}">#{author}</a></b>
- #{recode_date(child.created)} ago
</p> </p>
<div> <div>
#{body_html} #{body_html}