mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 08:09:58 -07:00
global: snapshot
This commit is contained in:
@@ -12,6 +12,10 @@ impl Date {
|
||||
pub const INDEX_ONE: Self = Self(20090109);
|
||||
pub const INDEX_ONE_: Date_ = Date_::constant(2009, 1, 9);
|
||||
|
||||
pub fn new(year: u16, month: u8, day: u8) -> Self {
|
||||
Self(year as u32 * 1_00_00 + month as u32 * 1_00 + day as u32)
|
||||
}
|
||||
|
||||
pub fn year(&self) -> u16 {
|
||||
(self.0 / 1_00_00) as u16
|
||||
}
|
||||
@@ -33,7 +37,7 @@ impl Default for Date {
|
||||
|
||||
impl From<Date_> for Date {
|
||||
fn from(value: Date_) -> Self {
|
||||
Self(value.year() as u32 * 1_00_00 + value.month() as u32 * 1_00 + value.day() as u32)
|
||||
Self::new(value.year() as u16, value.month() as u8, value.day() as u8)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,3 +62,9 @@ impl From<Dateindex> for Date {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Date {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&format!("{}-{}-{}", self.year(), self.month(), self.day()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use derive_deref::Deref;
|
||||
use jiff::{civil::date, tz::TimeZone};
|
||||
use serde::Serialize;
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
@@ -7,12 +8,27 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
)]
|
||||
pub struct Timestamp(u32);
|
||||
|
||||
impl Timestamp {
|
||||
pub fn floor_seconds(self) -> Self {
|
||||
let t = jiff::Timestamp::from(self).to_zoned(TimeZone::UTC);
|
||||
let d = jiff::civil::DateTime::from(t);
|
||||
let d = date(d.year(), d.month(), d.day()).at(d.hour(), d.minute(), 0, 0);
|
||||
Self::from(d.to_zoned(TimeZone::UTC).unwrap().timestamp())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Timestamp {
|
||||
fn from(value: u32) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<jiff::Timestamp> for Timestamp {
|
||||
fn from(value: jiff::Timestamp) -> Self {
|
||||
Self(value.as_second() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Timestamp> for jiff::Timestamp {
|
||||
fn from(value: Timestamp) -> Self {
|
||||
jiff::Timestamp::from_second(*value as i64).unwrap()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use byteview::ByteView;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Unit;
|
||||
|
||||
impl From<ByteView> for Unit {
|
||||
|
||||
Reference in New Issue
Block a user