mirror of
https://github.com/stoatchat/iso8601-timestamp.git
synced 2026-07-01 21:45:22 -04:00
Final 3.0 cleanup
This commit is contained in:
+3
-3
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "iso8601-timestamp"
|
||||
version = "0.3.0-rc.1"
|
||||
version = "0.3.0"
|
||||
authors = ["novacrazy <novacrazy@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "High-performance ISO8601 Timestamp formatting and parsing"
|
||||
@@ -31,10 +31,10 @@ verify = [] # Verify numeric in
|
||||
default = ["std", "serde"]
|
||||
|
||||
[dependencies]
|
||||
generic-array = "1.0.0"
|
||||
serde = { optional = true, version = "1", default-features = false }
|
||||
time = { version = "0.3", default-features = false, features = ["macros"] }
|
||||
bytes = { optional = true, version = "1.1.0" }
|
||||
generic-array = "1.0.0"
|
||||
schemars = { optional = true, version = "0.8.8" }
|
||||
rusqlite = { optional = true, version = "0.32", default-features = false }
|
||||
postgres-types = { optional = true, version = "0.2.2", features = ["with-time-0_3"], default-features = false }
|
||||
@@ -42,7 +42,7 @@ postgres-protocol = { optional = true, version = "0.6", default-features = false
|
||||
diesel = { optional = true, version = "2", default-features = false, features = ["time", "with-deprecated"] }
|
||||
rand = { optional = true, version = "0.8", default-features = false }
|
||||
quickcheck = { optional = true, version = "1.0", default-features = false }
|
||||
worker = { optional = true, version = "0.3.0" }
|
||||
worker = { optional = true, version = "0.4" }
|
||||
js-sys = { optional = true, version = "0.3" }
|
||||
ramhorns = { optional = true, version = "1.0" }
|
||||
fred = { optional = true, version = "9.0", default-features = false }
|
||||
|
||||
+14
-2
@@ -1,15 +1,27 @@
|
||||
//! This example is used to examine generated assembly code via the command:
|
||||
//! ```
|
||||
//! cargo rustc --example ts_asm --release -- -C codegen-units=1 -C opt-level=3 --emit asm
|
||||
//! ```
|
||||
|
||||
use iso8601_timestamp::{formats::*, Timestamp, TimestampStr};
|
||||
use time::Month;
|
||||
|
||||
#[inline(never)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub fn format_iso8601(ts: Timestamp) -> TimestampStr<FullMilliseconds> {
|
||||
ts.format()
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub fn parse_iso8601(ts: &str) -> Option<Timestamp> {
|
||||
Timestamp::parse(ts)
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[unsafe(no_mangle)]
|
||||
pub fn to_calendar_date(ts: Timestamp) -> (i32, Month, u8) {
|
||||
ts.to_calendar_date()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "stable"
|
||||
+15
-17
@@ -98,33 +98,28 @@ impl From<PrimitiveDateTime> for Timestamp {
|
||||
// SystemTime::now() is not implemented on wasm32
|
||||
#[cfg(all(feature = "std", not(any(target_arch = "wasm64", target_arch = "wasm32"))))]
|
||||
impl Timestamp {
|
||||
/// Get the current time, assuming UTC
|
||||
///
|
||||
/// # Panics
|
||||
/// This will panic if the System Time is before the Unix Epoch.
|
||||
/// Get the current time, assuming UTC.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn now_utc() -> Self {
|
||||
Timestamp(
|
||||
*Self::UNIX_EPOCH
|
||||
+ SystemTime::UNIX_EPOCH
|
||||
.elapsed()
|
||||
.expect("SystemTime before UNIX_EPOCH"),
|
||||
)
|
||||
Timestamp::from(SystemTime::now())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "worker", target_arch = "wasm32", not(feature = "js")))]
|
||||
impl Timestamp {
|
||||
/// Get the current time, assuming UTC
|
||||
#[inline]
|
||||
/// Get the current time, assuming UTC.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the current time is before the UNIX Epoch.
|
||||
#[must_use]
|
||||
pub fn now_utc() -> Self {
|
||||
match Timestamp::UNIX_EPOCH
|
||||
.checked_add(Duration::milliseconds(worker::Date::now().as_millis() as i64))
|
||||
{
|
||||
Some(ts) => ts,
|
||||
None => unreachable!("Invalid Date::now() value"),
|
||||
None => panic!("Invalid Date::now() value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,13 +130,16 @@ impl Timestamp {
|
||||
not(feature = "worker")
|
||||
))]
|
||||
impl Timestamp {
|
||||
/// Get the current time, assuming UTC
|
||||
#[inline]
|
||||
/// Get the current time, assuming UTC.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the current time is before the UNIX Epoch.
|
||||
#[must_use]
|
||||
pub fn now_utc() -> Self {
|
||||
match Timestamp::UNIX_EPOCH.checked_add(Duration::milliseconds(js_sys::Date::now() as i64)) {
|
||||
Some(ts) => ts,
|
||||
None => unreachable!("Invalid Date::now() value"),
|
||||
None => panic!("Invalid Date::now() value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -886,7 +884,7 @@ mod rkyv_08_impl {
|
||||
fn from(value: ArchivedTimestamp) -> Self {
|
||||
Timestamp::UNIX_EPOCH
|
||||
.checked_add(Duration::milliseconds(value.get()))
|
||||
.unwrap_or(Timestamp::UNIX_EPOCH)
|
||||
.unwrap_or(Timestamp::UNIX_EPOCH) // should never fail, but provide a sane fallback anyway
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user