feat: moved the timestamp function to lib

This commit is contained in:
silver 2023-07-30 01:32:01 +01:00
parent 4ce3e94c36
commit 72776a967a
4 changed files with 17 additions and 13 deletions

View file

@ -6,6 +6,7 @@ use sqlx::{Error, Pool, Sqlite};
use std::env;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use chrono::{Datelike, SecondsFormat, Utc};
use tide::prelude::*;
#[derive(Debug, Deserialize, Serialize, sqlx::FromRow)]
@ -111,6 +112,15 @@ pub fn get_now() -> i64 {
}
}
pub fn get_now_iso(short: bool) -> String {
let now = Utc::now();
if short {
format!("{}-{:02}-{:02}", now.year(), now.month(), now.day())
} else {
now.to_rfc3339_opts(SecondsFormat::Millis, true)
}
}
#[derive(Clone)]
pub struct State {
pub db: Pool<Sqlite>,