Getting the actual start time of the game.

This commit is contained in:
calcu1on
2025-04-05 21:14:52 -04:00
parent 3bbf63132e
commit b07c4abd88
4 changed files with 252 additions and 21 deletions

View File

@@ -43,8 +43,13 @@ fn main() {
// Check if there is a sox game and print opp.
for sox_game in &sox_games {
if sox_game.date == yyyy_mm_dd {
// @todo - currently hardcoding time - figure out how to get it.
sox_status = format!("{} {}\n{} {}", baseball_icon, &sox_game.opponent, clock_icon, "8:00".to_string());
sox_status = format!(
"{} {}\n{} {}",
&baseball_icon,
&sox_game.opponent,
&clock_icon,
&sox_game.start_time,
);
break;
}
}

View File

@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use serde_alias::serde_alias;
// use iso8601;
use chrono::{DateTime, Utc};
use chrono_tz::US::Eastern;
const TEAM_ID: i32 = 111;
@@ -24,7 +25,7 @@ pub struct Game {
pub teams: Teams,
// pub date: String,
pub official_date: String,
// pub start_time: String,
pub game_date: String,
// pub opponent: String,
}
@@ -59,7 +60,7 @@ pub struct TeamRecord {
pub struct GameInfo {
pub opponent: String,
pub date: String,
// pub time: String,
pub start_time: String,
}
// Gets the full forecast from the response.
@@ -76,6 +77,7 @@ pub fn get_schedule() -> Vec<GameInfo> {
let game_info = GameInfo {
opponent: facing,
date: game.official_date,
start_time: get_start_time(&game.game_date),
};
full_schedule.push(game_info);
}
@@ -100,6 +102,12 @@ fn build_api_url() -> String {
format!("{}{}{}", url_first, TEAM_ID, url_second)
}
fn get_start_time(iso_string: &String) -> String {
let utc_dt: DateTime<Utc> = iso_string.parse().expect("Invalid ISO8601 string");
let est_dt = utc_dt.with_timezone(&Eastern);
est_dt.format("%I:%M").to_string()
}
#[cfg(test)]
mod team_tests {
use super::*;