Compare commits

..

No commits in common. "c0def257fbddb39cf43881582e60bb8f2973da7a" and "0c77774f34681ed1aa31403db5636578fefa78b3" have entirely different histories.

2 changed files with 5 additions and 10 deletions

View File

@ -24,7 +24,8 @@ impl DateTime {
self.year.get() self.year.get()
} }
fn timestamp_naive(&self) -> i64 { /// Gets the Unix timestamp corresponding to this `DateTime`
pub fn timestamp(&self) -> i64 {
let mut seconds: i64 = 0; let mut seconds: i64 = 0;
let mut year = Year::new(1970); let mut year = Year::new(1970);
if self.year() < 1970 { if self.year() < 1970 {
@ -49,12 +50,6 @@ impl DateTime {
seconds += i64::from(self.hour) * SECONDS_PER_HOUR; seconds += i64::from(self.hour) * SECONDS_PER_HOUR;
seconds += i64::from(self.minute) * SECONDS_PER_MINUTE; seconds += i64::from(self.minute) * SECONDS_PER_MINUTE;
seconds += i64::from(self.second); seconds += i64::from(self.second);
seconds
}
/// Gets the Unix timestamp corresponding to this `DateTime`
pub fn timestamp(&self) -> i64 {
let mut seconds = self.timestamp_naive();
seconds += self.zone.as_seconds(); seconds += self.zone.as_seconds();
seconds seconds
} }
@ -146,7 +141,7 @@ impl DateTime {
} }
pub fn weekday(&self) -> Weekday { pub fn weekday(&self) -> Weekday {
let ts = self.timestamp_naive(); let ts = self.timestamp();
let days = ts / SECONDS_PER_DAY; let days = ts / SECONDS_PER_DAY;
let rem = days % 7; let rem = days % 7;
rem.try_into().unwrap() rem.try_into().unwrap()
@ -283,7 +278,7 @@ mod tests {
#[test] #[test]
fn display() { fn display() {
let mut dt = DateTime::from_timestamp(1706571482); let mut dt = DateTime::from_timestamp(1706571482);
assert_eq!(dt.display(), "Mon Jan 29 23:38:02 UTC 2024"); assert_eq!(dt.display(), "Mon Jan 29 23:38:02 Utc 2024");
dt.zone = TimeZone::Offset { dt.zone = TimeZone::Offset {
sign: crate::zone::Sign::Positive, sign: crate::zone::Sign::Positive,
hours: 4, hours: 4,

View File

@ -97,7 +97,7 @@ impl TimeZone {
pub fn display(&self) -> String { pub fn display(&self) -> String {
match self { match self {
Self::Utc => "UTC".into(), Self::Utc => "Utc".into(),
_ => format!("{self}"), _ => format!("{self}"),
} }
} }