Skip to content

Commit

Permalink
frame-source: reduce string parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Mar 21, 2024
1 parent 2adee34 commit 94cfa75
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion media-utils/frame-source/src/ntp_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ fn chrono_to_ntp<TZ>(orig: chrono::DateTime<TZ>) -> Result<NtpTimestamp, std::nu
where
TZ: chrono::TimeZone,
{
let epoch: chrono::DateTime<chrono::Utc> = "1900-01-01 00:00:00Z".parse().unwrap();
let epoch_naive = chrono::NaiveDate::from_ymd_opt(1900, 1, 1)
.unwrap()
.and_hms_opt(0, 0, 0)
.unwrap();
let epoch = chrono::TimeZone::from_local_datetime(&chrono::Utc, &epoch_naive).unwrap();
let elapsed: chrono::TimeDelta = orig.to_utc() - epoch;
let sec_since_epoch: u32 = elapsed.num_seconds().try_into()?;
let nanos = elapsed.subsec_nanos();
Expand Down

0 comments on commit 94cfa75

Please sign in to comment.