diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-01-23 21:51:39 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-01-23 21:51:39 +0100 |
commit | ac2f011368d86f08b04a7589bab8b948be7c7888 (patch) | |
tree | 9a87c2d420f4d3cc69d3b3807dee9ed61c062e1d /src/icalwrap | |
parent | 0eed2f736252ebe9526c1c176be61fa2a7c1deba (diff) |
split from_ymd into floatin_ymd and and_hms
Diffstat (limited to 'src/icalwrap')
-rw-r--r-- | src/icalwrap/icaltime.rs | 21 | ||||
-rw-r--r-- | src/icalwrap/icalvcalendar.rs | 6 | ||||
-rw-r--r-- | src/icalwrap/icalvevent.rs | 14 |
3 files changed, 19 insertions, 22 deletions
diff --git a/src/icalwrap/icaltime.rs b/src/icalwrap/icaltime.rs index 632c673..63e55e7 100644 --- a/src/icalwrap/icaltime.rs +++ b/src/icalwrap/icaltime.rs @@ -22,27 +22,24 @@ impl IcalTime { dateutil::now().with_timezone(&Local).into() } - pub fn from_ymd(year: i32, month: i32, day: i32) -> Self { - let utc = IcalTimeZone::utc(); + pub fn floating_ymd(year: i32, month: i32, day: i32) -> Self { let time = ical::icaltimetype{ year, month, day, hour: 0, minute: 0, second: 0, is_date: 1, is_daylight: 0, - zone: *utc + zone: ::std::ptr::null(), }; IcalTime{ time } } - pub fn from_ymdhms(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32) -> Self { - let utc = IcalTimeZone::utc(); - let time = ical::icaltimetype{ - year, month, day, - hour, minute, second, - is_date: 0, - is_daylight: 0, - zone: *utc - }; + pub fn and_hms(&self, hour: i32, minute: i32, second: i32) -> Self { + let mut time = self.time; + time.hour = hour; + time.minute = minute; + time.second = second; + time.is_date = 0; + IcalTime{ time } } diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs index 36eafc1..0dd0b49 100644 --- a/src/icalwrap/icalvcalendar.rs +++ b/src/icalwrap/icalvcalendar.rs @@ -507,7 +507,7 @@ mod tests { testdata::setup(); let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap(); - let timestamp = IcalTime::from_ymdhms(2018, 1, 1, 11, 30, 20); + let timestamp = IcalTime::floating_ymd(2018, 1, 1).and_hms(11, 30, 20); let new_cal = cal.with_dtend(×tamp); let event = new_cal.get_principal_event(); @@ -519,7 +519,7 @@ mod tests { testdata::setup(); let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap(); - let timestamp = IcalTime::from_ymdhms(2018, 1, 1, 11, 30, 20); + let timestamp = IcalTime::floating_ymd(2018, 1, 1).and_hms(11, 30, 20); let new_cal = cal.with_dtstart(×tamp); let event = new_cal.get_principal_event(); @@ -530,7 +530,7 @@ mod tests { fn test_with_internal_timestamp() { let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap(); - let timestamp = IcalTime::from_ymdhms(2018, 1, 1, 11, 30, 20); + let timestamp = IcalTime::floating_ymd(2018, 1, 1).and_hms(11, 30, 20); let new_cal = cal.with_internal_timestamp(×tamp); let event = new_cal.get_principal_event(); diff --git a/src/icalwrap/icalvevent.rs b/src/icalwrap/icalvevent.rs index 0e13718..f4adf0f 100644 --- a/src/icalwrap/icalvevent.rs +++ b/src/icalwrap/icalvevent.rs @@ -215,8 +215,8 @@ mod tests { testdata::setup(); let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap(); let event = cal.get_principal_event(); - assert_eq!(IcalTime::from_ymd(2018, 10, 11), event.get_dtstart().unwrap()); - assert_eq!(IcalTime::from_ymd(2018, 10, 13), event.get_dtend().unwrap()); + assert_eq!(IcalTime::floating_ymd(2018, 10, 11), event.get_dtstart().unwrap()); + assert_eq!(IcalTime::floating_ymd(2018, 10, 13), event.get_dtend().unwrap()); assert_eq!("RRULE:FREQ=WEEKLY;COUNT=10", event.get_property(ical::icalproperty_kind_ICAL_RRULE_PROPERTY).unwrap().as_ical_string()); assert_eq!(10, event.get_recur_datetimes().len()); assert_eq!(10, event.get_recur_instances().count()); @@ -311,7 +311,7 @@ mod tests { fn test_is_recur_master_instance() { let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap(); let event = cal.get_principal_event(); - let event = event.with_internal_timestamp(&IcalTime::from_ymd(2018, 01, 01)); + let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2018, 01, 01)); assert!(!event.is_recur_master()); } @@ -328,8 +328,8 @@ mod tests { let event = cal.get_principal_event(); let mut recur_instances = event.get_recur_instances(); let local = IcalTimeZone::local(); - assert_eq!(IcalTime::from_ymd(2018, 10, 11).with_timezone(&local), recur_instances.next().unwrap().get_dtstart().unwrap()); - assert_eq!(IcalTime::from_ymd(2018, 10, 18).with_timezone(&local), recur_instances.next().unwrap().get_dtstart().unwrap()); + assert_eq!(IcalTime::floating_ymd(2018, 10, 11).with_timezone(&local), recur_instances.next().unwrap().get_dtstart().unwrap()); + assert_eq!(IcalTime::floating_ymd(2018, 10, 18).with_timezone(&local), recur_instances.next().unwrap().get_dtstart().unwrap()); } #[test] @@ -355,7 +355,7 @@ mod tests { let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap(); let event = cal.get_principal_event(); - let event = event.with_internal_timestamp(&IcalTime::from_ymd(2010, 01, 01)); + let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2010, 01, 01)); assert!(!event.is_recur_valid()); } @@ -365,7 +365,7 @@ mod tests { let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap(); let event = cal.get_principal_event(); - let event = event.with_internal_timestamp(&IcalTime::from_ymd(2018, 10, 25)); + let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2018, 10, 25)); assert!(event.is_recur_valid()); } |