Skip to content

Commit

Permalink
Fix parse_xs_duration parsing of seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
emarsden committed Jun 25, 2024
1 parent 5213c1f commit 9a71332
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ where
// Limitations: we can't represent negative durations (leading "-" character) due to the choice of a
// std::time::Duration. We only accept fractional parts of seconds, and reject for example "P0.5Y" and "PT2.3H".
fn parse_xs_duration(s: &str) -> Result<Duration, DashMpdError> {
use std::cmp::min;

match XS_DURATION_REGEX.captures(s) {
Some(m) => {
if m.name("hastime").is_none() &&
Expand All @@ -209,7 +211,8 @@ fn parse_xs_duration(s: &str) -> Result<Duration, DashMpdError> {
let mut nsecs: u32 = 0;
if let Some(nano) = m.name("nanoseconds") {
// We drop the initial "." and limit precision
if let Some(ss) = &nano.as_str().get(1..9) {
let lim = min(nano.as_str().len(), 9);
if let Some(ss) = &nano.as_str().get(1..lim) {
let padded = format!("{ss:0<9}");
nsecs = padded.parse::<u32>()
.map_err(|_| DashMpdError::InvalidDuration(String::from(s)))?;
Expand Down

2 comments on commit 9a71332

@sbuzzard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with this change I noticed that, for example, comes out now as 1379394956.61698913s That is the 9th decimal place is removed - is that the intent @emarsden?

@emarsden
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foiled by the dot! Thanks for noting, now fixed in HEAD.

Please sign in to comment.