summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Breitmoser <look@my.amazin.horse>2019-01-12 15:38:57 +0100
committerVincent Breitmoser <look@my.amazin.horse>2019-01-12 16:33:39 +0100
commitc61a8075a98c4674694f3ab25f15cca54f9958f8 (patch)
tree7ddb912ebc4460f25f130e9824181c5121734ad0 /src
parent5216a30ac92716aa16b8760bd9048820a7466f33 (diff)
use Local for instance timestamps instead of Utc
Diffstat (limited to 'src')
-rw-r--r--src/icalwrap/icalvcalendar.rs10
-rw-r--r--src/icalwrap/icalvevent.rs8
-rw-r--r--src/khline.rs17
-rw-r--r--src/utils/dateutil.rs5
4 files changed, 24 insertions, 16 deletions
diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs
index 19c182c..dd6a5af 100644
--- a/src/icalwrap/icalvcalendar.rs
+++ b/src/icalwrap/icalvcalendar.rs
@@ -1,4 +1,4 @@
-use chrono::{DateTime, Utc};
+use chrono::{DateTime, Local};
use std::ffi::{CStr, CString};
use std::path::{PathBuf,Path};
use std::rc::Rc;
@@ -10,7 +10,7 @@ use ical;
pub struct IcalVCalendar {
comp: Rc<IcalComponentOwner>,
path: Option<PathBuf>,
- instance_timestamp: Option<DateTime<Utc>>,
+ instance_timestamp: Option<DateTime<Local>>,
}
pub struct IcalEventIter<'a> {
@@ -57,7 +57,7 @@ impl IcalVCalendar {
}
}
- pub fn with_internal_timestamp(mut self, datetime: DateTime<Utc>) -> IcalVCalendar {
+ pub fn with_internal_timestamp(mut self, datetime: DateTime<Local>) -> IcalVCalendar {
self.instance_timestamp = Some(datetime);
self
}
@@ -321,7 +321,7 @@ impl Drop for IcalComponentOwner {
mod tests {
use super::*;
use testdata;
- use chrono::{Local, TimeZone};
+ use chrono::{Utc, Local, TimeZone};
#[test]
fn test_from_str_empty() {
@@ -415,7 +415,7 @@ mod tests {
fn test_with_internal_timestamp() {
let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
- let timestamp = Utc.ymd(2018, 1, 1).and_hms(11, 30, 20);
+ let timestamp = Local.ymd(2018, 1, 1).and_hms(11, 30, 20);
let new_cal = cal.with_internal_timestamp(timestamp);
let event = new_cal.get_principal_event();
diff --git a/src/icalwrap/icalvevent.rs b/src/icalwrap/icalvevent.rs
index d51003f..278d737 100644
--- a/src/icalwrap/icalvevent.rs
+++ b/src/icalwrap/icalvevent.rs
@@ -8,7 +8,7 @@ use ical;
pub struct IcalVEvent {
ptr: *mut ical::icalcomponent,
parent: Option<IcalVCalendar>,
- instance_timestamp: Option<DateTime<Utc>>,
+ instance_timestamp: Option<DateTime<Local>>,
}
impl Drop for IcalVEvent {
@@ -123,7 +123,7 @@ impl IcalVEvent {
result
}
- pub fn with_internal_timestamp(&self, datetime: DateTime<Utc>) -> IcalVEvent {
+ pub fn with_internal_timestamp(&self, datetime: DateTime<Local>) -> IcalVEvent {
IcalVEvent {
ptr: self.ptr,
parent: self.parent.as_ref().map(|parent| parent.shallow_copy()),
@@ -132,7 +132,9 @@ impl IcalVEvent {
}
pub fn get_recur_instances(&self) -> impl Iterator<Item = IcalVEvent> + '_ {
- self.get_recur_datetimes().into_iter().map(move |rec| self.with_internal_timestamp(rec))
+ self.get_recur_datetimes().into_iter()
+ .map(|recur_utc| recur_utc.with_timezone(&Local))
+ .map(move |recur_local| self.with_internal_timestamp(recur_local))
}
pub fn get_parent(&self) -> Option<&IcalVCalendar> {
diff --git a/src/khline.rs b/src/khline.rs
index 82fcf2d..a3e0a03 100644
--- a/src/khline.rs
+++ b/src/khline.rs
@@ -6,13 +6,13 @@ use icalwrap::IcalVEvent;
pub struct KhLine {
path: PathBuf,
- time: DateTime<Local>,
+ time: Option<DateTime<Local>>,
}
impl KhLine {
pub fn from(event: &IcalVEvent) -> Option<KhLine> {
- let time = event.get_dtstart()?;
let path = event.get_parent()?.get_path()?.to_path_buf();
+ let time = event.get_dtstart();
Some(KhLine{ path, time })
}
@@ -23,11 +23,16 @@ impl KhLine {
}
impl fmt::Display for KhLine {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let time_string = format!("{:010}", self.time.timestamp());
- let path_string = self.path.to_string_lossy();
- write!(f, "{} {}", time_string, path_string)
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let path_string = self.path.to_string_lossy();
+ match self.time {
+ Some(time) => {
+ let time_string = format!("{:010}", time.timestamp());
+ write!(f, "{} {}", time_string, path_string)
+ }
+ None => write!(f, "{}", path_string)
}
+ }
}
#[cfg(test)]
diff --git a/src/utils/dateutil.rs b/src/utils/dateutil.rs
index 84818ce..1272834 100644
--- a/src/utils/dateutil.rs
+++ b/src/utils/dateutil.rs
@@ -36,10 +36,11 @@ pub fn week_from_str_end(date_str: &str) -> Result<Date<Local>,String> {
Err("Could not parse '{}' as week".to_string())
}
-pub fn datetime_from_timestamp(timestamp: &str) -> Option<DateTime<Utc>> {
+pub fn datetime_from_timestamp(timestamp: &str) -> Option<DateTime<Local>> {
let timestamp_i64 = timestamp.parse::<i64>().ok()?;
let naive_datetime = NaiveDateTime::from_timestamp_opt(timestamp_i64, 0)?;
- Some(DateTime::from_utc(naive_datetime, Utc))
+ let utc_time: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
+ Some(utc_time.with_timezone(&Local))
}
#[cfg(test)]