]> gitweb.factorcode.org Git - factor.git/commitdiff
hacker-news: add relative timestamp on posts.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 30 Jul 2015 15:46:44 +0000 (08:46 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 30 Jul 2015 15:46:44 +0000 (08:46 -0700)
extra/hacker-news/hacker-news.factor

index c22a77ba44ef42f07d9e5a8987689d5d6a3a1c01..091c5f9f8d9a8519de8d6302c30b439d5f974f00 100644 (file)
@@ -1,9 +1,11 @@
 ! Copyright (C) 2012 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs classes.tuple colors.constants
-colors.hex combinators concurrency.combinators formatting fry
-hashtables http.client io io.styles json json.reader kernel make
-math math.parser sequences splitting ui urls ;
+
+USING: accessors assocs calendar calendar.elapsed
+colors.constants colors.hex combinators concurrency.combinators
+formatting fry hashtables http.client io io.styles json.reader
+kernel make math math.parser sequences ui urls ;
+
 IN: hacker-news
 
 <PRIVATE
@@ -55,7 +57,12 @@ PRIVATE>
         [ post>url host>> " (" ")" surround write-text nl ]
         [ "score" of "    %d points" sprintf write-text ]
         [ dup "by" of [ " by " write-text [ "by" of ] [ post>user-url ] bi write-link ] [ drop ] if ]
-        ! [ dup postedAgo>> [ " " write-text postedAgo>> write-text ] [ drop ] if ]
+        [
+            "time" of [
+                " " write-text now timestamp>unix-time
+                swap - relative-time write-text
+            ] when*
+        ]
         [
             dup "decendants" of [
                 " | " write-text