diff --git a/example.js b/example.js index ce66818..e566e97 100644 --- a/example.js +++ b/example.js @@ -2,6 +2,8 @@ const terminalProcedures = require('./') terminalProcedures.fetchCurrentCycle().then(r => console.log(r)) +terminalProcedures.currentCycleEffectiveDates().then(console.log) + // Also try updateing the Flag property to include one or more of the following: // A for only those that were Added since the last effective date // C for only those that were Changed since the last effective date diff --git a/index.js b/index.js index 069d239..c16f9eb 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,9 @@ terminalProcedures.currentCycleEffectiveDates = async () => { .get(BASE_URL) .set('Accept', ACCEPT) - return extractEffectiveDates(cheerio.load(response.text)) + const $ = cheerio.load(response.text) + var currentCycle = $('select#cycle > option:contains(Current)').text() + return parseEffectiveDates(currentCycle.replace(/(\n|\t)/gm, '')) } /** @@ -213,7 +215,14 @@ const extractEffectiveDates = $ => { .split('<')[0] .trim() - const [ startMonthDay, remainder ] = baseEffectiveDateString.split('-') + return parseEffectiveDates(baseEffectiveDateString) +} + +const parseEffectiveDates = str => { + if (!str) { + return null + } + const [ startMonthDay, remainder ] = str.split('-') const [ endMonthDay, yearAndCycle ] = remainder.split(',') const [ year, _ ] = yearAndCycle.split('[') return {