Skip to content

Commit

Permalink
Merge pull request #7 from lucianavlop/price-range-bug
Browse files Browse the repository at this point in the history
Was only highlighting 2 hours instead of 3
  • Loading branch information
lucianavlop authored Apr 27, 2023
2 parents dd3e73f + be4f093 commit 1056ce3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/PriceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ const DailyChart: React.FC<DailyChartProps> = ({
if (!showCheapPeriod) return Array<null>(prices.length).fill(null)

const cp = getCheapestPeriod(prices, 3)
return prices.map(item => {
return prices.map(p => {
const priceHour = new Date(p.dateTime).getHours()
// If the dateTime of item is contained in cp, return the price, else return null
if (cp.find(cpItem => cpItem.dateTime === item.dateTime)) {
return item.price
if (
cp.find(cpItem => {
const cpHour = new Date(cpItem.dateTime).getHours()
return cpHour === priceHour || cpHour + 1 === priceHour
})
) {
return p.price
} else {
return null
}
Expand All @@ -125,10 +131,16 @@ const DailyChart: React.FC<DailyChartProps> = ({
if (!showExpensivePeriod) return Array<null>(prices.length).fill(null)

const ep = getMostExpensivePeriod(prices, 3)
return prices.map(item => {
return prices.map(p => {
const priceHour = new Date(p.dateTime).getHours()
// If the dateTime of item is contained in ep, return the price, else return null
if (ep.find(epItem => epItem.dateTime === item.dateTime)) {
return item.price
if (
ep.find(epItem => {
const cpHour = new Date(epItem.dateTime).getHours()
return cpHour === priceHour || cpHour + 1 === priceHour
})
) {
return p.price
} else {
return null
}
Expand Down

0 comments on commit 1056ce3

Please sign in to comment.