From a55a144a263b716bef5a1c21ab712ed2309dbb17 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 4 Oct 2016 20:16:39 +0200 Subject: [PATCH] Use absolute times instead of durations (#236) --- codegen/src/main.rs | 46 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/codegen/src/main.rs b/codegen/src/main.rs index 927f0c67..4b32f31c 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -2,7 +2,7 @@ extern crate requests; extern crate getopts; extern crate chrono; -use chrono::Duration; +use chrono::{DateTime, UTC}; use std::fmt; fn main() { @@ -29,8 +29,6 @@ fn main() { } fn pr_list() -> String { - use chrono::{UTC, DateTime}; - const URL: &'static str = "https://api.github.com/search/issues?q=repo:phil-opp/blog_os+type:\ pr+is:merged+label:relnotes"; @@ -40,14 +38,11 @@ fn pr_list() -> String { let data = res.json().expect("Error parsing JSON"); for pr in data["items"].members().take(5) { - let now = UTC::now(); let merged_at = pr["closed_at"].as_str().unwrap().parse::>().unwrap(); - let ago = now - merged_at; - - let item = format!(r#"
  • {} {}"#, + let item = format!("
  • {} {}", pr["html_url"], pr["title"], - DateFmt(ago)); + DateFmt(merged_at)); ret.push_str(&item); } @@ -55,38 +50,13 @@ fn pr_list() -> String { ret } -struct DateFmt(Duration); +struct DateFmt(DateTime); impl fmt::Display for DateFmt { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, r#"