diff --git a/src/apps/investments/client/projects/transformers.js b/src/apps/investments/client/projects/transformers.js
index 9287dae8af3..da9cb0dc201 100644
--- a/src/apps/investments/client/projects/transformers.js
+++ b/src/apps/investments/client/projects/transformers.js
@@ -1,4 +1,7 @@
-const { formatMediumDateTime } = require('../../../../client/utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../../client/utils/date-utils')
const { addressToString } = require('../../../../client/utils/addresses')
@@ -9,7 +12,7 @@ const transformCompanyToListItem = (company) => ({
meta: [
{
label: 'Updated on',
- value: formatMediumDateTime(company.modified_on),
+ value: formatDate(company.modified_on, DATE_FORMAT_MEDIUM_WITH_TIME),
},
{
label: 'Company address',
diff --git a/src/apps/investments/middleware/shared.js b/src/apps/investments/middleware/shared.js
index 1a779b14e00..309353b49d1 100644
--- a/src/apps/investments/middleware/shared.js
+++ b/src/apps/investments/middleware/shared.js
@@ -5,7 +5,10 @@ const { getDitCompany } = require('../../companies/repos')
const { getAdviser } = require('../../adviser/repos')
const { getInvestment } = require('../repos')
const { companies, investments } = require('../../../lib/urls')
-const { formatMediumDateTime } = require('../../../client/utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../client/utils/date-utils')
function getCompanyDetails(req, res, next) {
getDitCompany(req, req.params.companyId)
@@ -82,7 +85,10 @@ async function getInvestmentDetails(req, res, next) {
},
{
label: 'Created on',
- value: formatMediumDateTime(investment.created_on),
+ value: formatDate(
+ investment.created_on,
+ DATE_FORMAT_MEDIUM_WITH_TIME
+ ),
},
...(investment.created_by?.dit_team?.name
? [
diff --git a/src/client/components/AuditHistory/transformers.js b/src/client/components/AuditHistory/transformers.js
index 7748cd3d691..b5ad83b5782 100644
--- a/src/client/components/AuditHistory/transformers.js
+++ b/src/client/components/AuditHistory/transformers.js
@@ -1,7 +1,10 @@
import React from 'react'
import { capitalize, isEmpty, lowerCase } from 'lodash'
-import { formatMediumDateTime } from '../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../utils/date-utils'
import { AUTOMATIC_UPDATE } from './constants'
export const transformFieldName = (fieldName) =>
@@ -24,7 +27,7 @@ const transformChanges = (changes, fieldMapper, excludedFields) =>
}))
const getUpdatedBy = (timestamp, user) => {
- const formattedTime = formatMediumDateTime(timestamp)
+ const formattedTime = formatDate(timestamp, DATE_FORMAT_MEDIUM_WITH_TIME)
const changedBy = user
? isEmpty(user?.name)
? user?.email
diff --git a/src/client/components/Dashboard/my-companies/MyCompaniesTable.jsx b/src/client/components/Dashboard/my-companies/MyCompaniesTable.jsx
index 16fcd7b56ad..8d7433c047a 100644
--- a/src/client/components/Dashboard/my-companies/MyCompaniesTable.jsx
+++ b/src/client/components/Dashboard/my-companies/MyCompaniesTable.jsx
@@ -14,7 +14,7 @@ import Filters from './MyCompaniesFilters'
import { GREY_1, GREY_3, TEXT_COLOUR } from '../../../../client/utils/colours'
import urls from '../../../../lib/urls'
-const { formatMediumDate } = require('../../../utils/date')
+const { formatDate, DATE_FORMAT_MEDIUM } = require('../../../utils/date-utils')
const StyledCellHeader = styled(Table.CellHeader)(
typography.font({ size: 14, weight: 'bold' }),
@@ -100,7 +100,7 @@ function MyCompaniesTable() {
{latestInteraction.date
- ? formatMediumDate(latestInteraction.date)
+ ? formatDate(latestInteraction.date, DATE_FORMAT_MEDIUM)
: '-'}
diff --git a/src/client/components/Dashboard/my-tasks/MyTasksTable.jsx b/src/client/components/Dashboard/my-tasks/MyTasksTable.jsx
index df9240a3721..83f7f5e3f4c 100644
--- a/src/client/components/Dashboard/my-tasks/MyTasksTable.jsx
+++ b/src/client/components/Dashboard/my-tasks/MyTasksTable.jsx
@@ -4,7 +4,7 @@ import { Link, Table } from 'govuk-react'
import styled from 'styled-components'
-import { formatMediumDateParsed } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import urls from '../../../../lib/urls'
import { STATUS } from '../../../modules/Tasks/TaskForm/constants'
@@ -34,9 +34,9 @@ const rows = ({ results }) => {
{task.due_date
- ? formatMediumDateParsed(task.due_date)
+ ? formatDate(task.due_date, DATE_FORMAT_MEDIUM)
: task.dueDate
- ? formatMediumDateParsed(task.dueDate)
+ ? formatDate(task.dueDate, DATE_FORMAT_MEDIUM)
: ''}
diff --git a/src/client/components/InvestmentProjectLocalHeader/index.jsx b/src/client/components/InvestmentProjectLocalHeader/index.jsx
index 7ed649a1e8b..6f9a3aabc13 100644
--- a/src/client/components/InvestmentProjectLocalHeader/index.jsx
+++ b/src/client/components/InvestmentProjectLocalHeader/index.jsx
@@ -6,7 +6,10 @@ import { kebabCase, upperFirst } from 'lodash'
import Timeline from '../Timeline'
-import { formatMediumDateTime } from '../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../utils/date-utils'
import timelineTheme from './timeline-theme'
import urls from '../../../lib/urls'
import { INVESTMENT_PROJECT_STAGES } from '../../modules/Investments/Projects/constants'
@@ -87,7 +90,9 @@ const InvestmentProjectLocalHeader = ({ investment }) => (
{investment.valueComplete ? 'Project valued' : 'Not yet valued'}
- {investment.createdOn ? formatMediumDateTime(investment.createdOn) : ''}
+ {investment.createdOn
+ ? formatDate(investment.createdOn, DATE_FORMAT_MEDIUM_WITH_TIME)
+ : ''}
{investment.createdBy?.ditTeam?.name && (
diff --git a/src/client/filters.js b/src/client/filters.js
index 6a0d303b865..b8e25fff682 100644
--- a/src/client/filters.js
+++ b/src/client/filters.js
@@ -1,7 +1,13 @@
-const { formatLongDate, formatShortDate } = require('./utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_FULL,
+ DATE_FORMAT_MONTH_YEAR,
+} = require('./utils/date-utils')
-const getDateLabel = (value) => (value ? formatLongDate(value) : '')
-const getShortDateLabel = (value) => (value ? formatShortDate(value) : '')
+const getDateLabel = (value) =>
+ value ? formatDate(value, DATE_FORMAT_FULL) : ''
+const getShortDateLabel = (value) =>
+ value ? formatDate(value, DATE_FORMAT_MONTH_YEAR) : ''
export const buildOptionsFilter = ({
options = [],
diff --git a/src/client/modules/Companies/CollectionList/transformers.js b/src/client/modules/Companies/CollectionList/transformers.js
index 8f956c5a292..c7587d72260 100644
--- a/src/client/modules/Companies/CollectionList/transformers.js
+++ b/src/client/modules/Companies/CollectionList/transformers.js
@@ -5,7 +5,11 @@ import urls from '../../../../lib/urls'
import { addressToString } from '../../../utils/addresses'
-const { format, formatMediumDateTime } = require('../../../utils/date')
+const { format } = require('../../../utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../utils/date-utils')
export const transformArchivedToApi = (archivedParam) => {
const archived = Array.isArray(archivedParam)
@@ -79,7 +83,7 @@ const transformCompanyToListItem = ({
return {
id,
subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
+ ? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: urls.companies.detail(id),
diff --git a/src/client/modules/Companies/CompanyActivity/transformers.js b/src/client/modules/Companies/CompanyActivity/transformers.js
index cceb9524f57..5e4906599ce 100644
--- a/src/client/modules/Companies/CompanyActivity/transformers.js
+++ b/src/client/modules/Companies/CompanyActivity/transformers.js
@@ -3,7 +3,7 @@ import Link from '@govuk-react/link'
import { TAGS } from './constants'
import urls from '../../../../lib/urls'
-import { formatMediumDateParsed } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import { truncateData } from '../utils'
import { AdviserResource } from '../../../components/Resource'
import { INTERACTION_NAMES } from '../../../../apps/interactions/constants'
@@ -93,7 +93,8 @@ export const transformInteractionToListItem = (activity) => {
metadata: [
{
label: 'Date',
- value: interaction.date ? formatMediumDateParsed(interaction.date) : '',
+ value:
+ interaction.date && formatDate(interaction.date, DATE_FORMAT_MEDIUM),
},
{
label: verifyLabel(interaction.contacts, 'Contact'),
@@ -116,9 +117,7 @@ export const transformInteractionToListItem = (activity) => {
dataTest: 'activity-kind-label',
},
{
- text: interaction.service
- ? getServiceText(interaction.service?.name)
- : '',
+ text: interaction.service && getServiceText(interaction.service?.name),
colour: 'blue',
dataTest: 'activity-service-label',
},
@@ -135,13 +134,13 @@ export const transformReferralToListItem = (activity) => {
metadata: [
{
label: 'Created on',
- value: formatMediumDateParsed(referral.created_on),
+ value: formatDate(referral.created_on, DATE_FORMAT_MEDIUM),
},
{
label: 'Completed on',
- value: referral.completed_on
- ? formatMediumDateParsed(referral.completed_on)
- : '',
+ value:
+ referral.completed_on &&
+ formatDate(referral.completed_on, DATE_FORMAT_MEDIUM),
},
{
label: 'Sending adviser',
@@ -177,19 +176,22 @@ export const transformInvestmentToListItem = (activity) => {
return {
id: activity.investment.id,
metadata: [
- { label: 'Created Date', value: formatMediumDateParsed(activity.date) },
+ {
+ label: 'Created Date',
+ value: formatDate(activity.date, DATE_FORMAT_MEDIUM),
+ },
{
label: 'Investment Type',
value: activity.investment.investment_type.name,
},
{
label: 'Added by',
- value: activity.investment.created_by
- ? AdviserRenderer({
- adviser: activity.investment.created_by,
- team: activity.investment.created_by.dit_team,
- })
- : '',
+ value:
+ activity.investment.created_by &&
+ AdviserRenderer({
+ adviser: activity.investment.created_by,
+ team: activity.investment.created_by.dit_team,
+ }),
},
{
label: 'Estimated land date',
@@ -234,32 +236,30 @@ export const transformOrderToListItem = (activity) => {
return {
id: activity.order.id,
metadata: [
- { label: 'Date', value: formatMediumDateParsed(activity.date) },
+ { label: 'Date', value: formatDate(activity.date, DATE_FORMAT_MEDIUM) },
{
label: 'Country',
value: activity.order.primary_market.name,
},
- activity.order.uk_region
- ? {
- label: 'UK region',
- value: activity.order.uk_region.name,
- }
- : '',
+ activity.order.uk_region && {
+ label: 'UK region',
+ value: activity.order.uk_region.name,
+ },
{
label: 'Added by',
- value: activity.order.created_by
- ? AdviserRenderer({
- adviser: activity.order.created_by,
- team: activity.order.created_by.dit_team,
- })
- : '',
+ value:
+ activity.order.created_by &&
+ AdviserRenderer({
+ adviser: activity.order.created_by,
+ team: activity.order.created_by.dit_team,
+ }),
},
{
label: 'Company Contact',
value:
activity.order.contact.name + ' ' + activity.order.contact.job_title,
},
- ].filter(({ value }) => Boolean(value)),
+ ].filter((entry) => entry && Boolean(entry.value)),
tags: [
{
text: 'Orders (OMIS)',
@@ -287,7 +287,7 @@ export const transformGreatExportEnquiryToListItem = (activity) => {
return {
id: great.id,
metadata: [
- { label: 'Date', value: formatMediumDateParsed(activity.date) },
+ { label: 'Date', value: formatDate(activity.date, DATE_FORMAT_MEDIUM) },
{
label: 'Contact',
value: formattedContacts([great.contact]),
diff --git a/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/transformers.js b/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/transformers.js
index 3ea57f22091..532d69bfcf3 100644
--- a/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/transformers.js
+++ b/src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/transformers.js
@@ -1,9 +1,5 @@
import { isBoolean, isNumber } from 'lodash'
-import {
- formatMediumDateTimeWithoutParsing,
- isUnparsedDateValid,
-} from '../../../../utils/date'
import { COMPANY_FIELD_NAME_TO_LABEL_MAP, HEADQUARTER_TYPES } from './constants'
import {
ARCHIVED,
@@ -31,17 +27,21 @@ const getValueFromBoolean = (value, field) => {
}
}
-export const getValue = (value, field) =>
- isBoolean(value)
- ? getValueFromBoolean(value, field)
- : isNumber(value)
- ? field === 'Turnover'
- ? currencyGBP(value, {
- maximumSignificantDigits: 2,
- })
- : value.toString()
- : isUnparsedDateValid(value)
- ? formatMediumDateTimeWithoutParsing(value)
- : field === 'Headquarter type'
- ? HEADQUARTER_TYPES[value] || NOT_SET
- : value || NOT_SET
+export const getValue = (value, field) => {
+ if (isBoolean(value)) {
+ return getValueFromBoolean(value, field)
+ }
+
+ if (isNumber(value)) {
+ if (field === 'Turnover') {
+ return currencyGBP(value, { maximumSignificantDigits: 2 })
+ }
+ return value.toString()
+ }
+
+ if (field === 'Headquarter type') {
+ return HEADQUARTER_TYPES[value] || NOT_SET
+ }
+
+ return value || NOT_SET
+}
diff --git a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/transformers.js b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/transformers.js
index 56fe4ab7ee1..15db803eabe 100644
--- a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/transformers.js
+++ b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/transformers.js
@@ -5,7 +5,11 @@ import urls from '../../../../../lib/urls'
import { addressToString } from '../../../../utils/addresses'
-const { format, formatMediumDateTime } = require('../../../../utils/date')
+const { format } = require('../../../../utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../../utils/date-utils')
const transformGlobalHQToListItem = (childCompanyId) => (company) => {
const {
@@ -54,7 +58,7 @@ const transformGlobalHQToListItem = (childCompanyId) => (company) => {
return {
id,
subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
+ ? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: urls.companies.hierarchies.ghq.add(childCompanyId, id),
diff --git a/src/client/modules/Companies/CompanyBusinessDetails/LinkSubsidiary/transformers.js b/src/client/modules/Companies/CompanyBusinessDetails/LinkSubsidiary/transformers.js
index 7cf83e22eac..0d550dc6ee1 100644
--- a/src/client/modules/Companies/CompanyBusinessDetails/LinkSubsidiary/transformers.js
+++ b/src/client/modules/Companies/CompanyBusinessDetails/LinkSubsidiary/transformers.js
@@ -5,7 +5,11 @@ import urls from '../../../../../lib/urls'
import { addressToString } from '../../../../utils/addresses'
-const { format, formatMediumDateTime } = require('../../../../utils/date')
+const { format } = require('../../../../utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../../utils/date-utils')
const isGlobalHQ = (hqId) => hqId == '43281c5e-92a4-4794-867b-b4d5f801e6f3'
@@ -70,7 +74,7 @@ const transformSubsidiaryToListItem = (parentCompanyId) => (company) => {
return {
id,
subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
+ ? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: buildUrl(id, parentCompanyId, headquarter_type),
diff --git a/src/client/modules/Companies/CompanyExports/ExportHistory/tasks.js b/src/client/modules/Companies/CompanyExports/ExportHistory/tasks.js
index 36f58748f99..7d59390903b 100644
--- a/src/client/modules/Companies/CompanyExports/ExportHistory/tasks.js
+++ b/src/client/modules/Companies/CompanyExports/ExportHistory/tasks.js
@@ -1,4 +1,7 @@
-import { formatMediumDateTime } from '../../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../../utils/date-utils'
import { GREEN } from '../../../../utils/colours'
import urls from '../../../../../lib/urls'
import groupExportCountries from '../../../../../lib/group-export-countries'
@@ -48,7 +51,10 @@ function createHistory(item) {
label: 'By',
value: item.history_user?.name ?? 'unknown',
},
- { label: 'Date', value: formatMediumDateTime(item.date) },
+ {
+ label: 'Date',
+ value: formatDate(item.date, DATE_FORMAT_MEDIUM_WITH_TIME),
+ },
],
}
}
@@ -91,7 +97,7 @@ function createInteraction(item) {
return {
headingText: item.subject,
headingUrl: urls.interactions.detail(item.id),
- subheading: `Created ${formatMediumDateTime(item.date)}`,
+ subheading: `Created ${formatDate(item.date, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
badges: [
{
text: 'Interaction',
diff --git a/src/client/modules/Companies/CompanyExports/ExportWins/index.jsx b/src/client/modules/Companies/CompanyExports/ExportWins/index.jsx
index a88abe5e4d7..6827a813c99 100644
--- a/src/client/modules/Companies/CompanyExports/ExportWins/index.jsx
+++ b/src/client/modules/Companies/CompanyExports/ExportWins/index.jsx
@@ -5,7 +5,10 @@ import CompanyExportWins from '../../../../components/Resource/CompanyExportWins
import { WIN_STATUS } from '../../../../modules/ExportWins/Status/constants'
import { createRoleTags } from '../../../ExportWins/Status/utils'
import { currencyGBP } from '../../../../utils/number-utils'
-import { formatShortDate } from '../../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MONTH_YEAR,
+} from '../../../../utils/date-utils'
import { CollectionItem } from '../../../../components'
import { BLACK } from '../../../../utils/colours'
import State from '../../../../components/State'
@@ -44,7 +47,9 @@ export const CompanyExportWinsList = ({ exportWins, currentAdviserId }) =>
},
{
label: 'Date won',
- value: {formatShortDate(item.date)},
+ value: (
+ {formatDate(item.date, DATE_FORMAT_MONTH_YEAR)}
+ ),
},
{
label: 'Type of win',
diff --git a/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js b/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js
index e2d1d26d2c7..b6ed35ded2d 100644
--- a/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js
+++ b/src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers.js
@@ -1,8 +1,6 @@
import { TAGS } from '../../../CompanyActivity/constants'
-import {
- formatMediumDateParsed,
- isDateInFuture,
-} from '../../../../../utils/date'
+import { isDateInFuture } from '../../../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../../../utils/date-utils'
import { truncateData } from '../../../../../utils/truncate'
import { INTERACTION_NAMES } from '../../../../../../apps/interactions/constants'
import urls from '../../../../../../lib/urls'
@@ -78,7 +76,7 @@ export const transformReferralToListItem = (activity) => {
const summary = `Company was referred to ${referral.recipient.name} by ${referral.created_by.name}`
const date =
- !referral.completedOn && formatMediumDateParsed(referral.created_on)
+ !referral.completedOn && formatDate(referral.created_on, DATE_FORMAT_MEDIUM)
return {
id: referral.id,
@@ -104,7 +102,9 @@ export const transformInteractionToListItem = (activity) => {
const companyId = activity.company.id
return {
id: interaction.id,
- date: interaction.date ? formatMediumDateParsed(interaction.date) : '',
+ date: interaction.date
+ ? formatDate(interaction.date, DATE_FORMAT_MEDIUM)
+ : '',
tags: [
{
text: INTERACTION_NAMES[interaction.kind],
@@ -128,7 +128,7 @@ export const transformInvestmentToListItem = (activity) => {
return {
id: investment.id,
- date: formatMediumDateParsed(activity.date),
+ date: formatDate(activity.date, DATE_FORMAT_MEDIUM),
tags: [
{
text: 'New Investment Project',
@@ -161,7 +161,7 @@ export const transformOrderToListItem = (activity) => {
: summary.push('')
return {
id: order.id,
- date: formatMediumDateParsed(activity.date),
+ date: formatDate(activity.date, DATE_FORMAT_MEDIUM),
tags: [
{
text: 'New Order',
@@ -179,7 +179,7 @@ export const transformGreatExportEnquiryToListItem = (activity) => {
const great = activity.great_export_enquiry
return {
id: great.id,
- date: formatMediumDateParsed(activity.date),
+ date: formatDate(activity.date, DATE_FORMAT_MEDIUM),
tags: [
{
diff --git a/src/client/modules/Contacts/CollectionList/transformers.js b/src/client/modules/Contacts/CollectionList/transformers.js
index 783e00f7e57..6d2f737c45a 100644
--- a/src/client/modules/Contacts/CollectionList/transformers.js
+++ b/src/client/modules/Contacts/CollectionList/transformers.js
@@ -1,6 +1,9 @@
import { get } from 'lodash'
-import { formatMediumDateTime } from '../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../utils/date-utils'
import urls from '../../../../lib/urls'
@@ -33,7 +36,7 @@ export const transformContactToListItem = (companyId) => (contact) => {
headingUrl: urls.contacts.details(contact.id),
tags: tags.filter((item) => item.text),
headingText: `${contact.first_name} ${contact.last_name}`.trim(),
- subheading: `Updated on ${formatMediumDateTime(contact.modified_on)}`,
+ subheading: `Updated on ${formatDate(contact.modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
}
}
diff --git a/src/client/modules/Contacts/ContactActivity/transformers.js b/src/client/modules/Contacts/ContactActivity/transformers.js
index acecca7c02c..3e4b552e9cc 100644
--- a/src/client/modules/Contacts/ContactActivity/transformers.js
+++ b/src/client/modules/Contacts/ContactActivity/transformers.js
@@ -1,5 +1,5 @@
import urls from '../../../../lib/urls'
-import { formatMediumDateParsed } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import {
verifyLabel,
formattedAdvisers,
@@ -19,7 +19,7 @@ export const transformContactActivityToListItem = ({
}) => ({
id,
metadata: [
- { label: 'Date', value: formatMediumDateParsed(date) },
+ { label: 'Date', value: formatDate(date, DATE_FORMAT_MEDIUM) },
{
label: verifyLabel(contacts, 'Contact'),
value: formattedContacts(contacts),
diff --git a/src/client/modules/Contacts/ContactAuditHistory/transformers.js b/src/client/modules/Contacts/ContactAuditHistory/transformers.js
index 7766e60ba5a..df00cb80feb 100644
--- a/src/client/modules/Contacts/ContactAuditHistory/transformers.js
+++ b/src/client/modules/Contacts/ContactAuditHistory/transformers.js
@@ -2,7 +2,11 @@ import { isBoolean, isNumber } from 'lodash'
import { transformFieldName } from '../../../components/AuditHistory/transformers'
import { CONTACT_FIELD_NAME_TO_LABEL_MAP } from './constants'
-import { formatMediumDateTime, isUnparsedDateValid } from '../../../utils/date'
+import { isUnparsedDateValid } from '../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../utils/date-utils'
import {
ARCHIVED,
NO,
@@ -26,5 +30,5 @@ export const getValue = (value, field) =>
: isNumber(value)
? value.toString()
: isUnparsedDateValid(value)
- ? formatMediumDateTime(value)
+ ? formatDate(value, DATE_FORMAT_MEDIUM_WITH_TIME)
: value || NOT_SET
diff --git a/src/client/modules/Events/AttendeeSearch/transformers.js b/src/client/modules/Events/AttendeeSearch/transformers.js
index a54857d3f1d..4847e4cc5d2 100644
--- a/src/client/modules/Events/AttendeeSearch/transformers.js
+++ b/src/client/modules/Events/AttendeeSearch/transformers.js
@@ -1,7 +1,10 @@
import { get } from 'lodash'
import urls from '../../../../lib/urls'
-import { formatMediumDateTime } from '../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../utils/date-utils'
export const transformContactToListItem = (companyId, eventId) => (contact) => {
const metadata = [
@@ -22,7 +25,7 @@ export const transformContactToListItem = (companyId, eventId) => (contact) => {
headingUrl: urls.events.addAttendee(eventId, contact.id),
badges: badges.filter((item) => item.text),
headingText: `${contact.first_name} ${contact.last_name}`.trim(),
- subheading: `Updated on ${formatMediumDateTime(contact.modified_on)}`,
+ subheading: `Updated on ${formatDate(contact.modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
}
}
diff --git a/src/client/modules/Events/transformers.js b/src/client/modules/Events/transformers.js
index b2da3835ca2..a4046349987 100644
--- a/src/client/modules/Events/transformers.js
+++ b/src/client/modules/Events/transformers.js
@@ -2,12 +2,13 @@ import { compact } from 'lodash'
import urls from '../../../lib/urls'
+import { getDifferenceInDays, formatStartAndEndDate } from '../../utils/date'
+
import {
- formatMediumDateTime,
- getDifferenceInDays,
- formatLongDate,
- formatStartAndEndDate,
-} from '../../utils/date'
+ formatDate,
+ DATE_FORMAT_FULL,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../utils/date-utils'
import { transformIdNameToValueLabel } from '../../transformers'
import {
@@ -85,9 +86,9 @@ const transformEventToListItem = ({
id,
headingText: name,
headingUrl: urls.events.details(id),
- subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
- : undefined,
+ subheading:
+ modified_on &&
+ `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
tags: tags,
metadata: metadata.filter((item) => item.value),
}
@@ -122,8 +123,8 @@ const transformResponseToEventDetails = ({
}) => ({
name,
eventType: event_type.name,
- startDate: formatLongDate(start_date),
- endDate: formatLongDate(end_date),
+ startDate: formatDate(start_date, DATE_FORMAT_FULL),
+ endDate: formatDate(end_date, DATE_FORMAT_FULL),
eventDays:
getDifferenceInDays(end_date) - getDifferenceInDays(start_date) + 1,
locationType: location_type?.name,
diff --git a/src/client/modules/ExportPipeline/ExportList/ResultItem.jsx b/src/client/modules/ExportPipeline/ExportList/ResultItem.jsx
index 480a3715f41..69b1caca1d0 100644
--- a/src/client/modules/ExportPipeline/ExportList/ResultItem.jsx
+++ b/src/client/modules/ExportPipeline/ExportList/ResultItem.jsx
@@ -7,7 +7,11 @@ import { get, capitalize } from 'lodash'
import Tag, { TAG_COLOURS } from '../../../components/Tag'
import { ToggleSection } from '../../../components/ToggleSection/index.jsx'
import { DARK_GREY, MID_GREY, BLACK } from '../../../utils/colours.js'
-import { formatShortDate, formatMediumDateTime } from '../../../utils/date.js'
+import {
+ formatDate,
+ DATE_FORMAT_MONTH_YEAR,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../utils/date-utils.js'
import { currencyGBP } from '../../../utils/number-utils.js'
import { ToggleButton } from '../../../components/ToggleSection/BaseToggleSection.jsx'
@@ -134,7 +138,7 @@ const ResultItem = (item) => {
Estimated date for win:
{item.estimated_win_date
- ? formatShortDate(item.estimated_win_date)
+ ? formatDate(item.estimated_win_date, DATE_FORMAT_MONTH_YEAR)
: 'Not set'}
Main sector:
@@ -142,7 +146,9 @@ const ResultItem = (item) => {
Owner:
{item.owner.name}
Created on:
- {formatMediumDateTime(item.created_on)}
+
+ {formatDate(item.created_on, DATE_FORMAT_MEDIUM_WITH_TIME)}
+
diff --git a/src/client/modules/ExportWins/Form/SummaryStep.jsx b/src/client/modules/ExportWins/Form/SummaryStep.jsx
index 1ca3293721d..520838805a5 100644
--- a/src/client/modules/ExportWins/Form/SummaryStep.jsx
+++ b/src/client/modules/ExportWins/Form/SummaryStep.jsx
@@ -9,7 +9,10 @@ import pluralize from 'pluralize'
import { Step, ButtonLink, FieldInput, SummaryTable } from '../../../components'
import { OPTION_NO, OPTION_YES } from '../../../../common/constants'
import { useFormContext } from '../../../components/Form/hooks'
-import { formatMediumDateTimeWithoutParsing } from '../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../utils/date-utils'
import { WIN_STATUS } from '../Status/constants'
import { ContactLink } from './ExportWinForm'
import urls from '../../../../lib/urls'
@@ -365,10 +368,10 @@ const AdditionalInformation = ({ values, isEditing }) => {
{winStatus === WIN_STATUS.PENDING && (
<>
- {formatMediumDateTimeWithoutParsing(values.first_sent)}
+ {formatDate(values.first_sent, DATE_FORMAT_MEDIUM_WITH_TIME)}
- {formatMediumDateTimeWithoutParsing(values.last_sent)}
+ {formatDate(values.last_sent, DATE_FORMAT_MEDIUM_WITH_TIME)}
Pending
diff --git a/src/client/modules/ExportWins/Review/index.jsx b/src/client/modules/ExportWins/Review/index.jsx
index 0052b30bd35..487607b83bd 100644
--- a/src/client/modules/ExportWins/Review/index.jsx
+++ b/src/client/modules/ExportWins/Review/index.jsx
@@ -28,7 +28,7 @@ import { WithoutOurSupport } from '../../../components/Resource'
import MarketingSource from '../../../components/Resource/MarketingSource'
import Err from '../../../components/Task/Error'
import { currencyGBP } from '../../../utils/number-utils'
-import { formatMediumDateParsed } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import AccesibilityStatement from './AccesibilityStatement'
import PrivacyNotice from './PrivacyNotice'
@@ -168,7 +168,7 @@ const Step1 = ({ win, name }) => {
{`${currencyGBP(totalAmount)} over ${totalYears} ${pluralize('year', totalYears)}`}
- {formatMediumDateParsed(win?.date)}
+ {formatDate(win?.date, DATE_FORMAT_MEDIUM)}
{win?.leadOfficer?.name}
diff --git a/src/client/modules/Interactions/ESSInteractionDetails/transformers.js b/src/client/modules/Interactions/ESSInteractionDetails/transformers.js
index 5e66ed7fded..830d7c548b6 100644
--- a/src/client/modules/Interactions/ESSInteractionDetails/transformers.js
+++ b/src/client/modules/Interactions/ESSInteractionDetails/transformers.js
@@ -1,6 +1,9 @@
const { get } = require('lodash')
-const { formatLongDate } = require('../../../../client/utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_FULL,
+} = require('../../../../client/utils/date-utils')
const transformResponseToESSInteractionDetails = ({ id, object }) => {
const formData = get(object, 'dit:directoryFormsApi:Submission:Data')
@@ -10,7 +13,7 @@ const transformResponseToESSInteractionDetails = ({ id, object }) => {
? formData.nature_of_enquiry
: 'ESS Inbound Enquiry',
question: formData.aaa_question,
- dateOfInteraction: formatLongDate(object.published),
+ dateOfInteraction: formatDate(object.published, DATE_FORMAT_FULL),
countries: formData.countries,
companyName: formData.company_name,
enquirer: formData.full_name,
diff --git a/src/client/modules/Interactions/InteractionDetails/index.jsx b/src/client/modules/Interactions/InteractionDetails/index.jsx
index 6832f924247..93a176e2394 100644
--- a/src/client/modules/Interactions/InteractionDetails/index.jsx
+++ b/src/client/modules/Interactions/InteractionDetails/index.jsx
@@ -12,7 +12,7 @@ import ArchivePanel from '../../../components/ArchivePanel'
import CompleteInteraction from './CompleteInteraction'
import { currencyGBP } from '../../../utils/number-utils'
-import { formatLongDate } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_FULL } from '../../../utils/date-utils'
import urls from '../../../../lib/urls'
import {
getEditLink,
@@ -88,7 +88,7 @@ const InteractionDetails = ({ interactionId }) => {
) : null}
{interaction.ditParticipants ? (
data ? { value: data.id, label: data.name } : {}
@@ -37,7 +40,7 @@ export const transformInvestmentOpportunityDetails = ({
status: idNameToValueLabel(status),
id,
detailsFields: {
- createdOn: formatMediumDateTime(created_on),
+ createdOn: formatDate(created_on, DATE_FORMAT_MEDIUM_WITH_TIME),
name,
description,
ukRegions: uk_region_locations.map(idNameToValueLabel),
diff --git a/src/client/modules/Investments/Projects/Details/EditRecipientCompany/transformers.js b/src/client/modules/Investments/Projects/Details/EditRecipientCompany/transformers.js
index ef567606de0..90dc1ebe686 100644
--- a/src/client/modules/Investments/Projects/Details/EditRecipientCompany/transformers.js
+++ b/src/client/modules/Investments/Projects/Details/EditRecipientCompany/transformers.js
@@ -3,7 +3,11 @@ import { get } from 'lodash'
import urls from '../../../../../../lib/urls'
import labels from '../../../../Companies/CollectionList/labels'
import { addressToString } from '../../../../../utils/addresses'
-import { format, formatMediumDateTime } from '../../../../../utils/date'
+import { format } from '../../../../../utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../../../utils/date-utils'
export const checkIfRecipientCompanyExists = (hasRecipientCompany) =>
hasRecipientCompany ? 'Update recipient company' : 'Add recipient company'
@@ -67,7 +71,7 @@ const transformCompanyToListItem =
return {
id,
subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
+ ? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: urls.investments.projects.editRecipientCompany(projectId, id),
diff --git a/src/client/modules/Investments/Projects/EditHistory/transformers.js b/src/client/modules/Investments/Projects/EditHistory/transformers.js
index 9869e5833ae..75fc159fb21 100644
--- a/src/client/modules/Investments/Projects/EditHistory/transformers.js
+++ b/src/client/modules/Investments/Projects/EditHistory/transformers.js
@@ -1,7 +1,8 @@
import { isBoolean, isNumber } from 'lodash'
import { PROJECT_FIELD_NAME_TO_LABEL_MAP } from './constants'
-import { formatMediumDate, isUnparsedDateValid } from '../../../../utils/date'
+import { isUnparsedDateValid } from '../../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../../utils/date-utils'
import { currencyGBP } from '../../../../utils/number-utils'
import { NOT_SET, NO, YES } from '../../../../components/AuditHistory/constants'
import { transformFieldName } from '../../../../components/AuditHistory/transformers'
@@ -36,5 +37,5 @@ export const getValue = (value, field) =>
: Array.isArray(value)
? value.join(', ')
: isUnparsedDateValid(value)
- ? formatMediumDate(value)
+ ? formatDate(value, DATE_FORMAT_MEDIUM)
: value || NOT_SET
diff --git a/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx b/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx
index 72ba24fb13c..f69d2c74b68 100644
--- a/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx
+++ b/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx
@@ -16,7 +16,7 @@ import {
transformDocumentStatus,
} from './transformers'
import urls from '../../../../../lib/urls'
-import { formatLongDate } from '../../../../utils/date'
+import { formatDate, DATE_FORMAT_FULL } from '../../../../utils/date-utils'
import { buildProjectBreadcrumbs } from '../../utils'
import { ID, TASK_PROPOSITION_COMPLETE, propositionState2props } from '../state'
import { PROPOSITION_COMPLETE } from '../../../../../client/actions'
@@ -95,15 +95,24 @@ const PropositionDetails = ({
/>
{
+ const getInputAndExpected = () => ({
+ input: { count: 10, summary: 'Test summary' },
+ expected: { count: 10, summary: 'Test summary', results: [] },
+ })
+
+ it('should handle missing results by defaulting to an empty array in transformResponseToCollection', () => {
+ const { input, expected } = getInputAndExpected()
+ expect(transformResponseToCollection(input)).to.deep.equal(expected)
+ })
+
+ it('should handle missing results by defaulting to an empty array in transformResponseToReconciliationCollection', () => {
+ const { input, expected } = getInputAndExpected()
+ expect(transformResponseToReconciliationCollection(input)).to.deep.equal(
+ expected
+ )
+ })
+})
diff --git a/src/client/modules/Omis/CollectionList/transformers.js b/src/client/modules/Omis/CollectionList/transformers.js
index ab1f274dfde..27a506a4cc0 100644
--- a/src/client/modules/Omis/CollectionList/transformers.js
+++ b/src/client/modules/Omis/CollectionList/transformers.js
@@ -4,11 +4,12 @@ import { STATUSES } from './constants'
import { omis } from '../../../../lib/urls'
import { currencyGBP } from '../../../utils/number-utils'
+const { format } = require('../../../utils/date')
const {
- format,
- formatMediumDate,
- formatMediumDateTime,
-} = require('../../../utils/date')
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../utils/date-utils')
export const transformOrderCost = (cost) => (cost ? cost * 100 : undefined)
@@ -34,7 +35,7 @@ export const transformOrderToListItem = ({
},
{
label: 'Created',
- value: created_on ? formatMediumDateTime(created_on) : null,
+ value: created_on && formatDate(created_on, DATE_FORMAT_MEDIUM_WITH_TIME),
},
{
label: 'Contact',
@@ -65,9 +66,9 @@ export const transformOrderToListItem = ({
metadata,
headingText: reference,
headingUrl: omis.workOrder(id),
- subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
- : null,
+ subheading:
+ modified_on &&
+ `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
}
return retVal
@@ -88,7 +89,8 @@ export const transformOrderToReconciliationListItem = ({
const metadata = [
{
label: 'Payment due date',
- value: payment_due_date ? formatMediumDate(payment_due_date) : null,
+ value:
+ payment_due_date && formatDate(payment_due_date, DATE_FORMAT_MEDIUM),
},
{
label: 'Company name',
@@ -112,30 +114,25 @@ export const transformOrderToReconciliationListItem = ({
metadata,
headingText: reference,
headingUrl: omis.paymentReconciliation(id),
- subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
- : null,
+ subheading:
+ modified_on &&
+ `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
}
return retVal
}
-export const transformResponseToCollection = ({
- count,
- results = [],
- summary,
-}) => ({
- count,
- summary,
- results: results.map(transformOrderToListItem),
-})
+const transformResponse =
+ (transformItem) =>
+ ({ count, results = [], summary }) => ({
+ count,
+ summary,
+ results: results.map(transformItem),
+ })
-export const transformResponseToReconciliationCollection = ({
- count,
- results = [],
- summary,
-}) => ({
- count,
- summary,
- results: results.map(transformOrderToReconciliationListItem),
-})
+export const transformResponseToCollection = transformResponse(
+ transformOrderToListItem
+)
+export const transformResponseToReconciliationCollection = transformResponse(
+ transformOrderToReconciliationListItem
+)
diff --git a/src/client/modules/Omis/CreateOrder/CompanySelect/transformers.js b/src/client/modules/Omis/CreateOrder/CompanySelect/transformers.js
index f7ad78bf6ca..49c3f1bc148 100644
--- a/src/client/modules/Omis/CreateOrder/CompanySelect/transformers.js
+++ b/src/client/modules/Omis/CreateOrder/CompanySelect/transformers.js
@@ -5,7 +5,11 @@ import urls from '../../../../../lib/urls'
import { addressToString } from '../../../../utils/addresses'
-const { format, formatMediumDateTime } = require('../../../../utils/date')
+const { format } = require('../../../../utils/date')
+const {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} = require('../../../../utils/date-utils')
const transformCompanyToListItem = ({
id,
@@ -67,7 +71,7 @@ const transformCompanyToListItem = ({
return {
id,
subheading: modified_on
- ? `Updated on ${formatMediumDateTime(modified_on)}`
+ ? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: urls.omis.create.form(id),
diff --git a/src/client/modules/Omis/OMISLocalHeader.jsx b/src/client/modules/Omis/OMISLocalHeader.jsx
index e95925735b2..2d5e19e03b4 100644
--- a/src/client/modules/Omis/OMISLocalHeader.jsx
+++ b/src/client/modules/Omis/OMISLocalHeader.jsx
@@ -4,11 +4,11 @@ import { Button, GridCol, GridRow, Link } from 'govuk-react'
import { FONT_WEIGHTS } from '@govuk-react/constants'
import LocalHeaderDetails from '../../components/LocalHeaderDetails'
+import { getDifferenceInWords, isDateInFuture } from '../../utils/date'
import {
- formatMediumDateTime,
- getDifferenceInWords,
- isDateInFuture,
-} from '../../utils/date'
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../utils/date-utils'
import { STATUS } from './constants'
import urls from '../../../lib/urls'
@@ -60,10 +60,13 @@ const setHeaderItems = (order, quote) => {
{ label: 'Country (market)', value: order.primaryMarket.name },
]
const secondItems = [
- { label: 'Created on', value: formatMediumDateTime(order.createdOn) },
+ {
+ label: 'Created on',
+ value: formatDate(order.createdOn, DATE_FORMAT_MEDIUM_WITH_TIME),
+ },
{
label: 'Updated on',
- value: formatMediumDateTime(order.modifiedOn),
+ value: formatDate(order.modifiedOn, DATE_FORMAT_MEDIUM_WITH_TIME),
},
{
label: 'Status',
diff --git a/src/client/modules/Omis/OrderQuote.jsx b/src/client/modules/Omis/OrderQuote.jsx
index 40cdd7894e6..70e787cc7f1 100644
--- a/src/client/modules/Omis/OrderQuote.jsx
+++ b/src/client/modules/Omis/OrderQuote.jsx
@@ -25,11 +25,12 @@ import { ORDERS__QUOTE_PREVIEW_LOADED } from '../../actions'
import OMISTermsAndConditions from './OMISTermsAndConditions'
import urls from '../../../lib/urls'
import { DARK_GREY, RED_2 } from '../../utils/colours'
+import { isDateInFuture } from '../../utils/date'
import {
- formatMediumDateParsed,
- formatMediumDateTime,
- isDateInFuture,
-} from '../../utils/date'
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../utils/date-utils'
import { STATUS } from './constants'
const StyledInsetText = styled(InsetText)`
@@ -111,7 +112,7 @@ const SentOn = ({ quote }) => (
<>
Sent on
- {formatMediumDateTime(quote.createdOn)}
+ {formatDate(quote.createdOn, DATE_FORMAT_MEDIUM_WITH_TIME)}
Sent by
{quote.createdBy.name}
@@ -122,7 +123,7 @@ const AcceptedOn = ({ quote }) => (
<>
Accepted on
- {formatMediumDateTime(quote.acceptedOn)}
+ {formatDate(quote.acceptedOn, DATE_FORMAT_MEDIUM_WITH_TIME)}
Accepted by
{quote.acceptedBy.name}
@@ -201,7 +202,10 @@ const OrderQuote = ({ quotePreview }) => {
Will expire on
- {formatMediumDateParsed(quotePreview?.expires_on)}
+ {formatDate(
+ quotePreview?.expires_on,
+ DATE_FORMAT_MEDIUM
+ )}
{
{setExpiryLabel(quote)}
- {formatMediumDateParsed(quote.expiresOn)}
+ {formatDate(quote.expiresOn, DATE_FORMAT_MEDIUM)}
@@ -281,7 +285,10 @@ const OrderQuote = ({ quotePreview }) => {
Cancelled on
- {formatMediumDateTime(quote.cancelledOn)}
+ {formatDate(
+ quote.cancelledOn,
+ DATE_FORMAT_MEDIUM_WITH_TIME
+ )}
Cancelled by
diff --git a/src/client/modules/Omis/WorkOrderTables/QuoteInformationTable.jsx b/src/client/modules/Omis/WorkOrderTables/QuoteInformationTable.jsx
index 1904ea1ce94..43611154328 100644
--- a/src/client/modules/Omis/WorkOrderTables/QuoteInformationTable.jsx
+++ b/src/client/modules/Omis/WorkOrderTables/QuoteInformationTable.jsx
@@ -3,7 +3,7 @@ import { Link } from 'govuk-react'
import { SummaryTable } from '../../../components'
import { canEditOrder } from '../transformers'
-import { formatMediumDateParsed } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import urls from '../../../../lib/urls'
const QuoteInformationTable = ({ order }) => (
@@ -25,7 +25,7 @@ const QuoteInformationTable = ({ order }) => (
>
{order.deliveryDate
- ? formatMediumDateParsed(order.deliveryDate)
+ ? formatDate(order.deliveryDate, DATE_FORMAT_MEDIUM)
: 'Not set'}
diff --git a/src/client/modules/Reminders/ItemRenderers/Exports/ExportItemRenderer.jsx b/src/client/modules/Reminders/ItemRenderers/Exports/ExportItemRenderer.jsx
index b7de95f9b35..8f1209406e0 100644
--- a/src/client/modules/Reminders/ItemRenderers/Exports/ExportItemRenderer.jsx
+++ b/src/client/modules/Reminders/ItemRenderers/Exports/ExportItemRenderer.jsx
@@ -5,7 +5,7 @@ import { GREY_1 } from '../../../../utils/colours'
import ItemRenderer from '../ItemRenderer'
import { INTERACTION_NAMES } from '../../constants'
-import { formatMediumDateParsed } from '../../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../../utils/date-utils'
import urls from '../../../../../lib/urls'
const ItemHint = styled('span')({
@@ -16,7 +16,7 @@ const ItemContent = ({ item, hintLabel }) => (
-
{`${hintLabel}: `}
- {formatMediumDateParsed(item.last_interaction_date)}
+ {formatDate(item.last_interaction_date, DATE_FORMAT_MEDIUM)}
{item.interaction ? (
<>
@@ -66,7 +66,7 @@ const ExportItemRenderer = ({
item={item}
onDeleteReminder={onDeleteReminder}
disableDelete={disableDelete}
- deletedText={`Received ${formatMediumDateParsed(item.created_on)} for ${
+ deletedText={`Received ${formatDate(item.created_on, DATE_FORMAT_MEDIUM)} for ${
item.company.name
}`}
headerLinkTitle={headerLinkTitle}
diff --git a/src/client/modules/Reminders/ItemRenderers/ItemRenderer.jsx b/src/client/modules/Reminders/ItemRenderers/ItemRenderer.jsx
index a84d819af6f..f522a8aedca 100644
--- a/src/client/modules/Reminders/ItemRenderers/ItemRenderer.jsx
+++ b/src/client/modules/Reminders/ItemRenderers/ItemRenderer.jsx
@@ -11,7 +11,7 @@ import {
ItemHeaderLink,
ItemFooter,
} from './styled'
-import { formatMediumDateParsed } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import { BLACK, DARK_GREY } from '../../../utils/colours'
export const ItemRenderer = ({
@@ -39,7 +39,9 @@ export const ItemRenderer = ({
- - Received {formatMediumDateParsed(item.created_on)}
+ -
+ Received {formatDate(item.created_on, DATE_FORMAT_MEDIUM)}
+
{headerLinkHref && (
-
diff --git a/src/client/modules/Tasks/TaskDetails/TaskDetailsTable.jsx b/src/client/modules/Tasks/TaskDetails/TaskDetailsTable.jsx
index ff7b88ed89e..644e3f35486 100644
--- a/src/client/modules/Tasks/TaskDetails/TaskDetailsTable.jsx
+++ b/src/client/modules/Tasks/TaskDetails/TaskDetailsTable.jsx
@@ -3,7 +3,7 @@ import { Link } from 'govuk-react'
import { SummaryTable } from '../../../components'
-import { formatLongDate } from '../../../utils/date'
+import { formatDate, DATE_FORMAT_FULL } from '../../../utils/date-utils'
import { transformAdvisers } from './transformers'
import { NOT_SET_TEXT } from '../../../../apps/companies/constants'
import urls from '../../../../lib/urls'
@@ -44,7 +44,11 @@ const TaskDetailsTable = ({ task, company, project }) => (
)}
(
/>
diff --git a/src/client/utils/__test__/date-utils.test.js b/src/client/utils/__test__/date-utils.test.js
index aa2afdf1c89..3d9481feac3 100644
--- a/src/client/utils/__test__/date-utils.test.js
+++ b/src/client/utils/__test__/date-utils.test.js
@@ -13,60 +13,133 @@ import {
DATE_FORMAT_INTERACTION_TIMESTAMP,
} from '../date-utils'
-describe('formatDate', () => {
+describe('date-utils', () => {
const date = '2024-12-04'
const time = 'T10:41:45.425717Z'
const dateAndTime = `${date}${time}`
- it("should render '04 Dec 2024' (default format)", () => {
- expect(formatDate(date)).to.equal('04 Dec 2024') // the default
- })
+ context('formatDate() - formatting ISO date strings', () => {
+ it("should render '04 Dec 2024' (default format)", () => {
+ expect(formatDate(date)).to.equal('04 Dec 2024') // the default
+ })
- it("should render '04 Dec 2024' (DATE_FORMAT_COMPACT)", () => {
- expect(formatDate(date, DATE_FORMAT_COMPACT)).to.equal('04 Dec 2024')
- })
+ it("should render '04 Dec 2024' (DATE_FORMAT_COMPACT)", () => {
+ expect(formatDate(date, DATE_FORMAT_COMPACT)).to.equal('04 Dec 2024')
+ })
- it("should render '4 Dec 2024' (DATE_FORMAT_MEDIUM)", () => {
- expect(formatDate(dateAndTime, DATE_FORMAT_MEDIUM)).to.equal('4 Dec 2024')
- })
+ it("should render '4 Dec 2024' (DATE_FORMAT_MEDIUM)", () => {
+ expect(formatDate(dateAndTime, DATE_FORMAT_MEDIUM)).to.equal('4 Dec 2024')
+ })
- it("should render '4 Dec 2024, 10:41am' (DATE_FORMAT_MEDIUM_WITH_TIME)", () => {
- expect(formatDate(dateAndTime, DATE_FORMAT_MEDIUM_WITH_TIME)).to.equal(
- '4 Dec 2024, 10:41am'
- )
- })
+ it("should render '4 Dec 2024, 10:41am' (DATE_FORMAT_MEDIUM_WITH_TIME)", () => {
+ expect(formatDate(dateAndTime, DATE_FORMAT_MEDIUM_WITH_TIME)).to.equal(
+ '4 Dec 2024, 10:41am'
+ )
+ })
- it("should render '4 December 2024' (DATE_FORMAT_FULL)", () => {
- expect(formatDate(date, DATE_FORMAT_FULL)).to.equal('4 December 2024')
- })
+ it("should render '4 December 2024' (DATE_FORMAT_FULL)", () => {
+ expect(formatDate(date, DATE_FORMAT_FULL)).to.equal('4 December 2024')
+ })
- it("should render 'Wed, 04 Dec 2024' (DATE_FORMAT_FULL_DAY)", () => {
- expect(formatDate(date, DATE_FORMAT_FULL_DAY)).to.equal('Wed, 04 Dec 2024')
- })
+ it("should render 'Wed, 04 Dec 2024' (DATE_FORMAT_FULL_DAY)", () => {
+ expect(formatDate(date, DATE_FORMAT_FULL_DAY)).to.equal(
+ 'Wed, 04 Dec 2024'
+ )
+ })
- it("should render '2024-12-04' (DATE_FORMAT_ISO)", () => {
- expect(formatDate(date, DATE_FORMAT_ISO)).to.equal('2024-12-04')
- })
+ it("should render '2024-12-04' (DATE_FORMAT_ISO)", () => {
+ expect(formatDate(date, DATE_FORMAT_ISO)).to.equal('2024-12-04')
+ })
- it("should render '2024-12' (DATE_FORMAT_YEAR_MONTH)", () => {
- expect(formatDate(date, DATE_FORMAT_YEAR_MONTH)).to.equal('2024-12')
- })
+ it("should render '2024-12' (DATE_FORMAT_YEAR_MONTH)", () => {
+ expect(formatDate(date, DATE_FORMAT_YEAR_MONTH)).to.equal('2024-12')
+ })
- it("should render 'December 2024' (DATE_FORMAT_MONTH_YEAR)", () => {
- expect(formatDate(date, DATE_FORMAT_MONTH_YEAR)).to.equal('December 2024')
- })
+ it("should render 'December 2024' (DATE_FORMAT_MONTH_YEAR)", () => {
+ expect(formatDate(date, DATE_FORMAT_MONTH_YEAR)).to.equal('December 2024')
+ })
- it("should render 'Dec 2024' (DATE_FORMAT_MONTH_ABBR_YEAR)", () => {
- expect(formatDate(date, DATE_FORMAT_MONTH_ABBR_YEAR)).to.equal('Dec 2024')
- })
+ it("should render 'Dec 2024' (DATE_FORMAT_MONTH_ABBR_YEAR)", () => {
+ expect(formatDate(date, DATE_FORMAT_MONTH_ABBR_YEAR)).to.equal('Dec 2024')
+ })
+
+ it("should render '04 Dec' (DATE_FORMAT_DAY_MONTH)", () => {
+ expect(formatDate(date, DATE_FORMAT_DAY_MONTH)).to.equal('04 Dec')
+ })
- it("should render '04 Dec' (DATE_FORMAT_DAY_MONTH)", () => {
- expect(formatDate(date, DATE_FORMAT_DAY_MONTH)).to.equal('04 Dec')
+ it("should render '2024-12-4' (DATE_FORMAT_INTERACTION_TIMESTAMP)", () => {
+ expect(formatDate(date, DATE_FORMAT_INTERACTION_TIMESTAMP)).to.equal(
+ '2024-12-4'
+ )
+ })
})
+ context('formatDate() - formatting Date objects ', () => {
+ it("should render '04 Dec 2024' (default format)", () => {
+ expect(formatDate(new Date(date))).to.equal('04 Dec 2024') // the default
+ })
+
+ it("should render '04 Dec 2024' (DATE_FORMAT_COMPACT)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_COMPACT)).to.equal(
+ '04 Dec 2024'
+ )
+ })
+
+ it("should render '4 Dec 2024' (DATE_FORMAT_MEDIUM)", () => {
+ expect(formatDate(new Date(dateAndTime), DATE_FORMAT_MEDIUM)).to.equal(
+ '4 Dec 2024'
+ )
+ })
+
+ it("should render '4 Dec 2024, 10:41am' (DATE_FORMAT_MEDIUM_WITH_TIME)", () => {
+ expect(
+ formatDate(new Date(dateAndTime), DATE_FORMAT_MEDIUM_WITH_TIME)
+ ).to.equal('4 Dec 2024, 10:41am')
+ })
+
+ it("should render '4 December 2024' (DATE_FORMAT_FULL)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_FULL)).to.equal(
+ '4 December 2024'
+ )
+ })
+
+ it("should render 'Wed, 04 Dec 2024' (DATE_FORMAT_FULL_DAY)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_FULL_DAY)).to.equal(
+ 'Wed, 04 Dec 2024'
+ )
+ })
+
+ it("should render '2024-12-04' (DATE_FORMAT_ISO)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_ISO)).to.equal('2024-12-04')
+ })
+
+ it("should render '2024-12' (DATE_FORMAT_YEAR_MONTH)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_YEAR_MONTH)).to.equal(
+ '2024-12'
+ )
+ })
+
+ it("should render 'December 2024' (DATE_FORMAT_MONTH_YEAR)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_MONTH_YEAR)).to.equal(
+ 'December 2024'
+ )
+ })
+
+ it("should render 'Dec 2024' (DATE_FORMAT_MONTH_ABBR_YEAR)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_MONTH_ABBR_YEAR)).to.equal(
+ 'Dec 2024'
+ )
+ })
+
+ it("should render '04 Dec' (DATE_FORMAT_DAY_MONTH)", () => {
+ expect(formatDate(new Date(date), DATE_FORMAT_DAY_MONTH)).to.equal(
+ '04 Dec'
+ )
+ })
- it("should render '2024-12-4' (DATE_FORMAT_INTERACTION_TIMESTAMP)", () => {
- expect(formatDate(date, DATE_FORMAT_INTERACTION_TIMESTAMP)).to.equal(
- '2024-12-4'
- )
+ it("should render '2024-12-4' (DATE_FORMAT_INTERACTION_TIMESTAMP)", () => {
+ expect(
+ formatDate(new Date(date), DATE_FORMAT_INTERACTION_TIMESTAMP)
+ ).to.equal('2024-12-4')
+ })
})
})
diff --git a/src/client/utils/date-utils.js b/src/client/utils/date-utils.js
index 8c16bb4c0c2..be6f40fd793 100644
--- a/src/client/utils/date-utils.js
+++ b/src/client/utils/date-utils.js
@@ -67,41 +67,39 @@ const DATE_FORMAT_DAY_MONTH = 'dd MMM'
const DATE_FORMAT_INTERACTION_TIMESTAMP = 'y-MM-d'
/**
- * Formats a given date string into a specified format using `date-fns`.
+ * Formats a date into the specified string format using predefined constants.
*
- * @param {string} dateISO - The date string in ISO format (e.g., '2024-12-04').
- * @param {string} [dateISOFormat=DATE_FORMAT_COMPACT] - The format to use for formatting the date.
- * Available format constants include:
- * - `DATE_FORMAT_FULL`: Full date with day and full month name (e.g., '4 December 2024').
- * - `DATE_FORMAT_FULL_DAY`: Full date with weekday included (e.g., 'Wed, 04 Dec 2024').
- * - `DATE_FORMAT_COMPACT`: Compact date with abbreviated month name (e.g., '04 Dec 2024').
- * - `DATE_FORMAT_ISO`: ISO standard format (e.g., '2024-12-04').
- * - `DATE_FORMAT_MEDIUM`: Medium date format with single-digit day (e.g., '4 Dec 2024').
- * - `DATE_FORMAT_MEDIUM_WITH_TIME`: Medium date with 12-hour time (e.g., '4 Dec 2024, 3:30PM').
- * - `DATE_FORMAT_YEAR_MONTH`: Year and month format (e.g., '2024-12').
- * - `DATE_FORMAT_MONTH_YEAR`: Full month and year (e.g., 'December 2024').
- * - `DATE_FORMAT_MONTH_ABBR_YEAR`: Abbreviated month and year (e.g., 'Dec 2024').
- * - `DATE_FORMAT_DAY_MONTH`: Day and abbreviated month (e.g., '04 Dec').
- * - `DATE_FORMAT_INTERACTION_TIMESTAMP`: Interaction timestamp format (e.g., '2024-12-4').
- * @returns {string} - The formatted date string.
+ * @param {Date|string} date - The date to format. Can be a Date object or an ISO date string (e.g., '2024-12-04').
+ * @param {string} [dateISOFormat=DATE_FORMAT_COMPACT] - The desired format string. Defaults to the compact date format (`DATE_FORMAT_COMPACT`).
+ * Available formats include:
+ * - `DATE_FORMAT_FULL`: Full date with day and full month name (e.g., '4 December 2024').
+ * - `DATE_FORMAT_FULL_DAY`: Full date including the weekday (e.g., 'Wed, 04 Dec 2024').
+ * - `DATE_FORMAT_COMPACT`: Compact date format with abbreviated month (e.g., '04 Dec 2024').
+ * - `DATE_FORMAT_ISO`: ISO standard date format (e.g., '2024-12-04').
+ * - `DATE_FORMAT_MEDIUM`: Medium date with abbreviated month (e.g., '4 Dec 2024').
+ * - `DATE_FORMAT_MEDIUM_WITH_TIME`: Medium date with time in 12-hour format (e.g., '4 Dec 2024, 3:30PM').
+ * - `DATE_FORMAT_YEAR_MONTH`: Year and month in compact form (e.g., '2024-12').
+ * - `DATE_FORMAT_MONTH_YEAR`: Full month name and year (e.g., 'December 2024').
+ * - `DATE_FORMAT_MONTH_ABBR_YEAR`: Abbreviated month name and year (e.g., 'Dec 2024').
+ * - `DATE_FORMAT_DAY_MONTH`: Day and abbreviated month (e.g., '04 Dec').
+ * - `DATE_FORMAT_INTERACTION_TIMESTAMP`: Timestamp-like format (e.g., '2024-12-4').
+ *
+ * @returns {string} The formatted date string based on the specified format.
*
* @example
- * // Format a date to the default compact format
- * formatDate('2024-12-04')
- * // Returns: '04 Dec 2024'
+ * // Formatting with default format (DATE_FORMAT_COMPACT)
+ * formatDate(new Date('2024-12-04')) // '04 Dec 2024'
*
* @example
- * // Format a date to a full format
- * formatDate('2024-12-04', DATE_FORMAT_FULL)
- * // Returns: '4 December 2024'
+ * // Formatting with a different predefined format
+ * formatDate('2024-12-04', DATE_FORMAT_FULL) // '4 December 2024'
*
* @example
- * // Format a date with abbreviated month and year
- * formatDate('2024-12-04', DATE_FORMAT_MONTH_ABBR_YEAR)
- * // Returns: 'Dec 2024'
+ * // Formatting with a timestamp-like format
+ * formatDate(new Date(), DATE_FORMAT_INTERACTION_TIMESTAMP) // '2024-12-9'
*/
-function formatDate(dateISO, dateISOFormat = DATE_FORMAT_COMPACT) {
- return format(parseISO(dateISO), dateISOFormat)
+function formatDate(date, dateISOFormat = DATE_FORMAT_COMPACT) {
+ return format(typeof date === 'string' ? parseISO(date) : date, dateISOFormat)
}
module.exports = {
diff --git a/src/client/utils/date.js b/src/client/utils/date.js
index 1dbe362e39d..813502fdf23 100644
--- a/src/client/utils/date.js
+++ b/src/client/utils/date.js
@@ -34,13 +34,9 @@ const {
} = require('date-fns')
const {
- DATE_LONG_FORMAT_1,
DATE_LONG_FORMAT_2,
DATE_LONG_FORMAT_3,
- DATE_MEDIUM_FORMAT,
- DATE_TIME_MEDIUM_FORMAT,
DATE_SHORT_FORMAT,
- DATE_SHORT_FORMAT_2,
INTERACTION_TIMESTAMP_FORMAT,
DATE_DAY_MONTH,
} = require('../../common/constants')
@@ -136,30 +132,6 @@ function formatWithoutParsing(date, dateFormat = DATE_LONG_FORMAT_2) {
return isUnparsedDateValid(date) ? formatFns(date, dateFormat) : null
}
-function formatMediumDate(dateString) {
- return formatWithoutParsing(dateString, DATE_MEDIUM_FORMAT)
-}
-
-function formatMediumDateParsed(dateString) {
- return format(dateString, DATE_MEDIUM_FORMAT)
-}
-
-function formatLongDate(dateString) {
- return format(dateString, DATE_LONG_FORMAT_1)
-}
-
-function formatShortDate(dateString) {
- return format(dateString, DATE_SHORT_FORMAT_2)
-}
-
-function formatMediumDateTime(dateString) {
- return format(dateString, DATE_TIME_MEDIUM_FORMAT)
-}
-
-function formatMediumDateTimeWithoutParsing(dateString) {
- return formatWithoutParsing(dateString, DATE_TIME_MEDIUM_FORMAT)
-}
-
const formatMonthYearDate = (date) =>
formatFns(parse(date, DATE_SHORT_FORMAT, new Date()), DATE_LONG_FORMAT_3)
@@ -389,10 +361,6 @@ module.exports = {
addYears,
createAndFormatDateObject,
format,
- formatMediumDate,
- formatMediumDateTime,
- formatLongDate,
- formatShortDate,
formatMonthYearDate,
formatWithoutParsing,
generateFinancialYearLabel,
@@ -404,6 +372,7 @@ module.exports = {
getYesterday,
isDateAfter,
isDateValid,
+ isValid,
isNormalisedDateValid,
isShortDateValid,
isUnparsedDateValid,
@@ -427,8 +396,6 @@ module.exports = {
subtractMonths,
areDatesEqual,
tomorrow,
- formatMediumDateTimeWithoutParsing,
- formatMediumDateParsed,
convertUnparsedDateToFieldDateObject,
convertUnparsedDateToFieldShortDateObject,
isDateInFutureParsed,
diff --git a/test/component/cypress/specs/Dashboard/MyTasks/MyTasksTable.cy.jsx b/test/component/cypress/specs/Dashboard/MyTasks/MyTasksTable.cy.jsx
index 98ce7f69351..b8169ee0583 100644
--- a/test/component/cypress/specs/Dashboard/MyTasks/MyTasksTable.cy.jsx
+++ b/test/component/cypress/specs/Dashboard/MyTasks/MyTasksTable.cy.jsx
@@ -6,7 +6,10 @@ import {
} from '../../../../../functional/cypress/support/assertions'
import { taskWithInvestmentProjectListFaker } from '../../../../../functional/cypress/fakers/task'
-import { formatMediumDateParsed } from '../../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+} from '../../../../../../src/client/utils/date-utils'
import { MyTasksContent } from '../../../../../../src/client/components/Dashboard/my-tasks/MyTasks'
import urls from '../../../../../../src/lib/urls'
@@ -40,7 +43,7 @@ describe('My Tasks on the Dashboard', () => {
element: '[data-test="my-tasks-table"]',
rows: [
[
- formatMediumDateParsed(myTaskResults[0].due_date),
+ formatDate(myTaskResults[0].due_date, DATE_FORMAT_MEDIUM),
myTaskResults[0].title,
myTaskResults[0].company.name,
myTaskResults[0].investment_project.name,
@@ -50,7 +53,7 @@ describe('My Tasks on the Dashboard', () => {
'Active',
],
[
- formatMediumDateParsed(myTaskResults[1].due_date),
+ formatDate(myTaskResults[1].due_date, DATE_FORMAT_MEDIUM),
myTaskResults[1].title,
myTaskResults[1].company.name,
myTaskResults[1].investment_project.name,
@@ -60,7 +63,7 @@ describe('My Tasks on the Dashboard', () => {
'Completed',
],
[
- formatMediumDateParsed(myTaskResults[2].due_date),
+ formatDate(myTaskResults[2].due_date, DATE_FORMAT_MEDIUM),
myTaskResults[2].title,
myTaskResults[2].company.name,
myTaskResults[2].investment_project.name,
diff --git a/test/component/cypress/specs/Omis/PaymentReconciliation/InvoiceDetails.cy.jsx b/test/component/cypress/specs/Omis/PaymentReconciliation/InvoiceDetails.cy.jsx
index de718a95146..af8fdd89524 100644
--- a/test/component/cypress/specs/Omis/PaymentReconciliation/InvoiceDetails.cy.jsx
+++ b/test/component/cypress/specs/Omis/PaymentReconciliation/InvoiceDetails.cy.jsx
@@ -2,10 +2,11 @@ import React from 'react'
import { InvoiceDetails } from '../../../../../../src/client/modules/Omis/PaymentReconciliation'
import { assertGovReactTable } from '../../../../../functional/cypress/support/assertions'
+import { getDifferenceInWords } from '../../../../../../src/client/utils/date'
import {
- formatLongDate,
- getDifferenceInWords,
-} from '../../../../../../src/client/utils/date'
+ formatDate,
+ DATE_FORMAT_FULL,
+} from '../../../../../../src/client/utils/date-utils'
const invoice = {
paymentDueDate: '2017-09-27T08:59:20.381047',
@@ -27,7 +28,7 @@ describe('PaymentReconciliation invoice details', () => {
it('should render the invoice details', () => {
const paymentDueDate =
- formatLongDate(invoice.paymentDueDate) +
+ formatDate(invoice.paymentDueDate, DATE_FORMAT_FULL) +
' (' +
getDifferenceInWords(invoice.paymentDueDate) +
')'
diff --git a/test/component/cypress/specs/Omis/WorkOrder/OMISLocalHeader.cy.jsx b/test/component/cypress/specs/Omis/WorkOrder/OMISLocalHeader.cy.jsx
index 4a8ffd2cd02..31206f227db 100644
--- a/test/component/cypress/specs/Omis/WorkOrder/OMISLocalHeader.cy.jsx
+++ b/test/component/cypress/specs/Omis/WorkOrder/OMISLocalHeader.cy.jsx
@@ -3,10 +3,11 @@ import React from 'react'
import OMISLocalHeader from '../../../../../../src/client/modules/Omis/OMISLocalHeader'
import { orderFaker } from '../../../../../functional/cypress/fakers/orders'
import { STATUS } from '../../../../../../src/client/modules/Omis/constants'
+import { getDifferenceInWords } from '../../../../../../src/client/utils/date'
import {
- formatMediumDateTime,
- getDifferenceInWords,
-} from '../../../../../../src/client/utils/date'
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../../../../src/client/utils/date-utils'
import {
assertLink,
assertLinkWithText,
@@ -30,10 +31,18 @@ const assertUkRegion = (region) =>
assertLocalHeaderDetails(2, 'UK region', region)
const assertCreatedOn = (index, date) =>
- assertLocalHeaderDetails(index, 'Created on', formatMediumDateTime(date))
+ assertLocalHeaderDetails(
+ index,
+ 'Created on',
+ formatDate(date, DATE_FORMAT_MEDIUM_WITH_TIME)
+ )
const assertUpdatedOn = (index, date) =>
- assertLocalHeaderDetails(index, 'Updated on', formatMediumDateTime(date))
+ assertLocalHeaderDetails(
+ index,
+ 'Updated on',
+ formatDate(date, DATE_FORMAT_MEDIUM_WITH_TIME)
+ )
const assertStatus = (index, status) =>
assertLocalHeaderDetails(index, 'Status', status)
diff --git a/test/component/cypress/specs/Omis/WorkOrder/QuoteInformationTable.cy.jsx b/test/component/cypress/specs/Omis/WorkOrder/QuoteInformationTable.cy.jsx
index 98d143c6467..e7cde09c589 100644
--- a/test/component/cypress/specs/Omis/WorkOrder/QuoteInformationTable.cy.jsx
+++ b/test/component/cypress/specs/Omis/WorkOrder/QuoteInformationTable.cy.jsx
@@ -7,7 +7,10 @@ import {
} from '../../../../../functional/cypress/support/assertions'
import { STATUS } from '../../../../../../src/client/modules/Omis/constants'
import urls from '../../../../../../src/lib/urls'
-import { formatMediumDateParsed } from '../../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+} from '../../../../../../src/client/utils/date-utils'
const order = {
id: '123',
@@ -59,8 +62,9 @@ describe('QuoteInformationTable', () => {
heading: 'Information for the quote',
showEditLink: true,
content: {
- 'Delivery date': formatMediumDateParsed(
- orderWithAllFields.deliveryDate
+ 'Delivery date': formatDate(
+ orderWithAllFields.deliveryDate,
+ DATE_FORMAT_MEDIUM
),
'Description of the activity': orderWithAllFields.description,
},
diff --git a/test/component/cypress/specs/Tasks/TaskDetails/TaskDetailsTable.cy.jsx b/test/component/cypress/specs/Tasks/TaskDetails/TaskDetailsTable.cy.jsx
index 34b047f7d4e..3c869c734b9 100644
--- a/test/component/cypress/specs/Tasks/TaskDetails/TaskDetailsTable.cy.jsx
+++ b/test/component/cypress/specs/Tasks/TaskDetails/TaskDetailsTable.cy.jsx
@@ -9,7 +9,10 @@ import {
taskWithInteractionFaker,
} from '../../../../../functional/cypress/fakers/task'
import urls from '../../../../../../src/lib/urls'
-import { formatLongDate } from '../../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_FULL,
+} from '../../../../../../src/client/utils/date-utils'
import { NOT_SET_TEXT } from '../../../../../../src/apps/companies/constants'
import TaskDetailsTable from '../../../../../../src/client/modules/Tasks/TaskDetails/TaskDetailsTable'
import { companyFaker } from '../../../../../functional/cypress/fakers/companies'
@@ -42,13 +45,19 @@ describe('Task details table', () => {
href: urls.investments.projects.details(project.id),
name: project.name,
},
- ['Date due']: formatLongDate(investmentProjectTask.dueDate),
+ ['Date due']: formatDate(
+ investmentProjectTask.dueDate,
+ DATE_FORMAT_FULL
+ ),
'Assigned to': investmentProjectTask.advisers
.map((adviser) => adviser.name)
.join(''),
'Task description': investmentProjectTask.description,
'Reminders set': `${investmentProjectTask.reminderDays} days before due date`,
- 'Date created': formatLongDate(investmentProjectTask.createdOn),
+ 'Date created': formatDate(
+ investmentProjectTask.createdOn,
+ DATE_FORMAT_FULL
+ ),
'Created by': investmentProjectTask.createdBy.name,
},
})
@@ -91,7 +100,10 @@ describe('Task details table', () => {
.join(''),
'Task description': NOT_SET_TEXT,
'Reminders set': NOT_SET_TEXT,
- 'Date created': formatLongDate(taskWithNoInvestmentProject.createdOn),
+ 'Date created': formatDate(
+ taskWithNoInvestmentProject.createdOn,
+ DATE_FORMAT_FULL
+ ),
'Created by': taskWithNoInvestmentProject.createdBy.name,
},
})
@@ -120,13 +132,19 @@ describe('Task details table', () => {
href: urls.interactions.detail(taskWithInteraction.interaction.id),
name: taskWithInteraction.interaction.subject,
},
- ['Date due']: formatLongDate(taskWithInteraction.dueDate),
+ ['Date due']: formatDate(
+ taskWithInteraction.dueDate,
+ DATE_FORMAT_FULL
+ ),
'Assigned to': taskWithInteraction.advisers
.map((adviser) => adviser.name)
.join(''),
'Task description': taskWithInteraction.description,
'Reminders set': `${taskWithInteraction.reminderDays} days before due date`,
- 'Date created': formatLongDate(taskWithInteraction.createdOn),
+ 'Date created': formatDate(
+ taskWithInteraction.createdOn,
+ DATE_FORMAT_FULL
+ ),
'Created by': taskWithInteraction.createdBy.name,
},
})
diff --git a/test/functional/cypress/specs/companies/export/company-export-wins-spec.js b/test/functional/cypress/specs/companies/export/company-export-wins-spec.js
index 977965de263..9632cd1ce90 100644
--- a/test/functional/cypress/specs/companies/export/company-export-wins-spec.js
+++ b/test/functional/cypress/specs/companies/export/company-export-wins-spec.js
@@ -1,4 +1,7 @@
-import { formatShortDate } from '../../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MONTH_YEAR,
+} from '../../../../../../src/client/utils/date-utils'
import { companyExportWinFaker } from '../../../fakers/company-export-win'
import { companyFaker } from '../../../fakers/companies'
import urls from '../../../../../../src/lib/urls'
@@ -16,7 +19,7 @@ const getExpectedMetadata = (win) => ({
'Company name': 'Not set',
'Contact name': `${win.contact.name} (${win.contact.job_title} - ${win.contact.email})`,
Destination: win.country,
- 'Date won': formatShortDate(win.date),
+ 'Date won': formatDate(win.date, DATE_FORMAT_MONTH_YEAR),
'Type of win': win.business_type,
'Total value': `£${win.value.export.total}`,
'Type of goods or services': win.name_of_export,
diff --git a/test/functional/cypress/specs/investments/project-details-meta-list-spec.js b/test/functional/cypress/specs/investments/project-details-meta-list-spec.js
index 51de0f2feca..b7b7c8efad8 100644
--- a/test/functional/cypress/specs/investments/project-details-meta-list-spec.js
+++ b/test/functional/cypress/specs/investments/project-details-meta-list-spec.js
@@ -1,6 +1,9 @@
import { upperFirst } from 'lodash'
-import { formatMediumDateTime } from '../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../../../src/client/utils/date-utils'
const urls = require('../../../../../src/lib/urls')
const { investmentProjectFaker } = require('../../fakers/investment-projects')
@@ -69,7 +72,10 @@ describe('Investment project details', () => {
.next('span')
.should(
'contain',
- formatMediumDateTime(investmentProjectWithAllDetails.created_on)
+ formatDate(
+ investmentProjectWithAllDetails.created_on,
+ DATE_FORMAT_MEDIUM_WITH_TIME
+ )
)
cy.get('[data-test="meta-list-item-created-by"]')
@@ -132,7 +138,10 @@ describe('Investment project details', () => {
.next('span')
.should(
'contain',
- formatMediumDateTime(investmentProjectWithoutAllDetails.created_on)
+ formatDate(
+ investmentProjectWithoutAllDetails.created_on,
+ DATE_FORMAT_MEDIUM_WITH_TIME
+ )
)
cy.get('[data-test="meta-list-item-created-by"]').should('not.exist')
diff --git a/test/functional/cypress/specs/investments/project-edit-recipient-spec.js b/test/functional/cypress/specs/investments/project-edit-recipient-spec.js
index d839eeac958..ac6271eb9ac 100644
--- a/test/functional/cypress/specs/investments/project-edit-recipient-spec.js
+++ b/test/functional/cypress/specs/investments/project-edit-recipient-spec.js
@@ -3,7 +3,10 @@ import fixture from '../../fixtures/investment/investment-needing-external-fundi
import { collectionListRequest } from '../../support/actions'
import { getCollectionList } from '../../support/collection-list-assertions'
import { companyFaker } from '../../fakers/companies'
-import { formatMediumDateTime } from '../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../../../src/client/utils/date-utils'
describe('Edit the recipient company', () => {
context('When searching for a recipient company', () => {
@@ -34,7 +37,7 @@ describe('Edit the recipient company', () => {
)
cy.get('h4').should(
'contain',
- `Updated on ${formatMediumDateTime(company.modified_on)}`
+ `Updated on ${formatDate(company.modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
)
cy.get('@metadataItems')
.eq(0)
diff --git a/test/functional/cypress/specs/omis/quote-spec.js b/test/functional/cypress/specs/omis/quote-spec.js
index 084d468cfea..2c269832920 100644
--- a/test/functional/cypress/specs/omis/quote-spec.js
+++ b/test/functional/cypress/specs/omis/quote-spec.js
@@ -6,9 +6,10 @@ import {
assertLocalHeader,
} from '../../support/assertions'
import {
- formatMediumDateParsed,
- formatMediumDateTime,
-} from '../../../../../src/client/utils/date'
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+ DATE_FORMAT_MEDIUM_WITH_TIME,
+} from '../../../../../src/client/utils/date-utils'
const {
cancelledOrder,
@@ -28,7 +29,10 @@ const assertSenderDetails = (quote) =>
.should('have.text', 'Sent on')
cy.get('[data-test="sent-on-date"]')
.should('exist')
- .should('have.text', formatMediumDateTime(quote.created_on))
+ .should(
+ 'have.text',
+ formatDate(quote.created_on, DATE_FORMAT_MEDIUM_WITH_TIME)
+ )
cy.get('[data-test="sent-by-heading"]')
.should('exist')
.should('have.text', 'Sent by')
@@ -44,7 +48,10 @@ const assertAcceptanceDetails = (quote) =>
.should('have.text', 'Accepted on')
cy.get('[data-test="accepted-on-date"]')
.should('exist')
- .should('have.text', formatMediumDateTime(quote.accepted_on))
+ .should(
+ 'have.text',
+ formatDate(quote.accepted_on, DATE_FORMAT_MEDIUM_WITH_TIME)
+ )
cy.get('[data-test="accepted-by-heading"]')
.should('exist')
.should('have.text', 'Accepted by')
@@ -86,7 +93,10 @@ describe('Order quote', () => {
.should('have.text', 'Will expire on')
cy.get('[data-test="expiry-date"]')
.should('exist')
- .should('have.text', formatMediumDateParsed(quotePreview.expires_on))
+ .should(
+ 'have.text',
+ formatDate(quotePreview.expires_on, DATE_FORMAT_MEDIUM)
+ )
})
it('should display the warning message', () => {
@@ -142,7 +152,7 @@ describe('Order quote', () => {
.should('exist')
.should(
'have.text',
- formatMediumDateParsed(quoteNotAccepted.expires_on)
+ formatDate(quoteNotAccepted.expires_on, DATE_FORMAT_MEDIUM)
)
})
@@ -224,7 +234,10 @@ describe('Order quote', () => {
.should('have.text', 'Cancelled on')
cy.get('[data-test="cancelled-on-date"]')
.should('exist')
- .should('have.text', formatMediumDateTime(quoteCancelled.cancelled_on))
+ .should(
+ 'have.text',
+ formatDate(quoteCancelled.cancelled_on, DATE_FORMAT_MEDIUM_WITH_TIME)
+ )
cy.get('[data-test="cancelled-by-heading"]')
.should('exist')
.should('have.text', 'Cancelled by')
diff --git a/test/functional/cypress/specs/reminders/export-new-interactions-list-spec.js b/test/functional/cypress/specs/reminders/export-new-interactions-list-spec.js
index 55d64670af4..49c4d5c1aa9 100644
--- a/test/functional/cypress/specs/reminders/export-new-interactions-list-spec.js
+++ b/test/functional/cypress/specs/reminders/export-new-interactions-list-spec.js
@@ -6,7 +6,10 @@ import {
nestedInteractionFaker,
reminderListFaker,
} from '../../fakers/reminders'
-import { formatMediumDateParsed } from '../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+} from '../../../../../src/client/utils/date-utils'
const remindersEndpoint = '/api-proxy/v4/reminder/new-export-interaction'
@@ -333,8 +336,9 @@ describe('Exports New Interaction Reminders', () => {
.find('[data-test="item-content"]')
.should(
'contain',
- `Received ${formatMediumDateParsed(
- deleted_reminder_date.toISOString()
+ `Received ${formatDate(
+ deleted_reminder_date.toISOString(),
+ DATE_FORMAT_MEDIUM
)} for ${reminders[4].company.name}`
)
.find('a')
diff --git a/test/functional/cypress/specs/reminders/export-no-recent-interactions-list-spec.js b/test/functional/cypress/specs/reminders/export-no-recent-interactions-list-spec.js
index aa1e038c16a..478b0934bd9 100644
--- a/test/functional/cypress/specs/reminders/export-no-recent-interactions-list-spec.js
+++ b/test/functional/cypress/specs/reminders/export-no-recent-interactions-list-spec.js
@@ -6,7 +6,10 @@ import {
nestedInteractionFaker,
reminderListFaker,
} from '../../fakers/reminders'
-import { formatMediumDateParsed } from '../../../../../src/client/utils/date'
+import {
+ formatDate,
+ DATE_FORMAT_MEDIUM,
+} from '../../../../../src/client/utils/date-utils'
const remindersEndpoint = '/api-proxy/v4/reminder/no-recent-export-interaction'
@@ -138,7 +141,7 @@ describe('Exports no recent Interaction Reminders', () => {
.find('[data-test="item-content"]')
.should(
'contain',
- `${formatMediumDateParsed(reminders[0].last_interaction_date)}`
+ `${formatDate(reminders[0].last_interaction_date, DATE_FORMAT_MEDIUM)}`
)
})
})
@@ -343,8 +346,9 @@ describe('Exports no recent Interaction Reminders', () => {
.find('[data-test="item-content"]')
.should(
'contain',
- `Received ${formatMediumDateParsed(
- deleted_reminder_date.toISOString()
+ `Received ${formatDate(
+ deleted_reminder_date.toISOString(),
+ DATE_FORMAT_MEDIUM
)} for ${reminders[4].company.name}`
)
.find('a')