From 2effe63f4da696cedbb6c0731d0c0e4d25f4225a Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Thu, 15 Feb 2018 21:01:38 +0900 Subject: [PATCH] Remove `chrono` for supporting `wasm32-unknown-unknown` compilation target --- Cargo.toml | 1 - src/lib.rs | 1 - src/media_segment.rs | 4 ++-- src/tags/media_segment.rs | 45 ++++++++++++--------------------------- 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4779db..4028bdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ travis-ci = {repository = "sile/hls_m3u8"} codecov = {repository = "sile/hls_m3u8"} [dependencies] -chrono = "0.4" trackable = "0.2" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 8b420bd..6ddc7a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,6 @@ //! ``` #![warn(missing_docs)] #![cfg_attr(feature = "cargo-clippy", allow(const_static_lifetime))] -extern crate chrono; #[macro_use] extern crate trackable; diff --git a/src/media_segment.rs b/src/media_segment.rs index 43063e0..9666b8c 100644 --- a/src/media_segment.rs +++ b/src/media_segment.rs @@ -139,8 +139,8 @@ impl MediaSegment { } /// Returns the `EXT-X-PROGRAM-DATE-TIME` tag associated with the media segment. - pub fn program_date_time_tag(&self) -> Option { - self.program_date_time_tag + pub fn program_date_time_tag(&self) -> Option<&ExtXProgramDateTime> { + self.program_date_time_tag.as_ref() } /// Returns the `EXT-X-MAP` tag associated with the media segment. diff --git a/src/tags/media_segment.rs b/src/tags/media_segment.rs index f76ae13..fe30e94 100644 --- a/src/tags/media_segment.rs +++ b/src/tags/media_segment.rs @@ -2,7 +2,6 @@ use std::collections::BTreeMap; use std::fmt; use std::str::FromStr; use std::time::Duration; -use chrono::{DateTime, FixedOffset, NaiveDate}; use trackable::error::ErrorKindExt; use {Error, ErrorKind, Result}; @@ -298,21 +297,21 @@ impl FromStr for ExtXMap { /// [4.3.2.6. EXT-X-PROGRAM-DATE-TIME] /// /// [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]: https://tools.ietf.org/html/rfc8216#section-4.3.2.6 -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExtXProgramDateTime { - date_time: DateTime, + date_time: SingleLineString, } impl ExtXProgramDateTime { pub(crate) const PREFIX: &'static str = "#EXT-X-PROGRAM-DATE-TIME:"; /// Makes a new `ExtXProgramDateTime` tag. - pub fn new(date_time: DateTime) -> Self { + pub fn new(date_time: SingleLineString) -> Self { ExtXProgramDateTime { date_time } } - /// Returns the `DateTime` of the first sample of the associated media segment. - pub fn date_time(&self) -> DateTime { - self.date_time + /// Returns the date-time of the first sample of the associated media segment. + pub fn date_time(&self) -> &SingleLineString { + &self.date_time } /// Returns the protocol compatibility version that this tag requires. @@ -322,7 +321,7 @@ impl ExtXProgramDateTime { } impl fmt::Display for ExtXProgramDateTime { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}", Self::PREFIX, self.date_time.to_rfc3339()) + write!(f, "{}{}", Self::PREFIX, self.date_time) } } impl FromStr for ExtXProgramDateTime { @@ -331,7 +330,7 @@ impl FromStr for ExtXProgramDateTime { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let suffix = s.split_at(Self::PREFIX.len()).1; Ok(ExtXProgramDateTime { - date_time: track!(suffix.parse().map_err(|e| ErrorKind::InvalidInput.cause(e)))?, + date_time: track!(SingleLineString::new(suffix))?, }) } } @@ -346,8 +345,8 @@ impl FromStr for ExtXProgramDateTime { pub struct ExtXDateRange { pub id: QuotedString, pub class: Option, - pub start_date: NaiveDate, - pub end_date: Option, + pub start_date: QuotedString, + pub end_date: Option, pub duration: Option, pub planned_duration: Option, pub scte35_cmd: Option, @@ -371,13 +370,9 @@ impl fmt::Display for ExtXDateRange { if let Some(ref x) = self.class { write!(f, ",CLASS={}", x)?; } - write!( - f, - ",START-DATE={:?}", - self.start_date.format("%Y-%m-%d").to_string() - )?; + write!(f, ",START-DATE={}", self.start_date)?; if let Some(ref x) = self.end_date { - write!(f, ",END-DATE={:?}", x.format("%Y-%m-%d").to_string())?; + write!(f, ",END-DATE={}", x)?; } if let Some(x) = self.duration { write!(f, ",DURATION={}", DecimalFloatingPoint::from_duration(x))?; @@ -429,20 +424,8 @@ impl FromStr for ExtXDateRange { match key { "ID" => id = Some(track!(value.parse())?), "CLASS" => class = Some(track!(value.parse())?), - "START-DATE" => { - let s: QuotedString = track!(value.parse())?; - start_date = Some(track!( - NaiveDate::parse_from_str(&s, "%Y-%m-%d") - .map_err(|e| ErrorKind::InvalidInput.cause(e)) - )?); - } - "END-DATE" => { - let s: QuotedString = track!(value.parse())?; - end_date = Some(track!( - NaiveDate::parse_from_str(&s, "%Y-%m-%d") - .map_err(|e| ErrorKind::InvalidInput.cause(e)) - )?); - } + "START-DATE" => start_date = Some(track!(value.parse())?), + "END-DATE" => end_date = Some(track!(value.parse())?), "DURATION" => { let seconds: DecimalFloatingPoint = track!(value.parse())?; duration = Some(seconds.to_duration());