Skip to content

Commit

Permalink
fix: fixed the wrong time zone when checking if the input is already …
Browse files Browse the repository at this point in the history
…released

* previously it was UTC-4, changed to UTC-5 as stated in the FAQ of AoC:
https://adventofcode.com/2022/about

Closes #13
  • Loading branch information
kpagacz committed Dec 23, 2022
1 parent 427212a commit ef6cc9c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[package]
name = "elv"
description = "A little CLI helper for Advent of Code. 🎄"
version = "0.9.0"
version = "0.9.1"
edition = "2021"
readme = "README.md"
license-file = "LICENSE"
Expand Down
14 changes: 7 additions & 7 deletions src/aoc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ impl AocApi {
};
let mut response = match self.http_client.get(url).send() {
Ok(response) => response,
Err(_) => return Self::failed_input_request_response(),
Err(_) => return InputResponse::failed(),
};
if response.status() != StatusCode::OK {
return Self::failed_input_request_response();
return InputResponse::failed();
}
let mut body = String::new();
if response.read_to_string(&mut body).is_err() {
return Self::failed_input_request_response();
return InputResponse::failed();
}
if body.starts_with("Please don't repeatedly request this") {
return InputResponse::new(
Expand Down Expand Up @@ -208,10 +208,6 @@ impl AocApi {
);
Ok(answer_text)
}

fn failed_input_request_response() -> InputResponse {
InputResponse::new("Failed to get input".to_string(), ResponseStatus::Error)
}
}

#[derive(Debug, PartialEq, Eq)]
Expand All @@ -231,6 +227,10 @@ impl InputResponse {
pub fn new(body: String, status: ResponseStatus) -> Self {
Self { body, status }
}

pub fn failed() -> Self {
Self::new("Failed to get input".to_string(), ResponseStatus::Error)
}
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Driver {

match InputCache::load(year, day) {
Ok(input) => return Ok(input),
Err(e) => println!("Failed loading the input from the cache, cause: {}", e),
Err(e) => println!("Failed loading the input from the cache. Cause:\n {}", e),
};

let aoc_api = AocApi::new(&self.configuration);
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Driver {
day: u8,
now: &chrono::DateTime<chrono::Utc>,
) -> Result<bool> {
let input_release_time = match chrono::FixedOffset::west_opt(60 * 60 * 4)
let input_release_time = match chrono::FixedOffset::west_opt(60 * 60 * 5)
.unwrap()
.with_ymd_and_hms(year as i32, 12, day as u32, 0, 0, 0)
.single()
Expand Down Expand Up @@ -178,7 +178,7 @@ mod tests {
#[test]
fn test_is_input_released_yet() {
let driver = Driver::default();
let now = chrono::Utc.with_ymd_and_hms(2022, 12, 1, 4, 0, 0).unwrap();
let now = chrono::Utc.with_ymd_and_hms(2022, 12, 1, 5, 0, 0).unwrap();
for (year, day, expected) in &[
(2019, 1, true),
(2020, 1, true),
Expand Down

0 comments on commit ef6cc9c

Please sign in to comment.