summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-01-23 22:47:50 +0100
committerNora <nora.widdecke@tu-bs.de>2019-01-23 22:47:50 +0100
commit530c85b176bfa1eb2f920c79eb49ff92c48a749d (patch)
tree0b44bd9f9a97bc23e301d9046432553e7d804078
parent2489ae5fa4bd6bdc540df3c1583602d00215e23f (diff)
icaltimezone: add method ymd to create an icaltime wrt the timezone
-rw-r--r--src/icalwrap/icaltimezone.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/icalwrap/icaltimezone.rs b/src/icalwrap/icaltimezone.rs
index 1354fa1..465c2b1 100644
--- a/src/icalwrap/icaltimezone.rs
+++ b/src/icalwrap/icaltimezone.rs
@@ -63,6 +63,10 @@ impl IcalTimeZone {
ical::icaltimezone_get_utc_offset(self.timezone, &mut icaltime , &mut is_dst)
}
}
+
+ pub fn ymd(&self, year: i32, month: i32, day: i32) -> IcalTime {
+ IcalTime::floating_ymd(year, month, day).with_timezone(&self)
+ }
}
#[cfg(test)]
@@ -107,6 +111,24 @@ mod tests {
}
#[test]
+ fn test_ymd() {
+ let tz = IcalTimeZone::from_name("US/Eastern").unwrap();
+ let date = tz.ymd(2014,3,1);
+ assert_eq!(IcalTime::floating_ymd(2014,3,1), date);
+ assert_eq!(1393650000, date.timestamp());
+ assert_eq!("US/Eastern", date.get_timezone().unwrap().get_name());
+ }
+
+ #[test]
+ fn test_ymd_and_hms() {
+ let tz = IcalTimeZone::from_name("US/Eastern").unwrap();
+ let date = tz.ymd(2014,3,1).and_hms(17, 20, 0);
+ assert_eq!(IcalTime::floating_ymd(2014,3,1).and_hms(17, 20, 0), date);
+ assert_eq!(1393712400, date.timestamp());
+ assert_eq!("US/Eastern", date.get_timezone().unwrap().get_name());
+ }
+
+ #[test]
fn test_from_name() {
let tz = IcalTimeZone::from_name("US/Eastern").unwrap();
assert_eq!("US/Eastern", tz.get_name());