Skip to content

Commit

Permalink
Prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
sbimochan committed Feb 3, 2019
1 parent b70bb65 commit b7d6284
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
dateList
dateList
} from './dateList';
/**
* @param {string} inputDate
Expand All @@ -11,55 +11,55 @@ export default function fiscalCalculator(inputDate) {
* Only checking if it contains hyphen, first is 4 digit and a string
* Should I use moment isValid? 🤔
*/
if (inputDate.indexOf('-') === 4 && typeof inputDate === 'string') {
return manipulateDate(inputDate);
} else {
throw new TypeError('Date is not in right format.');
}
if (inputDate.indexOf('-') === 4 && typeof inputDate === 'string') {
return manipulateDate(inputDate);
} else {
throw new TypeError('Date is not in right format.');
}
}

function manipulateDate(inputDate) {
let splittedDate = {};
const splittedIntDate = inputDate
.split('-')
.map(stringDate => parseInt(stringDate));
let splittedDate = {};
const splittedIntDate = inputDate
.split('-')
.map(stringDate => parseInt(stringDate));

splittedDate.year = splittedIntDate[0];
splittedDate.month = splittedIntDate[1];
splittedDate.day = splittedIntDate[2];
const nextFiscalExpireDate = fiscalMachine(splittedDate);
splittedDate.year = splittedIntDate[0];
splittedDate.month = splittedIntDate[1];
splittedDate.day = splittedIntDate[2];
const nextFiscalExpireDate = fiscalMachine(splittedDate);

return nextFiscalExpireDate;
return nextFiscalExpireDate;
}

function fiscalMachine(splittedDate) {
let fiscalYear;
switch (true) {
case splittedDate.month > 7:
fiscalYear = splittedDate.year + 1;
break;
let fiscalYear;
switch (true) {
case splittedDate.month > 7:
fiscalYear = splittedDate.year + 1;
break;

case splittedDate.month >= 7 &&
splittedDate.day > dateList[splittedDate.year]:
fiscalYear = splittedDate.year + 1;
break;
case splittedDate.month >= 7 &&
splittedDate.day > dateList[splittedDate.year]:
fiscalYear = splittedDate.year + 1;
break;

case splittedDate.month >= 7 &&
splittedDate.day === dateList[splittedDate.year]:
fiscalYear = splittedDate.year + 1;
break;
case splittedDate.month >= 7 &&
splittedDate.day === dateList[splittedDate.year]:
fiscalYear = splittedDate.year + 1;
break;

case splittedDate.month >= 7 &&
splittedDate.day < dateList[splittedDate.year]:
fiscalYear = splittedDate.year;
break;
case splittedDate.month >= 7 &&
splittedDate.day < dateList[splittedDate.year]:
fiscalYear = splittedDate.year;
break;

default:
fiscalYear = splittedDate.year;
break;
}
const fiscalDay = dateList[fiscalYear];
const nextFiscalExpireDate = `${fiscalYear}-07-${fiscalDay}`;
default:
fiscalYear = splittedDate.year;
break;
}
const fiscalDay = dateList[fiscalYear];
const nextFiscalExpireDate = `${fiscalYear}-07-${fiscalDay}`;

return nextFiscalExpireDate;
return nextFiscalExpireDate;
}

0 comments on commit b7d6284

Please sign in to comment.