aboutsummaryrefslogtreecommitdiff
path: root/src/gateway
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-06-04 20:32:25 -0700
committerZeyla Hellyer <[email protected]>2017-06-06 10:12:13 -0700
commit990e611a56f37f64fbce74fbc487c7dcc4aa4e28 (patch)
tree399c69583bd256d31668affc227f235386814552 /src/gateway
parentAdd CurrentUser::face(), User::face() (diff)
downloadserenity-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/gateway')
-rw-r--r--src/gateway/prep.rs6
-rw-r--r--src/gateway/shard.rs4
2 files changed, 5 insertions, 5 deletions
diff --git a/src/gateway/prep.rs b/src/gateway/prep.rs
index 6a415f8..8e04df4 100644
--- a/src/gateway/prep.rs
+++ b/src/gateway/prep.rs
@@ -1,3 +1,4 @@
+use chrono::{Duration, UTC};
use serde_json::Value;
use std::sync::mpsc::{
Receiver as MpscReceiver,
@@ -8,7 +9,6 @@ use std::sync::{Arc, Mutex};
use std::time::{Duration as StdDuration, Instant};
use std::{env, thread};
use super::{GatewayError, GatewayStatus};
-use time::{self, Duration};
use websocket::client::request::Url as RequestUrl;
use websocket::client::{Receiver, Sender};
use websocket::result::WebSocketError as WsError;
@@ -81,7 +81,7 @@ pub fn keepalive(interval: u64,
mut sender: Sender<WebSocketStream>,
channel: &MpscReceiver<GatewayStatus>) {
let mut base_interval = Duration::milliseconds(interval as i64);
- let mut next_tick = time::get_time() + base_interval;
+ let mut next_tick = UTC::now() + base_interval;
let mut last_sequence = 0;
let mut last_successful = false;
@@ -110,7 +110,7 @@ pub fn keepalive(interval: u64,
}
}
- if time::get_time() >= next_tick {
+ if UTC::now() >= next_tick {
// If the last heartbeat didn't receive an acknowledgement, then
// shutdown and auto-reconnect.
if !*last_ack.lock().unwrap() {
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs
index 7790cc6..343aa06 100644
--- a/src/gateway/shard.rs
+++ b/src/gateway/shard.rs
@@ -1,3 +1,4 @@
+use chrono::UTC;
use std::io::Write;
use std::net::Shutdown;
use std::sync::mpsc::{self, Sender as MpscSender};
@@ -6,7 +7,6 @@ use std::thread::{self, Builder as ThreadBuilder};
use std::time::{Duration as StdDuration, Instant};
use std::mem;
use super::{GatewayError, GatewayStatus, prep};
-use time;
use websocket::client::{Client as WsClient, Sender, Receiver};
use websocket::message::Message as WsMessage;
use websocket::result::WebSocketError;
@@ -788,7 +788,7 @@ impl Shard {
fn update_presence(&self) {
let (ref game, status, afk) = self.current_presence;
- let now = time::get_time().sec as u64;
+ let now = UTC::now().timestamp() as u64;
let msg = json!({
"op": OpCode::StatusUpdate.num(),