diff --git a/Cargo.lock b/Cargo.lock index 3051460..b08cbdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -431,6 +431,27 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "chrono-tz" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6dd8046d00723a59a2f8c5f295c515b9bb9a331ee4f8f3d4dd49e428acd3b6" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf", +] + +[[package]] +name = "chrono-tz-build" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94fea34d77a245229e7746bd2beb786cd2a896f306ff491fb8cecb3074b10a7" +dependencies = [ + "parse-zoneinfo", + "phf_codegen", +] + [[package]] name = "colored" version = "2.1.0" @@ -1543,6 +1564,15 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "parse-zoneinfo" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24" +dependencies = [ + "regex", +] + [[package]] name = "paste" version = "1.0.15" @@ -1618,6 +1648,26 @@ dependencies = [ "phf_shared", ] +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared", + "rand", +] + [[package]] name = "phf_shared" version = "0.11.2" @@ -1919,6 +1969,7 @@ dependencies = [ "async-graphql-axum", "axum 0.7.5", "chrono", + "chrono-tz", "hex", "hmac", "serde", diff --git a/Cargo.toml b/Cargo.toml index ca5dcaf..5a315f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,5 @@ sqlx = { version = "0.7.1", features = ["chrono"] } tokio = "1.28.2" hmac = "0.12.1" sha2 = "0.10.8" -hex = "0.4.3" \ No newline at end of file +hex = "0.4.3" +chrono-tz = "0.10.0" diff --git a/src/graphql/mutations.rs b/src/graphql/mutations.rs index ea3f032..dda1dfe 100644 --- a/src/graphql/mutations.rs +++ b/src/graphql/mutations.rs @@ -1,8 +1,9 @@ use async_graphql::{Context, Object}; use ::chrono::Local; use chrono::{NaiveDate, NaiveTime}; +use chrono_tz::Asia::Kolkata; use sqlx::PgPool; -use sqlx::types::chrono; +use sqlx::types::chrono; use std::sync::Arc; use hmac::{Hmac,Mac}; use sha2::Sha256; @@ -113,10 +114,7 @@ impl MutationRoot { return Err(sqlx::Error::Protocol("HMAC verification failed".into())); } - - - - let current_time = Local::now().time(); + let current_time = Local::now().with_timezone(&Kolkata).time(); let attendance = sqlx::query_as::<_, Attendance>( " diff --git a/src/main.rs b/src/main.rs index 093df7a..ed37c1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::time::Duration; use async_graphql_axum::GraphQL; use axum::{routing::get, Router}; use chrono::{ Local, NaiveTime}; - +use chrono_tz::Asia::Kolkata; use db::member::Member; use sqlx::PgPool; use async_graphql::{ Schema, EmptySubscription}; @@ -63,7 +63,7 @@ async fn scheduled_task(pool: Arc) { match members { Ok(members) => { - let today = Local::now().naive_local(); + let today = Local::now().with_timezone(&Kolkata); for member in members { let timein = NaiveTime::from_hms_opt(0, 0, 0);