Compare commits
No commits in common. "c0def257fbddb39cf43881582e60bb8f2973da7a" and "0c77774f34681ed1aa31403db5636578fefa78b3" have entirely different histories.
c0def257fb
...
0c77774f34
@ -24,7 +24,8 @@ impl DateTime {
|
||||
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 year = Year::new(1970);
|
||||
if self.year() < 1970 {
|
||||
@ -49,12 +50,6 @@ impl DateTime {
|
||||
seconds += i64::from(self.hour) * SECONDS_PER_HOUR;
|
||||
seconds += i64::from(self.minute) * SECONDS_PER_MINUTE;
|
||||
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
|
||||
}
|
||||
@ -146,7 +141,7 @@ impl DateTime {
|
||||
}
|
||||
|
||||
pub fn weekday(&self) -> Weekday {
|
||||
let ts = self.timestamp_naive();
|
||||
let ts = self.timestamp();
|
||||
let days = ts / SECONDS_PER_DAY;
|
||||
let rem = days % 7;
|
||||
rem.try_into().unwrap()
|
||||
@ -283,7 +278,7 @@ mod tests {
|
||||
#[test]
|
||||
fn display() {
|
||||
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 {
|
||||
sign: crate::zone::Sign::Positive,
|
||||
hours: 4,
|
||||
|
@ -97,7 +97,7 @@ impl TimeZone {
|
||||
|
||||
pub fn display(&self) -> String {
|
||||
match self {
|
||||
Self::Utc => "UTC".into(),
|
||||
Self::Utc => "Utc".into(),
|
||||
_ => format!("{self}"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user