Use proper datetime type

This commit is contained in:
kageru 2020-06-21 01:00:29 +02:00
parent da8430092b
commit 6405c8fa33
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 82 additions and 4 deletions

76
Cargo.lock generated
View File

@ -1,5 +1,23 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "chrono"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
dependencies = [
"num-integer",
"num-traits",
"serde",
"time",
]
[[package]]
name = "envy"
version = "0.4.1"
@ -9,14 +27,40 @@ dependencies = [
"serde",
]
[[package]]
name = "libc"
version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
[[package]]
name = "mparsed"
version = "0.1.0"
dependencies = [
"chrono",
"envy",
"serde",
]
[[package]]
name = "num-integer"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro2"
version = "1.0.18"
@ -66,8 +110,40 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "winapi"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -8,5 +8,6 @@ edition = "2018"
serde = { version = "1.0", features = ["derive"] }
#itertools = "0.9"
envy = "0.4"
chrono = { version = "0.4", features = ["serde"] }
[lib]

View File

@ -64,6 +64,7 @@ pub fn deserialize_response<'a, I: Iterator<Item = &'a str>, T: de::DeserializeO
#[cfg(test)]
mod tests {
use super::*;
use chrono::DateTime;
#[test]
fn track_de_test() {
@ -85,7 +86,7 @@ OK";
t,
Track {
file: "American Pie.flac".to_string(),
last_modified: Some("2019-12-16T21:38:54Z".to_string()),
last_modified: Some(DateTime::parse_from_rfc3339("2019-12-16T21:38:54Z").unwrap()),
album: Some("American Pie".to_string()),
artist: Some("Don McLean".to_string()),
date: Some(1979),
@ -137,7 +138,7 @@ OK"#;
t,
Track {
file: "06 Symphonie No. 41 en ut majeur, K. 551 _Jupiter_ I. Allegro Vivace.flac".to_string(),
last_modified: Some("2018-11-11T09:01:54Z".to_string()),
last_modified: Some(DateTime::parse_from_rfc3339("2018-11-11T09:01:54Z").unwrap()),
album: Some("Symphonies n°40 & n°41".to_string()),
artist: Some("Wolfgang Amadeus Mozart".to_string()),
artist_sort: Some("Mozart, Wolfgang Amadeus".to_string()),

View File

@ -1,3 +1,4 @@
use chrono::prelude::*;
use helpers::*;
use serde::Deserialize;
use std::time::Duration;
@ -25,9 +26,8 @@ pub struct Track {
pub artist: Option<String>,
pub pos: u32,
pub id: u32,
// TODO: use proper time here
#[serde(rename = "last-modified")]
pub last_modified: Option<String>,
pub last_modified: Option<DateTime<FixedOffset>>,
#[serde(rename = "originaldate")]
pub original_date: Option<u16>,
// probably not needed. it’s just the duration but as an int