summary refs log tree commit diff stats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5f80c1c..ea0c8ae 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -406,7 +406,12 @@ pub use valid_context::ValidContext;
 #[derive(Clone)]
 pub struct EventAttrs<'a> {
     /// Server time.
+    #[deprecated(since="2.3.0", note="Use raw_server_time instead")]
     pub server_time: Option<SystemTime>,
+    /// Raw server time. Only does anything if `use_raw_server_time` is set.
+    pub raw_server_time: libc::time_t,
+    /// Whether to pass `server_time` or `raw_server_time` to hexchat.
+    pub use_raw_server_time: bool,
     _dummy: PhantomData<&'a ()>,
 }
 
@@ -1589,18 +1594,25 @@ impl<'ph> PluginHandle<'ph> {
 
 impl<'a> EventAttrs<'a> {
     /// Creates a new `EventAttrs`.
+    #[allow(deprecated)]
     pub fn new() -> EventAttrs<'a> {
         EventAttrs {
             server_time: None,
+            raw_server_time: 0,
+            use_raw_server_time: false,
             _dummy: PhantomData,
         }
     }
 }
 
 impl<'a> From<&'a RawAttrs> for EventAttrs<'a> {
+    #[allow(deprecated)]
     fn from(other: &'a RawAttrs) -> EventAttrs<'a> {
         EventAttrs {
             server_time: if other.server_time_utc > 0 { Some(UNIX_EPOCH + Duration::from_secs(other.server_time_utc as u64)) } else { None },
+            raw_server_time: other.server_time_utc,
+            // Defaults to false for API compatibility.
+            use_raw_server_time: false,
             _dummy: PhantomData,
         }
     }
@@ -2106,10 +2118,19 @@ impl<'a, 'ph> HexchatEventAttrsHelper<'a, 'ph> where 'ph: 'a {
     /// `ph` must be a valid raw plugin handle.
     unsafe fn new_with(ph: &'a PluginHandle<'ph>, attrs: EventAttrs<'_>) -> Self {
         let helper = Self::new(ph);
-        let v = attrs.server_time.or(Some(UNIX_EPOCH)).map(|st| match st.duration_since(UNIX_EPOCH) {
-            Ok(n) => n.as_secs(),
-            Err(_) => 0
-        }).filter(|&st| st < (time_t::max_value() as u64)).unwrap() as time_t;
+        #[allow(deprecated)]
+        let v = if attrs.use_raw_server_time {
+            attrs.raw_server_time
+        } else {
+            attrs.server_time.or(Some(UNIX_EPOCH)).map(|st| {
+                match st.duration_since(UNIX_EPOCH) {
+                    Ok(n) => n.as_secs(),
+                    Err(_) => 0
+                }
+            }).filter(|&st| {
+                st < (time_t::max_value() as u64)
+            }).unwrap() as time_t
+        };
         (*helper.0).server_time_utc = v;
         helper
     }