Skip to content

Commit

Permalink
Modify formatDate to return null on invalid Date object
Browse files Browse the repository at this point in the history
  • Loading branch information
crablab committed Jul 29, 2020
1 parent da3cefc commit 6aa2351
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { APPLICATION_STATUS } from '@/helpers/constants';
const formatDate = (value, type) => {
if (value) {
const objDate = new Date(Date.parse(value));

// If not a valid date
if (!(objDate instanceof Date)){
return null;
}

switch (type) {
case 'month':
return `${objDate.toLocaleString('en-GB', { month: 'long' })} ${objDate.getUTCFullYear()}`;
Expand Down
4 changes: 2 additions & 2 deletions src/views/Exercises/Applications/Application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<h2
class="govuk-heading-m govuk-!-margin-bottom-0"
>
{{ application.createdAt | showAlternative("Unknown") | formatDate }}
{{ application.createdAt | formatDate | showAlternative("Unknown")}}
</h2>
</div>
</div>
Expand All @@ -88,7 +88,7 @@
v-if="isApplied"
class="govuk-heading-m govuk-!-margin-bottom-0"
>
{{ application.createdAt | showAlternative("Unknown") | formatDate }}
{{ application.appliedAt | formatDate | showAlternative("Unknown") }}
</h2>
<h2
v-else
Expand Down

0 comments on commit 6aa2351

Please sign in to comment.