Fix Weekday calculation to skip using TimeZone when converting DateTime to timestamp, so that the calculated weekday will match local time rather than UTC.
This commit is contained in:
parent
0c77774f34
commit
3594cfafdf
@ -24,8 +24,7 @@ impl DateTime {
|
|||||||
self.year.get()
|
self.year.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the Unix timestamp corresponding to this `DateTime`
|
fn timestamp_naive(&self) -> i64 {
|
||||||
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 {
|
||||||
@ -50,6 +49,12 @@ 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
|
||||||
}
|
}
|
||||||
@ -141,7 +146,7 @@ impl DateTime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn weekday(&self) -> Weekday {
|
pub fn weekday(&self) -> Weekday {
|
||||||
let ts = self.timestamp();
|
let ts = self.timestamp_naive();
|
||||||
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user