Skip to content

Commit

Permalink
[ASL-4592] Previous project expiry allows invalid date (#960)
Browse files Browse the repository at this point in the history
* Make format date more resilient

* [ASL-4592] Update message to prevent confusion from unintuitive ordering of the raw date

* npm version
  • Loading branch information
jeff-horton-ho-sas authored Nov 6, 2024
1 parent 8fe90dc commit bc45dd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions client/components/download-link/renderers/docx-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import isNull from 'lodash/isNull';
import get from 'lodash/get';
import pickBy from 'lodash/pickBy';
import mapValues from 'lodash/mapValues';
import { format } from 'date-fns';
import { projectSpecies as SPECIES } from '@ukhomeoffice/asl-constants';
import { getLegacySpeciesLabel, mapSpecies, stripInvalidXmlChars } from '../../../helpers';
import { getLegacySpeciesLabel, mapSpecies, stripInvalidXmlChars, formatDate } from '../../../helpers';
import { DATE_FORMAT } from '../../../constants';
import { filterSpeciesByActive } from '../../../pages/sections/protocols/animals';
import protocolConditions from '../../../constants/protocol-conditions';
import { getRepeatedFromProtocolIndex, hydrateSteps } from '../../../helpers/steps';
Expand Down Expand Up @@ -698,7 +698,7 @@ export default (application, sections, values, updateImageDimensions) => {
return (value || []).map(item => renderFields(doc, field, item, field.fields, project));

case 'date':
return renderText(doc, format(value, 'dd/MM/yyyy'));
return renderText(doc, formatDate(value, DATE_FORMAT.long));

case 'location-selector':
case 'objective-selector':
Expand Down
8 changes: 7 additions & 1 deletion client/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import LEGACY_SPECIES from '../constants/legacy-species';
import {projectSpecies as SPECIES} from '@ukhomeoffice/asl-constants';
import CONDITIONS from '../constants/conditions';

export const formatDate = (date, format) => (date ? dateFormatter(date, format) : '-');
export const formatDate = (date, format) => {
try {
return date ? dateFormatter(date, format) : '-';
} catch (err) {
return `Invalid date entered`;
}
};

export const getConditions = (values, project) => {
const isProtocol = !!project;
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asl/projects",
"version": "15.6.11",
"version": "15.6.12",
"description": "ASL PPL prototype",
"main": "client/external.js",
"styles": "assets/scss/projects.scss",
Expand Down

0 comments on commit bc45dd0

Please sign in to comment.