Browse Source

Tests with Chrono

master
Julio Biason 3 years ago
parent
commit
a4aaa4c6b0
  1. 93
      chronotest/Cargo.lock
  2. 9
      chronotest/Cargo.toml
  3. 46
      chronotest/src/main.rs

93
chronotest/Cargo.lock generated

@ -0,0 +1,93 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]]
name = "chronotest"
version = "0.1.0"
dependencies = [
"chrono",
]
[[package]]
name = "libc"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

9
chronotest/Cargo.toml

@ -0,0 +1,9 @@
[package]
name = "chronotest"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4.19"

46
chronotest/src/main.rs

@ -0,0 +1,46 @@
use chrono::DateTime;
use chrono::SecondsFormat;
use chrono::TimeZone;
use chrono::Utc;
fn from_millis(millis: i64) -> DateTime<Utc> {
Utc.timestamp_millis(millis)
}
fn candle_id(timestamp: &DateTime<Utc>, size_ms: i64) -> DateTime<Utc> {
let millis = timestamp.timestamp_millis();
println!(
"{} -> {}",
timestamp.to_rfc3339_opts(SecondsFormat::Millis, false),
millis
);
let id = (millis / size_ms) * size_ms;
println!(" {}", id);
Utc.timestamp_millis(id)
}
fn display(name: &str, millis: i64) {
let today = from_millis(millis);
println!(
"{:>10}: {}",
name,
today.to_rfc3339_opts(SecondsFormat::Millis, false)
);
println!(
"{:>10}: {}",
"ID",
candle_id(&today, 10).to_rfc3339_opts(SecondsFormat::Millis, false)
);
}
fn main() {
let complete = (1648641824010i64 / 10) * 10;
println!("Complete: {}", complete);
display("0", 1648641824000);
display("1", 1648641824001);
display("9", 1648641824009);
display("10", 1648641824010);
display("99", 1648641824099);
display("100", 1648641824100);
}
Loading…
Cancel
Save