From 858d5ab99d3cfd77c057ccc34e95e54a1de21563 Mon Sep 17 00:00:00 2001 From: ssuchichan Date: Mon, 11 Mar 2024 09:50:58 +0800 Subject: [PATCH] fix. --- explorer/src/service/v1/block.rs | 6 +++--- explorer/src/service/v1/chain.rs | 4 ++-- explorer/src/service/v1/validator.rs | 7 ++++--- explorer/src/service/v2/other.rs | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/explorer/src/service/v1/block.rs b/explorer/src/service/v1/block.rs index 230b9d0..21dd112 100644 --- a/explorer/src/service/v1/block.rs +++ b/explorer/src/service/v1/block.rs @@ -6,7 +6,7 @@ use poem_openapi::param::Query; use poem_openapi::{param::Path, payload::Json, ApiResponse, Object}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use sqlx::types::chrono::NaiveDateTime; +use sqlx::types::chrono::DateTime; use sqlx::{Error, Row}; use std::ops::Add; @@ -285,13 +285,13 @@ pub async fn get_blocks( if let Some(start_time) = start_time.0 { params.push(format!( " time >= '{}' ", - NaiveDateTime::from_timestamp_opt(start_time, 0).unwrap() + DateTime::from_timestamp(start_time, 0).unwrap() )); } if let Some(end_time) = end_time.0 { params.push(format!( " time <= '{}' ", - NaiveDateTime::from_timestamp_opt(end_time, 0).unwrap() + DateTime::from_timestamp(end_time, 0).unwrap() )); } let page = page.0.unwrap_or(1); diff --git a/explorer/src/service/v1/chain.rs b/explorer/src/service/v1/chain.rs index fdc004c..cce1434 100644 --- a/explorer/src/service/v1/chain.rs +++ b/explorer/src/service/v1/chain.rs @@ -217,12 +217,12 @@ pub async fn statistics(api: &Api, ty: Query>) -> Result={}", ty, - start_time.timestamp() + start_time.and_utc().timestamp() ) } else { format!( "SELECT COUNT(*) as cnt FROM transaction WHERE timestamp>={}", - start_time.timestamp() + start_time.and_utc().timestamp() ) }; let row = sqlx::query(sql_str.as_str()).fetch_one(&mut conn).await?; diff --git a/explorer/src/service/v1/validator.rs b/explorer/src/service/v1/validator.rs index 2ee3153..7d2002a 100644 --- a/explorer/src/service/v1/validator.rs +++ b/explorer/src/service/v1/validator.rs @@ -7,7 +7,7 @@ use poem_openapi::param::{Path, Query}; use poem_openapi::{payload::Json, ApiResponse, Object}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use sqlx::types::chrono::{Local, NaiveDateTime}; +use sqlx::types::chrono::{DateTime, Local}; use sqlx::Row; #[derive(ApiResponse)] @@ -465,6 +465,7 @@ pub async fn validator_signed_count( .date_naive() .and_hms_opt(0, 0, 0) .unwrap() + .and_utc() .timestamp() - (page - 1) * page_size * day_secs; @@ -472,8 +473,8 @@ pub async fn validator_signed_count( for i in 0..page_size { let start_secs = nt - i * day_secs; let end_secs = nt - i * day_secs + day_secs; - let start_time = NaiveDateTime::from_timestamp_opt(start_secs, 0).unwrap(); - let end_time = NaiveDateTime::from_timestamp_opt(end_secs, 0).unwrap(); + let start_time = DateTime::from_timestamp(start_secs, 0).unwrap(); + let end_time = DateTime::from_timestamp(end_secs, 0).unwrap(); let sql_block_cnt = format!( "SELECT count(*) as cnt FROM block WHERE time>='{start_time}' AND time<'{end_time}'" diff --git a/explorer/src/service/v2/other.rs b/explorer/src/service/v2/other.rs index 51783b5..811966b 100644 --- a/explorer/src/service/v2/other.rs +++ b/explorer/src/service/v2/other.rs @@ -61,7 +61,7 @@ pub async fn v2_statistics(api: &Api, ty: Query>) -> Result={}", - start_time.timestamp() + start_time.and_utc().timestamp() ); } _ => { @@ -69,7 +69,7 @@ pub async fn v2_statistics(api: &Api, ty: Query>) -> Result={}", - start_time.timestamp() + start_time.and_utc().timestamp() ); } }