// yt - A fully featured command line YouTube client // // Copyright (C) 2025 Benedikt Peetz // SPDX-License-Identifier: GPL-3.0-or-later // // This file is part of Yt. // // You should have received a copy of the License along with this program. // If not, see . use std::fmt::Display; use chrono::{DateTime, Utc}; use crate::storage::sql::insert::Transactionable; pub(crate) struct TxnLog { inner: Vec<(TimeStamp, O)>, } impl TxnLog { pub(crate) fn new(inner: Vec<(TimeStamp, O)>) -> Self { Self { inner } } pub(crate) fn inner(&self) -> &[(TimeStamp, O)] { &self.inner } } /// An UNIX time stamp. #[derive(Debug, Default, Clone, Copy)] pub(crate) struct TimeStamp { value: i64, } impl TimeStamp { /// Return the seconds since the UNIX epoch for this [`TimeStamp`]. #[must_use] pub(crate) fn as_secs(self) -> i64 { self.value } /// Construct a [`TimeStamp`] from a count of seconds since the UNIX epoch. #[must_use] pub(crate) fn from_secs(value: i64) -> Self { Self { value } } /// Construct a [`TimeStamp`] from the current time. #[must_use] pub(crate) fn from_now() -> Self { Self { value: Utc::now().timestamp(), } } } impl Display for TimeStamp { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { DateTime::from_timestamp(self.value, 0) .expect("The timestamps should always be valid") .format("%Y-%m-%d") .fmt(f) } }