Skip to content

Commit

Permalink
fix: Fix leap-day check in UniformDrawnProfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
jetuk committed Oct 15, 2024
1 parent 029c1c8 commit ed6fc5e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pywr-core/src/parameters/profiles/uniform_drawdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ impl SimpleParameter<f64> for UniformDrawdownProfileParameter {
// Current calendar year (might be adjusted depending on position of reset day)
let mut year = timestep.date.year();

// Zero-base current day of the year.
// Current day of the year.
let current_doy = timestep.date.ordinal();
let mut days_into_period: i32 = current_doy as i32 - self.reset_doy as i32;
if days_into_period < 0 {
// We're not past the reset day yet; use the previous year
year -= 1
}

if self.reset_doy > 59 {
if self.reset_doy > 60 {
year += 1
}

Expand All @@ -66,8 +66,8 @@ impl SimpleParameter<f64> for UniformDrawdownProfileParameter {
if days_into_period < 0 {
days_into_period += 366;
// Need to adjust for post 29th Feb in non-leap years.
// Recall `current_doy` was incremented by 1 if it is a non-leap already (hence comparison to 59)
if !is_leap_year(timestep.date.year()) && current_doy > 59 {
// Recall `current_doy` was incremented by 1 if it is a non-leap already (hence comparison to 60)
if !is_leap_year(timestep.date.year()) && current_doy > 60 {
days_into_period -= 1;
}
}
Expand Down

0 comments on commit ed6fc5e

Please sign in to comment.