|
|
@ -14,7 +14,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
|
|
|
|
|
|
|
|
use chrono::{DateTime, TimeZone, Utc};
|
|
|
|
use chrono::{DateTime, TimeZone, Utc};
|
|
|
|
use itertools::Itertools;
|
|
|
|
use itertools::Itertools;
|
|
|
|
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
use js_sys::Date;
|
|
|
|
use js_sys::Date;
|
|
|
|
use miette::{bail, ensure, miette, Result};
|
|
|
|
use miette::{bail, ensure, miette, Result};
|
|
|
|
use num_traits::FloatConst;
|
|
|
|
use num_traits::FloatConst;
|
|
|
@ -1486,13 +1486,13 @@ pub(crate) fn op_to_uuid(args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define_op!(OP_NOW, 0, false);
|
|
|
|
define_op!(OP_NOW, 0, false);
|
|
|
|
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
pub(crate) fn op_now(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
pub(crate) fn op_now(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
let d: f64 = Date::now() / 1000.;
|
|
|
|
let d: f64 = Date::now() / 1000.;
|
|
|
|
Ok(DataValue::from(d))
|
|
|
|
Ok(DataValue::from(d))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
pub(crate) fn op_now(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
pub(crate) fn op_now(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
let now = SystemTime::now();
|
|
|
|
let now = SystemTime::now();
|
|
|
|
Ok(DataValue::from(
|
|
|
|
Ok(DataValue::from(
|
|
|
@ -1501,12 +1501,12 @@ pub(crate) fn op_now(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn current_validity() -> ValidityTs {
|
|
|
|
pub(crate) fn current_validity() -> ValidityTs {
|
|
|
|
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
let ts_micros = {
|
|
|
|
let ts_micros = {
|
|
|
|
let now = SystemTime::now();
|
|
|
|
let now = SystemTime::now();
|
|
|
|
now.duration_since(UNIX_EPOCH).unwrap().as_micros() as i64
|
|
|
|
now.duration_since(UNIX_EPOCH).unwrap().as_micros() as i64
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
let ts_micros = { (Date::now() * 1000.) as i64 };
|
|
|
|
let ts_micros = { (Date::now() * 1000.) as i64 };
|
|
|
|
|
|
|
|
|
|
|
|
ValidityTs(Reverse(ts_micros))
|
|
|
|
ValidityTs(Reverse(ts_micros))
|
|
|
@ -1575,14 +1575,14 @@ define_op!(OP_RAND_UUID_V1, 0, false);
|
|
|
|
pub(crate) fn op_rand_uuid_v1(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
pub(crate) fn op_rand_uuid_v1(_args: &[DataValue]) -> Result<DataValue> {
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let uuid_ctx = uuid::v1::Context::new(rng.gen());
|
|
|
|
let uuid_ctx = uuid::v1::Context::new(rng.gen());
|
|
|
|
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
let ts = {
|
|
|
|
let ts = {
|
|
|
|
let since_epoch: f64 = Date::now();
|
|
|
|
let since_epoch: f64 = Date::now();
|
|
|
|
let seconds = since_epoch.floor();
|
|
|
|
let seconds = since_epoch.floor();
|
|
|
|
let fractional = (since_epoch - seconds) * 1.0e9;
|
|
|
|
let fractional = (since_epoch - seconds) * 1.0e9;
|
|
|
|
Timestamp::from_unix(uuid_ctx, seconds as u64, fractional as u32)
|
|
|
|
Timestamp::from_unix(uuid_ctx, seconds as u64, fractional as u32)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
let ts = {
|
|
|
|
let ts = {
|
|
|
|
let now = SystemTime::now();
|
|
|
|
let now = SystemTime::now();
|
|
|
|
let since_epoch = now.duration_since(UNIX_EPOCH).unwrap();
|
|
|
|
let since_epoch = now.duration_since(UNIX_EPOCH).unwrap();
|
|
|
|