Skip to content

Commit 00d31d1

Browse files
fix: weekday calculation bug (#114)
* fix: fix weekday calculation bug * chore: increase pyth agent version * feat: add test to check sunday * feat: silently ignore weekly_schedule out of bound error * feat: add test for monday
1 parent 920df19 commit 00d31d1

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-agent"
3-
version = "2.6.0"
3+
version = "2.6.1"
44
edition = "2021"
55

66
[[bin]]

src/agent/market_schedule.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl MarketSchedule {
9696
let month = when_local.date_naive().month0() + 1;
9797
let day = when_local.date_naive().day0() + 1;
9898
let time = when_local.time();
99-
let weekday = when_local.weekday().number_from_monday().to_usize();
99+
let weekday0 = when_local.weekday().number_from_monday().to_usize() - 1;
100100

101101
for holiday in &self.holidays {
102102
// Check if the day matches
@@ -105,7 +105,12 @@ impl MarketSchedule {
105105
}
106106
}
107107

108-
self.weekly_schedule[weekday].can_publish_at(time)
108+
let day_schedule = self.weekly_schedule.get(weekday0);
109+
110+
match day_schedule {
111+
Some(day_schedule) => day_schedule.can_publish_at(time),
112+
None => false,
113+
}
109114
}
110115
}
111116

@@ -462,6 +467,15 @@ mod tests {
462467
// Date 2400 range
463468
assert!(market_schedule
464469
.can_publish_at(&NaiveDateTime::parse_from_str("2023-12-31 23:59", format)?.and_utc()));
470+
471+
// Sunday
472+
assert!(market_schedule
473+
.can_publish_at(&NaiveDateTime::parse_from_str("2024-04-14 12:00", format)?.and_utc()));
474+
475+
// Monday
476+
assert!(market_schedule
477+
.can_publish_at(&NaiveDateTime::parse_from_str("2024-04-15 12:00", format)?.and_utc()));
478+
465479
Ok(())
466480
}
467481
}

0 commit comments

Comments
 (0)