Skip to content

Commit

Permalink
Merge pull request #3 from siketyan/format-datetime
Browse files Browse the repository at this point in the history
♻ Format datetime
  • Loading branch information
siketyan authored Dec 18, 2020
2 parents e508da1 + e1dd34a commit 733b939
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod api;
mod client;
mod video;

use chrono::Local;
use std::env::args;
use std::error::Error;

Expand All @@ -25,7 +26,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
response_to_videos(response).expect("Failed to determine videos from the response.");

for video in videos {
println!("{}: {} ({})", video.id, video.title, video.scheduled_at);
println!(
"{}: {} ({})",
video.id,
video.title,
video.scheduled_at.with_timezone(&Local)
);
}

Ok(())
Expand Down
6 changes: 4 additions & 2 deletions src/video.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use chrono::{DateTime, Utc, TimeZone};

pub struct Video {
pub id: String,
pub title: String,
pub scheduled_at: u64,
pub scheduled_at: DateTime<Utc>,
}

impl Video {
pub(crate) fn new(id: &str, title: &str, scheduled_at: u64) -> Self {
Self {
id: String::from(id),
title: String::from(title),
scheduled_at,
scheduled_at: Utc.timestamp(scheduled_at as i64, 0),
}
}
}

0 comments on commit 733b939

Please sign in to comment.