@defra/fcp-sfd-frontend-engine 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -914,6 +914,21 @@ var formatDateInputValues = (payloadDob, changedDob, originalDob) => {
914
914
  year: formatDatePart(changedDob == null ? void 0 : changedDob.year, originalDob == null ? void 0 : originalDob.year)
915
915
  };
916
916
  };
917
+ var formatLongDate = (date) => {
918
+ if (date === null || date === void 0 || date === "") {
919
+ return null;
920
+ }
921
+ const localDate = new Date(date);
922
+ if (Number.isNaN(localDate.getTime())) {
923
+ return null;
924
+ }
925
+ return localDate.toLocaleDateString("en-GB", {
926
+ day: "numeric",
927
+ month: "long",
928
+ year: "numeric",
929
+ timeZone: "UTC"
930
+ });
931
+ };
917
932
  var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
918
933
  const sortedErrors = [];
919
934
  for (const section of orderedSectionsToFix) {
@@ -1090,6 +1105,7 @@ var presenters = {
1090
1105
  formatBackLink,
1091
1106
  formatNumber,
1092
1107
  formatDateInputValues,
1108
+ formatLongDate,
1093
1109
  formatDisplayAddress,
1094
1110
  formatOriginalAddress,
1095
1111
  formatChangedAddress,
package/dist/index.js CHANGED
@@ -873,6 +873,21 @@ var formatDateInputValues = (payloadDob, changedDob, originalDob) => {
873
873
  year: formatDatePart(changedDob == null ? void 0 : changedDob.year, originalDob == null ? void 0 : originalDob.year)
874
874
  };
875
875
  };
876
+ var formatLongDate = (date) => {
877
+ if (date === null || date === void 0 || date === "") {
878
+ return null;
879
+ }
880
+ const localDate = new Date(date);
881
+ if (Number.isNaN(localDate.getTime())) {
882
+ return null;
883
+ }
884
+ return localDate.toLocaleDateString("en-GB", {
885
+ day: "numeric",
886
+ month: "long",
887
+ year: "numeric",
888
+ timeZone: "UTC"
889
+ });
890
+ };
876
891
  var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
877
892
  const sortedErrors = [];
878
893
  for (const section of orderedSectionsToFix) {
@@ -1049,6 +1064,7 @@ var presenters = {
1049
1064
  formatBackLink,
1050
1065
  formatNumber,
1051
1066
  formatDateInputValues,
1067
+ formatLongDate,
1052
1068
  formatDisplayAddress,
1053
1069
  formatOriginalAddress,
1054
1070
  formatChangedAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Shared frontend engine used by both the internal and external frontend applications.",
5
5
  "main": "./dist/index.cjs",
6
6
  "exports": {
@@ -69,6 +69,31 @@ export const formatDateInputValues = (payloadDob, changedDob, originalDob) => {
69
69
  }
70
70
  }
71
71
 
72
+ /**
73
+ * Formats a date as a long-form UK date string, e.g. "5 April 1990".
74
+ * Accepts a Date object or any value that can be passed to new Date().
75
+ * Returns null if no date is provided.
76
+ */
77
+ export const formatLongDate = (date) => {
78
+ if (date === null || date === undefined || date === '') {
79
+ return null
80
+ }
81
+
82
+ const localDate = new Date(date)
83
+
84
+ // new Date() on an unrecognisable value doesn't throw, it just produces NaN when you call getTime()
85
+ if (Number.isNaN(localDate.getTime())) {
86
+ return null
87
+ }
88
+
89
+ return localDate.toLocaleDateString('en-GB', {
90
+ day: 'numeric',
91
+ month: 'long',
92
+ year: 'numeric',
93
+ timeZone: 'UTC'
94
+ })
95
+ }
96
+
72
97
  /**
73
98
  * Shared helper used by base presenters to sort validation errors so they
74
99
  * appear in the same order as the sections and fields shown on a Fix List page.
@@ -2,6 +2,7 @@ import {
2
2
  formatBackLink,
3
3
  formatNumber,
4
4
  formatDateInputValues,
5
+ formatLongDate,
5
6
  sortErrorsBySectionOrder
6
7
  } from './base-presenter.js'
7
8
 
@@ -25,6 +26,7 @@ export const presenters = {
25
26
  formatBackLink,
26
27
  formatNumber,
27
28
  formatDateInputValues,
29
+ formatLongDate,
28
30
  formatDisplayAddress,
29
31
  formatOriginalAddress,
30
32
  formatChangedAddress,