Skip to content

Commit

Permalink
Merge pull request #8 from FAA-Aviation-Data-Portal/happy-new-year
Browse files Browse the repository at this point in the history
Fix effectiveStartDate being after effectiveEndDate
  • Loading branch information
corys authored Jan 26, 2022
2 parents 82fce52 + 7b0de98 commit 3f62562
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,16 @@ const parseEffectiveDates = str => {
const [ year, _ ] = yearAndCycle.split('[')

const effectiveStartDate = new Date(`${startMonthDay.trim()} ${year}`)
effectiveStartDate.setUTCHours(0,0,0,0)

const effectiveEndDate = new Date(`${endMonthDay.trim()} ${year}`)

// If effectiveStartDate does not have a year specified,
// it will default to the same year as effectiveEndDate.
// So if the date range spans Jan 1, roll effectiveStartDate back one year.
if (effectiveStartDate > effectiveEndDate) {
effectiveStartDate.setFullYear(effectiveStartDate.getFullYear() - 1 );
}

effectiveStartDate.setUTCHours(0,0,0,0)
effectiveEndDate.setUTCHours(0,0,0,0)

return { effectiveStartDate, effectiveEndDate }
Expand Down

0 comments on commit 3f62562

Please sign in to comment.