mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 18:15:39 +00:00
captcha stats
This commit is contained in:
17
src/date.rs
17
src/date.rs
@@ -14,12 +14,23 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use std::fmt::Debug;
|
||||
|
||||
use sqlx::types::time::OffsetDateTime;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Date {
|
||||
pub time: OffsetDateTime,
|
||||
}
|
||||
|
||||
impl Debug for Date {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Date")
|
||||
.field("time", &self.print_date())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub const MINUTE: i64 = 60;
|
||||
pub const HOUR: i64 = MINUTE * 60;
|
||||
pub const DAY: i64 = HOUR * 24;
|
||||
@@ -45,9 +56,15 @@ impl Date {
|
||||
}
|
||||
}
|
||||
|
||||
/// print relative time from date
|
||||
pub fn print_date(&self) -> String {
|
||||
Self::format(&self.time)
|
||||
}
|
||||
|
||||
/// print date
|
||||
pub fn date(&self) -> String {
|
||||
self.time.format("%F %r %z")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user