Commit 8682f274 by Dirreke

feat(guizhou): finish guizhou

parent 5e014f3e
...@@ -131,6 +131,28 @@ dependencies = [ ...@@ -131,6 +131,28 @@ dependencies = [
] ]
[[package]] [[package]]
name = "chrono-tz"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb"
dependencies = [
"chrono",
"chrono-tz-build",
"phf",
]
[[package]]
name = "chrono-tz-build"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1"
dependencies = [
"parse-zoneinfo",
"phf",
"phf_codegen",
]
[[package]]
name = "ciborium" name = "ciborium"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
...@@ -301,6 +323,7 @@ dependencies = [ ...@@ -301,6 +323,7 @@ dependencies = [
"arrow-schema", "arrow-schema",
"bytes", "bytes",
"chrono", "chrono",
"chrono-tz",
"ciborium", "ciborium",
"csv", "csv",
"log", "log",
...@@ -700,6 +723,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -700,6 +723,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
[[package]] [[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" name = "paste"
version = "1.0.15" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
...@@ -716,6 +748,44 @@ dependencies = [ ...@@ -716,6 +748,44 @@ dependencies = [
] ]
[[package]] [[package]]
name = "phf"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
dependencies = [
"siphasher",
]
[[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.14" version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
...@@ -807,6 +877,21 @@ dependencies = [ ...@@ -807,6 +877,21 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "rawpointer" name = "rawpointer"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
...@@ -941,6 +1026,12 @@ dependencies = [ ...@@ -941,6 +1026,12 @@ dependencies = [
] ]
[[package]] [[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "syn" name = "syn"
version = "2.0.72" version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
......
...@@ -14,4 +14,4 @@ mems = { path = "../../../mems" } ...@@ -14,4 +14,4 @@ mems = { path = "../../../mems" }
csv = "1.3.0" csv = "1.3.0"
bytes = "1.6.1" bytes = "1.6.1"
chrono = "0.4.38" chrono = "0.4.38"
# chrono-tz = "0.9" chrono-tz = "0.9"
...@@ -2,7 +2,8 @@ use arrow_schema::{DataType, TimeUnit, Field, Schema}; ...@@ -2,7 +2,8 @@ use arrow_schema::{DataType, TimeUnit, Field, Schema};
use bytes::{Buf, BufMut, BytesMut}; use bytes::{Buf, BufMut, BytesMut};
use log::info; use log::info;
use mems::model::{PluginInput, PluginOutput}; use mems::model::{PluginInput, PluginOutput};
use chrono::{Days, Duration, Local, Timelike}; use chrono::{Days, Duration, Timelike, Utc};
use chrono_tz::Asia::Shanghai;
static mut OUTPUT: Vec<u8> = vec![]; static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle] #[no_mangle]
...@@ -24,7 +25,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -24,7 +25,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
let mut rdr = csv::ReaderBuilder::new().has_headers(true).from_reader(&*input.bytes); let mut rdr = csv::ReaderBuilder::new().has_headers(true).from_reader(&*input.bytes);
let records = rdr.records(); let records = rdr.records();
let now = Local::now(); let now = Utc::now().with_timezone(&Shanghai);
let today = now.date_naive(); let today = now.date_naive();
let starttime = if input.dfs_len[0] >= 24 { let starttime = if input.dfs_len[0] >= 24 {
let startday = if now.hour() < 1 { let startday = if now.hour() < 1 {
...@@ -34,14 +35,15 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -34,14 +35,15 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
}; };
startday.and_hms_opt(0, 0, 0) startday.and_hms_opt(0, 0, 0)
.unwrap() .unwrap()
.and_local_timezone(Local) .and_local_timezone(Shanghai)
.unwrap() .unwrap()
} else { } else {
let time0 = today.and_hms_opt(0, 0, 0) let minutes = now.minute() / 15 * 15;
let time0 = today.and_hms_opt(now.hour(), minutes, 0)
.unwrap() .unwrap()
.and_local_timezone(Local) .and_local_timezone(Shanghai)
.unwrap(); .unwrap();
time0 + Duration::hours((now.hour() + 1) as i64) time0 + Duration::minutes(15)
}; };
for (i, record) in records.enumerate() { for (i, record) in records.enumerate() {
...@@ -72,3 +74,22 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -72,3 +74,22 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
return bytes.get_u64(); return bytes.get_u64();
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test() {
let now = Utc::now().with_timezone(&Shanghai);
let today = now.date_naive();
let startday = if now.hour() < 1 {
today
} else {
today.checked_add_days(chrono::Days::new(1)).unwrap()
};
let a = startday.and_hms_opt(0, 0, 0)
.unwrap()
.and_local_timezone(Shanghai)
.unwrap();
println!("{:?}", a);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论