Skip to content

Commit

Permalink
Remove Date object from formatDate
Browse files Browse the repository at this point in the history
  • Loading branch information
derekhouck committed Sep 6, 2024
1 parent a8b7619 commit f4446a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ const extractAdditionalFields = entity => {
};
const extractForms = resultObject => resultObject?.data?.nodeQuery?.entities;

const formatDate = dateString =>
// Depending on what time zone our servers operate on, we may need to adjust
// this offset.
new Date(Date.parse(`${dateString}T04:00-05:00`)).toLocaleDateString();
const formatDate = dateString => {
const removeLeadingZero = s => s.replace(/^0+/, '');
const [year, month, day] = dateString.split('-');
return `${removeLeadingZero(month)}/${removeLeadingZero(day)}/${year}`;
};

const normalizeChapter = ({ entity }) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ describe('postProcessDigitalForm', () => {
};

context('with a well-formed query result', () => {
const expDate = '2027-01-29';

const twoStepEntity = {
nid: 71004,
entityLabel: 'Form with Two Steps',
fieldVaFormNumber: '222222',
fieldOmbNumber: '1212-1212',
fieldRespondentBurden: 30,
fieldExpirationDate: {
value: '2027-01-29',
value: expDate,
},
fieldChapters: [
{
Expand Down Expand Up @@ -103,9 +105,8 @@ describe('postProcessDigitalForm', () => {

it('includes an OMB info object', () => {
const { ombInfo } = processedResult[1];
const formattedDate = new Date(
Date.parse(`${twoStepEntity.fieldExpirationDate.value}T04:00-05:00`),
).toLocaleDateString();
// expDate is 2027-01-29
const formattedDate = '1/29/2027';

expect(ombInfo.ombNumber).to.eq(twoStepEntity.fieldOmbNumber);
expect(ombInfo.expDate).to.eq(formattedDate);
Expand Down

0 comments on commit f4446a6

Please sign in to comment.