Pastie: Express the time as distance ago from now instead of absolute
authorBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 19:28:45 +0000 (15:28 -0400)
committerBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 19:28:45 +0000 (15:28 -0400)
pastie/templates/recent.inc
pastie/themes/screen.css

index d7c7f72..79a669b 100644 (file)
@@ -4,16 +4,26 @@ $uuid = Horde::applicationUrl('uuid');
 <div id="recentPastes">
 <h2>Recent Pastings</h2>
 <hr>
-<?php foreach ($recent as $r) {
-          if (empty($r['title'])) {
-              $r['title'] = _("[Untitled]");
-          }
+<?php
+$now = new DateTime;
+foreach ($recent as $r) {
+    if (empty($r['title'])) {
+      $r['title'] = _("[Untitled]");
+    }
+    $then = new DateTime('@' . $r['timestamp']->timestamp());
+    $ago = $now->diff($then, true);
+    $days = $ago->format("%a");
+    if ($days > 0) {
+        $ago = $ago->format("%a days %H:%i ago");
+    } else {
+        $ago = $ago->format("%H:%i min ago");
+    }
 ?>
     <div class="recentPaste">
         <span class="pasteTitle"><a href="<?php echo $uuid . '/' . $r['uuid']; ?>"><?php echo $r['title']; ?></a></span><br>
         <span class="pasteAuthor"><?php echo $r['owner']; ?></span> |
         <span class="pasteSyntax"><?php echo $r['syntax']; ?></span> |
-        <span class="pasteDate"><?php echo $r['timestamp']; ?></span>
+        <span class="pasteDate"><?php echo $ago; ?></span>
     </div>
     <hr>
 <?php } ?>
index 637b27c..154d5a3 100644 (file)
@@ -1,12 +1,12 @@
 /* Insert CSS definitions here. */
 #recentPastes {
     float: left;
-    width: 20%;
+    width: 18%;
     height: 100%;
     border: 1px solid #c00;
     padding: 2px;
     overflow: hidden;
-    margin: 50px 15px 10px 15px;
+    margin: 50px 10px 10px 10px;
 }
 
 .recentPaste {