Skip to content

Commit

Permalink
try not to brick itself during time zone changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Nov 2, 2024
1 parent 92021c8 commit f53101d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "amtrak-gtfs-rt"
version = "0.4.0"
version = "0.4.1"
license = "AGPL-3.0"
description = "Converts Amtrak Track-A-Train to valid GTFS-rt vehicle and trip information"
edition = "2021"
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,17 @@ fn tz_char_to_tz(tz: char) -> Option<chrono_tz::Tz> {

//for arrivals and departures, does not parse PM or AM.
fn time_and_tz_to_unix(timestamp_text: &String, tz: char) -> i64 {
println!("{}, {}",timestamp_text, tz);
//println!("{}, {}",timestamp_text, tz);
// tz: String like "P", "C", "M", or "E"
//time: "12/11/2023 17:36:00"
let naive_dt = NaiveDateTime::parse_from_str(timestamp_text, "%m/%d/%Y %H:%M:%S").unwrap();

let local_time_representation = tz_char_to_tz(tz)
.unwrap()
.from_local_datetime(&naive_dt)
.latest();
.latest().unwrap();

local_time_representation.latest()
local_time_representation.timestamp().try_into().unwrap()
}

//for origin departure conversion to local time representation
Expand All @@ -510,7 +510,7 @@ pub fn origin_departure(timestamp_text: &str, tz: char) -> chrono::DateTime<chro
tz_char_to_tz(tz)
.unwrap()
.from_local_datetime(&naive_dt)
.latest()
.latest().unwrap()
}

//time is formatted 11/18/2023 4:58:09 PM
Expand All @@ -519,7 +519,8 @@ pub fn process_timestamp_text(timestamp_text: &str) -> u64 {

let eastern_time = chrono_tz::America::New_York
.from_local_datetime(&naive_dt)
.latest();
.latest()
.unwrap();

eastern_time.timestamp().try_into().unwrap()
}
Expand Down

0 comments on commit f53101d

Please sign in to comment.