From 57fccd01d487284bb317fb1ff778e0fd2e140c12 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 23 Oct 2023 18:51:17 +0200 Subject: release date from infojson and sorting --- import/src/infojson.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'import/src/infojson.rs') diff --git a/import/src/infojson.rs b/import/src/infojson.rs index ca02551..dd2151b 100644 --- a/import/src/infojson.rs +++ b/import/src/infojson.rs @@ -4,6 +4,8 @@ Copyright (C) 2023 metamuffin */ +use anyhow::Context; +use jellycommon::chrono::{format::Parsed, DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -120,3 +122,22 @@ pub struct YHeatmapSample { pub end_time: f64, pub value: f64, } + +pub fn parse_upload_date(d: &str) -> anyhow::Result> { + let (year, month, day) = (&d[0..4], &d[4..6], &d[6..8]); + let (year, month, day) = ( + year.parse().context("parsing year")?, + month.parse().context("parsing month")?, + day.parse().context("parsing day")?, + ); + + let mut p = Parsed::new(); + p.year = Some(year); + p.month = Some(month); + p.day = Some(day); + p.hour_div_12 = Some(0); + p.hour_mod_12 = Some(0); + p.minute = Some(0); + p.second = Some(0); + Ok(p.to_datetime_with_timezone(&Utc)?) +} -- cgit v1.2.3-70-g09d2