Skip to content

Instantly share code, notes, and snippets.


peschkaj/ Secret

Last active Apr 6, 2018
What would you like to do?
extern crate time;
use time::{Timespec, Tm};
pub struct Todo {
pub title: String,
pub description: String,
created_at_s: i64,
completed_at_s: Option<i64>
impl Todo {
pub fn new(title: String, description: String) -> Todo {
Todo { title: title,
description: description,
created_at_s: time::now_utc().to_timespec().sec,
completed_at_s: None }
fn created_at(&self) -> Tm {
time::at(Timespec::new(self.created_at_s, 0))
fn completed_at(&self) -> Option<Tm> {|t| time::at(Timespec::new(t,0)))
pub fn is_done(&self) -> bool {
fn main() {
let t = Todo::new("hooray".to_string(), "do stuff".to_string());
println!("Title: {}", t.title);
println!("Description: {}", t.description);
println!("Created at: {}", t.created_at_s);
println!("Created at (pretty): {}", t.created_at().rfc822());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment