1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use chrono::{offset::LocalResult, DateTime, TimeZone, Utc};

use crate::browser::info::BrowserTime;

// pub mod passwd;
pub mod cookie;

// reference: https://support.moonpoint.com/network/web/browser/firefox/sqlite_cookies.php
pub(super) trait I64ToMozTime: BrowserTime {
    fn micros_to_moz_utc(&self) -> Option<DateTime<Utc>>;
    fn secs_to_moz_utc(&self) -> Option<DateTime<Utc>>;
}

impl I64ToMozTime for i64 {
    fn micros_to_moz_utc(&self) -> Option<DateTime<Utc>> {
        match Utc.timestamp_micros(*self) {
            LocalResult::Single(time) => Some(time),
            LocalResult::Ambiguous(..) | LocalResult::None => None,
        }
    }
    fn secs_to_moz_utc(&self) -> Option<DateTime<Utc>> {
        match Utc.timestamp_opt(*self, 0) {
            LocalResult::Single(time) => Some(time),
            LocalResult::Ambiguous(..) | LocalResult::None => None,
        }
    }
}