2023-05-26 19:28:34 +09:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
2022-02-10 04:50:46 +09:00
|
|
|
use chrono::{Duration, Utc};
|
2022-02-06 21:42:48 +09:00
|
|
|
use napi::bindgen_prelude::*;
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
fn date_to_number(input: Date) -> Result<f64> {
|
|
|
|
input.value_of()
|
|
|
|
}
|
2022-02-10 04:50:46 +09:00
|
|
|
|
|
|
|
#[napi]
|
|
|
|
fn chrono_date_to_millis(input: chrono::DateTime<Utc>) -> i64 {
|
|
|
|
input.timestamp_millis()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
fn chrono_date_add_1_minute(input: chrono::DateTime<Utc>) -> chrono::DateTime<Utc> {
|
2024-03-20 22:37:08 +09:00
|
|
|
Duration::try_minutes(1).map(|d| input + d).unwrap()
|
2022-02-10 04:50:46 +09:00
|
|
|
}
|
2022-02-11 02:52:57 +09:00
|
|
|
|
|
|
|
#[napi(object)]
|
|
|
|
pub struct Dates {
|
|
|
|
pub start: chrono::DateTime<Utc>,
|
|
|
|
pub end: Option<chrono::DateTime<Utc>>,
|
|
|
|
}
|
2023-05-26 19:28:34 +09:00
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub fn chrono_native_date_time(date: chrono::NaiveDateTime) -> i64 {
|
2024-03-20 22:37:08 +09:00
|
|
|
date.and_utc().timestamp_millis()
|
2023-05-26 19:28:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub fn chrono_native_date_time_return() -> Option<chrono::NaiveDateTime> {
|
|
|
|
chrono::NaiveDateTime::from_str("2016-12-23T15:25:59.325").ok()
|
|
|
|
}
|