rainbeam_shared/
lib.rs

1//! Xsu Utilities
2#![doc = include_str!("../README.md")]
3#![doc(issue_tracker_base_url = "https://github.com/swmff/rainbeam/issues/")]
4pub mod fs;
5pub mod hash;
6pub mod process;
7pub mod snow;
8pub mod ui;
9pub mod config;
10
11// ...
12use std::time::{SystemTime, UNIX_EPOCH};
13use chrono::{TimeZone, Utc};
14
15/// Get a [`u128`] timestamp
16pub fn unix_epoch_timestamp() -> u128 {
17    let right_now = SystemTime::now();
18    let time_since = right_now
19        .duration_since(UNIX_EPOCH)
20        .expect("Time travel is not allowed");
21
22    time_since.as_millis()
23}
24
25/// Get a [`i64`] timestamp from the given `year` epoch
26pub fn epoch_timestamp(year: i32) -> i64 {
27    let now = Utc::now().timestamp_millis();
28    let then = Utc
29        .with_ymd_and_hms(year, 1, 1, 0, 0, 0)
30        .unwrap()
31        .timestamp_millis();
32
33    now - then
34}