Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: weekday calculation bug #114

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-agent"
version = "2.6.0"
version = "2.6.1"
edition = "2021"

[[bin]]
Expand Down
18 changes: 16 additions & 2 deletions src/agent/market_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl MarketSchedule {
let month = when_local.date_naive().month0() + 1;
let day = when_local.date_naive().day0() + 1;
let time = when_local.time();
let weekday = when_local.weekday().number_from_monday().to_usize();
let weekday0 = when_local.weekday().number_from_monday().to_usize() - 1;
keyvankhademi marked this conversation as resolved.
Show resolved Hide resolved

for holiday in &self.holidays {
// Check if the day matches
Expand All @@ -105,7 +105,12 @@ impl MarketSchedule {
}
}

self.weekly_schedule[weekday].can_publish_at(time)
let day_schedule = self.weekly_schedule.get(weekday0);

match day_schedule {
Some(day_schedule) => day_schedule.can_publish_at(time),
None => false,
}
}
}

Expand Down Expand Up @@ -462,6 +467,15 @@ mod tests {
// Date 2400 range
assert!(market_schedule
.can_publish_at(&NaiveDateTime::parse_from_str("2023-12-31 23:59", format)?.and_utc()));

// Sunday
assert!(market_schedule
.can_publish_at(&NaiveDateTime::parse_from_str("2024-04-14 12:00", format)?.and_utc()));

// Monday
assert!(market_schedule
.can_publish_at(&NaiveDateTime::parse_from_str("2024-04-15 12:00", format)?.and_utc()));

Ok(())
}
}
Expand Down
Loading