aboutsummaryrefslogtreecommitdiff
path: root/src/model/mod.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-21 13:47:25 -0800
committerAustin Hellyer <[email protected]>2016-11-21 13:47:25 -0800
commitd89739a0084b368f29673a0487af74409d68965c (patch)
treed6462ed17555602ff499678959bbe2ede2a87be6 /src/model/mod.rs
parentMake Context::channel_id public (diff)
downloadserenity-d89739a0084b368f29673a0487af74409d68965c.tar.xz
serenity-d89739a0084b368f29673a0487af74409d68965c.zip
Add created_at method to Ids and User
Returns a Timespec of when the Id (or User) was created.
Diffstat (limited to 'src/model/mod.rs')
-rw-r--r--src/model/mod.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/model/mod.rs b/src/model/mod.rs
index 0b93823..20dfabb 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -33,6 +33,7 @@ pub use self::webhook::*;
use self::utils::*;
use std::collections::HashMap;
use std::fmt;
+use time::Timespec;
use ::internal::prelude::*;
use ::utils::{Colour, decode_array};
@@ -63,6 +64,12 @@ macro_rules! id {
fn decode(value: Value) -> Result<Self> {
decode_id(value).map($name)
}
+
+ /// Retrieves the time that the Id was created at.
+ pub fn created_at(&self) -> Timespec {
+ let offset = (self.0 >> 22) / 1000;
+ Timespec::new(1420070400 + offset as i64, 0)
+ }
}
impl fmt::Display for $name {