diff options
| author | Austin Hellyer <[email protected]> | 2016-11-21 13:47:25 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-21 13:47:25 -0800 |
| commit | d89739a0084b368f29673a0487af74409d68965c (patch) | |
| tree | d6462ed17555602ff499678959bbe2ede2a87be6 /src/model | |
| parent | Make Context::channel_id public (diff) | |
| download | serenity-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')
| -rw-r--r-- | src/model/mod.rs | 7 | ||||
| -rw-r--r-- | src/model/user.rs | 9 |
2 files changed, 16 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 { diff --git a/src/model/user.rs b/src/model/user.rs index efe41fd..68c46ec 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -18,6 +18,8 @@ use serde_json::builder::ObjectBuilder; #[cfg(feature = "methods")] use super::Message; #[cfg(feature = "methods")] +use time::Timespec; +#[cfg(feature = "methods")] use ::client::http; #[cfg(feature = "state")] @@ -38,6 +40,13 @@ impl User { format!(cdn_concat!("/avatars/{}/{}.jpg"), self.id, av)) } + /// Retrieves the time that this user was created at. + #[cfg(feature = "methods")] + #[inline] + pub fn created_at(&self) -> Timespec { + self.id.created_at() + } + /// This is an alias of [direct_message]. /// /// [direct_message]: #method.direct_message |