Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDVA5-161-date-formation #211

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locales/cy/is-this-your-company.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"incorporationDate": "Incorporation date welsh",
"companyType": "Company type welsh",
"registeredOfficeAddress": "Registered office address welsh",
"correspondaceAddress": "Correspondance address welsh",
"correspondaceAddress": "Correspondence address welsh",
"confirm": "Confirm and continue welsh",
"chooseADifferentCompany": "Choose a different company welsh"
}
4 changes: 2 additions & 2 deletions locales/en/is-this-your-company.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"companyNumber": "Company number",
"status": "Status",
"incorporationDate": "Incorporation date",
"companyType": "Company type welsh",
"companyType": "Company type",
"registeredOfficeAddress": "Registered office address",
"correspondaceAddress": "Correspondance address",
"correspondaceAddress": "Correspondence address",
"confirm": "Confirm and continue",
"chooseADifferentCompany": "Choose a different company"
}
93 changes: 60 additions & 33 deletions package-lock.json

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

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@
"@companieshouse/web-security-node": "^2.0.3",
"axios": "1.6.2",
"cookie-parser": "^1.4.6",
"express": "4.18.2",
"express": "^4.19.2",
"express-validator": "^6.14.0",
"govuk_frontend_toolkit": "^9.0.1",
"govuk-elements-sass": "^3.1.3",
"govuk-frontend": "^4.7.0",
"http-errors": "^1.7.3",
"ioredis": "4.28.5",
"js-yaml": "^3.14.0",
"luxon": "^3.4.4",
"node-mocks-http": "^1.12.2",
"nunjucks": "^3.2.3",
"tslib": "^2.0.3",
"uuid": "8.0.0",
"yargs": "15.3.1",
"node-mocks-http": "^1.12.2"
"yargs": "15.3.1"
},
"devDependencies": {
"@types/cheerio": "^0.22.18",
Expand All @@ -56,6 +57,7 @@
"@types/ioredis": "4.14.9",
"@types/jest": "^29.5.11",
"@types/js-yaml": "^3.12.5",
"@types/luxon": "^3.4.2",
"@types/node": "^12.7.8",
"@types/nunjucks": "3.1.2",
"@types/supertest": "^2.0.16",
Expand All @@ -74,6 +76,7 @@
"gulp-concat": "^2.6.1",
"gulp-sass": "^5.1.0",
"gulp-uglify": "^3.0.2",
"http-status-codes": "^2.2.0",
"husky": "^4.3.8",
"jest": "^29.7.0",
"nock": "12.0.3",
Expand All @@ -83,8 +86,7 @@
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-node": "8.10.1",
"typescript": "4.9.5",
"http-status-codes": "^2.2.0"
"typescript": "4.9.5"
},
"@comments devDependencies": {
"@package sass": [
Expand Down
58 changes: 58 additions & 0 deletions src/main/common/__utils/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { DateTime } from "luxon";
import { createAndLogError } from "./logger";
import { CompanyOfficer } from "@companieshouse/api-sdk-node/dist/services/officer-filing";
import { formatAppointmentDate } from "./format";

export const toReadableFormat = (dateToConvert: string | undefined, lang = "en"): string => {
if (!dateToConvert) {
return "";
}
const jsDate = new Date(dateToConvert);
const dateTime = DateTime.fromJSDate(jsDate);
let convertedDate;
switch (lang) {
case "cy":
convertedDate = dateTime.setLocale("cy").toFormat("d MMMM yyyy");
break;
case "en":
default:
convertedDate = dateTime.setLocale("en").toFormat("d MMMM yyyy");
break;
}
if (convertedDate === "Invalid DateTime") {
throw createAndLogError(`Unable to convert provided date ${dateToConvert}`);
}

return convertedDate;
};

export const isInFuture = (dateToCheckISO: string): boolean => {
const today: DateTime = DateTime.now();
const dateToCheck: DateTime = DateTime.fromISO(dateToCheckISO);
const timeUnitDay = "day";

return dateToCheck.startOf(timeUnitDay) > today.startOf(timeUnitDay);
};

export const toReadableFormatMonthYear = (monthNum: number, year: number): string => {
const datetime = DateTime.fromObject({ month: monthNum });
const convertedMonth = datetime.toFormat("MMMM");

if (convertedMonth === "Invalid DateTime") {
throw createAndLogError(`toReadableFormatMonthYear() - Unable to convert provided month ${monthNum}`);
}

return `${convertedMonth} ${year}`;
};

export const setAppointedOnDate = (officer: CompanyOfficer): string => {
var appointedOn = formatAppointmentDate(officer.appointedOn);
if (appointedOn === "") {
appointedOn = "Before 1992";
}
return appointedOn;
};

export const buildDateString = (day: string, month: string, year: string): string => {
return year + "-" + month.padStart(2, "0") + "-" + day.padStart(2, "0"); // Get date in the format yyyy-mm-dd
};
Loading