Skip to content

Commit

Permalink
Merge pull request #989 from CityOfBoston/DIG-3805
Browse files Browse the repository at this point in the history
DIG-3805: Bug Fix - Incorrect Birthdate Validation
  • Loading branch information
phillipbentonkelly authored Dec 29, 2023
2 parents b188103 + 810a8e4 commit ddb614b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
18 changes: 9 additions & 9 deletions modules-js/react-fleet/src/__snapshots__/Storyshots.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,7 @@ exports[`Storyshots Form Elements|Inputs/TextInput default 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -2624,7 +2624,7 @@ exports[`Storyshots Form Elements|Inputs/TextInput error 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -2694,7 +2694,7 @@ exports[`Storyshots Form Elements|Inputs/TextInput variations 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -2875,7 +2875,7 @@ exports[`Storyshots Form Elements|SelectDropdown default 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -2928,7 +2928,7 @@ exports[`Storyshots Form Elements|SelectDropdown variants 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -4450,7 +4450,7 @@ exports[`Storyshots ProgressBar default 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -4511,7 +4511,7 @@ exports[`Storyshots ProgressBar first step (interactive demo) 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -4572,7 +4572,7 @@ exports[`Storyshots ProgressBar last step (interactive demo) 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -4633,7 +4633,7 @@ exports[`Storyshots ProgressBar with task name 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Props {
handleDate: (newDate: Date | null) => void;
resetDate?: boolean;
disabled?: boolean;
modDateTime?: boolean;
}

interface State {
Expand Down Expand Up @@ -145,7 +146,7 @@ export default class MemorableDateInput extends React.Component<Props, State> {
// date. This lets us show the date constraints while they’re editing.
lastValidityError = this.state.lastValidityError;
} else {
date = fieldsToDate(fields);
date = fieldsToDate(fields, this.props.modDateTime);
lastValidityError = this.isDateValid(date);

if (lastValidityError) {
Expand Down Expand Up @@ -181,7 +182,7 @@ export default class MemorableDateInput extends React.Component<Props, State> {
// don’t disturb inputs if people temporarily make invalid dates while
// editing.
if (!inputCompleteError(fields)) {
const date = fieldsToDate(fields);
const date = fieldsToDate(fields, this.props.modDateTime);
fields = dateToFields(date);
}

Expand Down Expand Up @@ -577,8 +578,19 @@ export function dateValidError(
return errorString;
}

function fieldsToDate({ year, month, day }: Fields): Date {
return new Date(Date.UTC(+year, +month - 1, +day));
function fieldsToDate(
{ year, month, day }: Fields,
modDateTime?: boolean | null
): Date {
let retDate = new Date(Date.UTC(+year, +month - 1, +day));

if (modDateTime && modDateTime === true) {
retDate = new Date(
new Date(Date.UTC(+year, +month - 1, 1 + +day)).setHours(0, 0, 0, 0)
);
}

return retDate;
}

function dateToFields(date: Date): Fields {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39192,7 +39192,7 @@ exports[`Storyshots Common Components/DateRangePicker default 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -39405,7 +39405,7 @@ exports[`Storyshots Common Components/DateRangePicker range too vast 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -39618,7 +39618,7 @@ exports[`Storyshots Common Components/DateRangePicker with values 1`] = `
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -39784,7 +39784,7 @@ exports[`Storyshots Common Components/DateRangePicker/DateComponent default 1`]
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -39887,7 +39887,7 @@ exports[`Storyshots Common Components/DateRangePicker/DateComponent with values
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -41699,7 +41699,7 @@ exports[`Storyshots Common Components/Question Components/AltSpellings default 1
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down Expand Up @@ -41848,7 +41848,7 @@ exports[`Storyshots Common Components/Question Components/AltSpellings with exis
style={
Object {
"margin": "2rem auto",
"maxWidth": "600px",
"maxWidth": "768px",
}
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export default class PersonalInformation extends Component<Props> {
onlyAllowPast={true}
earliestDate={EARLIEST_DATE}
handleDate={this.handleDateChange}
modDateTime={true}
/>
</div>

Expand All @@ -145,15 +146,15 @@ export default class PersonalInformation extends Component<Props> {
private renderRecentBirthWarningText(): ReactChild {
const { birthCertificateRequest } = this.props;
const { birthDate } = birthCertificateRequest.requestInformation;
const pickUpDate = getPickUpDate(birthDate);
return (
<div className={NOTE_BOX_CLASSNAME} style={{ paddingBottom: 0 }}>
<h2 className="h3 tt-u">Birth Certificate is Being Processed</h2>
<p>
Birth information takes up to two weeks to arrive from a hospital to
the City of Boston. Please submit an order after{' '}
<span css={PICKUP_DATE_STYLE}>{getPickUpDate(birthDate)}</span>. We
apologize for the inconvenience. If you have any questions or
concerns, please{' '}
<span css={PICKUP_DATE_STYLE}>{pickUpDate}</span>. We apologize for
the inconvenience. If you have any questions or concerns, please{' '}
<a
href="https://www.boston.gov/still-have-questions-registry"
target="_blank"
Expand Down
5 changes: 5 additions & 0 deletions services-js/registry-certs/lib/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ describe('getPickUpDate', () => {
const expect12152023: Date = new Date('Mon Dec 01 2023');
expect(getPickUpDate(expect12152023)).toBe('12/15/2023');
});

it('Registry Cert Pickup Date - 12/18/2023 + 14 days = 01/01/2024', () => {
const expect01012024: Date = new Date('Mon Dec 18 2023');
expect(getPickUpDate(expect01012024)).toBe('1/1/2024');
});
});

0 comments on commit ddb614b

Please sign in to comment.