diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-04 20:32:25 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-06 10:12:13 -0700 |
| commit | 990e611a56f37f64fbce74fbc487c7dcc4aa4e28 (patch) | |
| tree | 399c69583bd256d31668affc227f235386814552 /src/model/guild | |
| parent | Add CurrentUser::face(), User::face() (diff) | |
| download | serenity-990e611a56f37f64fbce74fbc487c7dcc4aa4e28.tar.xz serenity-990e611a56f37f64fbce74fbc487c7dcc4aa4e28.zip | |
Use chrono for struct timestamp fields
Chrono is easier to use than timestamped strings, so they should be
automatically deserialized and available for the user, instead of having
the user deserialize the strings themselves.
These fields have been changed to use a type of `DateTime<FixedOffset>`:
- `ChannelPinsUpdateEvent.last_pin_timestamp`
- `Group.last_pin_timestamp`
- `Guild.joined_at`
- `GuildChannel.last_pin_timestamp`
- `Invite.created_at`
- `Member.joined_at`
- `Message.edited_timestamp
- `Message.timestamp`
- `MessageUpdateEvent.edited_timestamp`
- `MessageUpdateEvent.timestamp`
- `PrivateChannel.last_pin_timestamp`
`Member.joined_at` is now also an `Option`. Previously, if a Guild
Member Update was received for a member not in the cache, a new Member
would be instantiated with a default String value. This is incorrect
behaviour, and has now been replaced with being set to `None` in that
case.
Id methods' `created_at()` method now return a `chrono::NaiveDateTime`
instead of a `time::Timespec`, and `User::created_at` has been updated
to reflect that.
Additionally, drop `time` as a direct dependency and use chrono for
internals.
Diffstat (limited to 'src/model/guild')
| -rw-r--r-- | src/model/guild/member.rs | 5 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index 99bf67b..0082643 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, FixedOffset}; use std::fmt::{Display, Formatter, Result as FmtResult}; use super::deserialize_sync_user; use ::model::*; @@ -23,7 +24,7 @@ pub struct Member { /// The unique Id of the guild that the member is a part of. pub guild_id: Option<GuildId>, /// Timestamp representing the date when the member joined. - pub joined_at: String, + pub joined_at: Option<DateTime<FixedOffset>>, /// Indicator of whether the member can speak in voice channels. pub mute: bool, /// The member's nickname, if present. @@ -326,7 +327,7 @@ impl Member { .unwrap() .members .values() - .any(|m| m.user.read().unwrap().id == self.user.read().unwrap().id && m.joined_at == *self.joined_at)) + .any(|m| m.user.read().unwrap().id == self.user.read().unwrap().id && m.joined_at == self.joined_at)) .map(|guild| guild .read() .unwrap() diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 24e1881..a744b2c 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -14,6 +14,7 @@ pub use self::member::*; pub use self::partial_guild::*; pub use self::role::*; +use chrono::{DateTime, FixedOffset}; use serde::de::Error as DeError; use serde_json; use super::utils::*; @@ -73,7 +74,7 @@ pub struct Guild { /// that of the default channel (typically `#general`). pub id: GuildId, /// The date that the current user joined the guild. - pub joined_at: String, + pub joined_at: DateTime<FixedOffset>, /// Indicator of whether the guild is considered "large" by Discord. pub large: bool, /// The number of members in the guild. @@ -1149,7 +1150,7 @@ impl<'de> Deserialize<'de> for Guild { .map_err(DeError::custom)?; let joined_at = map.remove("joined_at") .ok_or_else(|| DeError::custom("expected guild joined_at")) - .and_then(String::deserialize) + .and_then(DateTime::deserialize) .map_err(DeError::custom)?; let large = map.remove("large") .ok_or_else(|| DeError::custom("expected guild large")) |