Add Time::new constructor

This commit is contained in:
Joscha 2023-01-20 17:11:00 +01:00
parent 142cdfab1c
commit 470f3455f7
2 changed files with 11 additions and 2 deletions

View file

@ -15,6 +15,7 @@ Procedure when bumping the version number:
### Added
- `Status` conversion utility methods
- `Time::new` constructor
## v0.2.0 - 2022-12-10

View file

@ -12,7 +12,7 @@ use std::{error, fmt};
use serde::{de, ser, Deserialize, Serialize};
use serde_json::Value;
use time::OffsetDateTime;
use time::{OffsetDateTime, UtcOffset};
/// Describes an account and its preferred name.
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -406,8 +406,16 @@ impl<'de> Deserialize<'de> for Snowflake {
pub struct Time(#[serde(with = "time::serde::timestamp")] pub OffsetDateTime);
impl Time {
pub fn new(time: OffsetDateTime) -> Self {
let time = time
.to_offset(UtcOffset::UTC)
.replace_millisecond(0)
.unwrap();
Self(time)
}
pub fn now() -> Self {
Self(OffsetDateTime::now_utc().replace_millisecond(0).unwrap())
Self::new(OffsetDateTime::now_utc())
}
}