1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Merge pull request #766 from actix/dependabot/cargo/chrono-0.4.35

chore(deps): bump chrono from 0.4.34 to 0.4.35
This commit is contained in:
Rob Ede 2024-03-11 19:55:35 +00:00 committed by GitHub
commit 9a7d5bbb5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 15 deletions

4
Cargo.lock generated
View File

@ -2016,9 +2016,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.34"
version = "0.4.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a"
dependencies = [
"android-tzdata",
"iana-time-zone",

View File

@ -1,7 +1,9 @@
#![allow(clippy::extra_unused_lifetimes)]
use chrono::{NaiveDateTime, TimeDelta, Utc};
use diesel::{r2d2::ConnectionManager, PgConnection};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::schema::*;
@ -13,7 +15,7 @@ pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
pub struct User {
pub email: String,
pub hash: String,
pub created_at: chrono::NaiveDateTime,
pub created_at: NaiveDateTime,
}
impl User {
@ -29,9 +31,9 @@ impl User {
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
#[diesel(table_name = invitations)]
pub struct Invitation {
pub id: uuid::Uuid,
pub id: Uuid,
pub email: String,
pub expires_at: chrono::NaiveDateTime,
pub expires_at: NaiveDateTime,
}
// any type that implements Into<String> can be used to create Invitation
@ -41,9 +43,9 @@ where
{
fn from(email: T) -> Self {
Invitation {
id: uuid::Uuid::new_v4(),
id: Uuid::new_v4(),
email: email.into(),
expires_at: chrono::Local::now().naive_local() + chrono::Duration::hours(24),
expires_at: (Utc::now() + TimeDelta::try_hours(24).unwrap()).naive_utc(),
}
}
}

View File

@ -4,7 +4,7 @@ use actix_web::{
HttpResponse, Responder,
};
use apalis::{prelude::*, redis::RedisStorage};
use chrono::{Duration, Utc};
use chrono::{TimeDelta, Utc};
use serde::Deserialize;
use crate::{persistent_jobs::Email, ItemCache};
@ -12,7 +12,7 @@ use crate::{persistent_jobs::Email, ItemCache};
#[derive(Debug, Deserialize)]
pub(crate) struct CacheInsert {
data: String,
duration: u64,
duration: u32,
}
#[get("/cache")]
@ -26,7 +26,7 @@ pub(crate) async fn cache_item(
cache: Data<ItemCache>,
web::Json(form): web::Json<CacheInsert>,
) -> actix_web::Result<impl Responder> {
let expires = Utc::now() + Duration::seconds(form.duration as i64);
let expires = Utc::now() + TimeDelta::try_seconds(form.duration as i64).unwrap();
// insert into item cache
cache.lock().unwrap().insert(form.data, expires);

View File

@ -11,8 +11,8 @@ use actix_web::{
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
Error, HttpResponse,
};
use chrono::{Local, NaiveDateTime};
use futures_util::{future::LocalBoxFuture, FutureExt, TryFutureExt};
use chrono::{DateTime, Utc};
use futures_util::{future::LocalBoxFuture, FutureExt as _, TryFutureExt as _};
#[doc(hidden)]
pub struct RateLimitService<S> {
@ -95,7 +95,7 @@ struct TokenBucket {
capacity: u64,
/// Time that last request was accepted.
last_req_time: NaiveDateTime,
last_req_time: DateTime<Utc>,
/// Numbers of tokens remaining.
///
@ -108,7 +108,7 @@ impl TokenBucket {
fn new(limit: u64) -> Self {
TokenBucket {
limit,
last_req_time: NaiveDateTime::UNIX_EPOCH,
last_req_time: DateTime::<Utc>::UNIX_EPOCH,
capacity: limit,
tokens: 0,
}
@ -116,7 +116,7 @@ impl TokenBucket {
/// Mutates leaky bucket for accepted request.
fn allow_query(&mut self) -> bool {
let current_time = Local::now().naive_local();
let current_time = Utc::now();
let time_elapsed = (current_time.timestamp() - self.last_req_time.timestamp()) as u64;