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

include FY/CY details for annual reports #160

Merged
merged 1 commit into from
Nov 16, 2022
Merged
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 publisher/src/components/Reports/CreateReport.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test("displayed created reports", async () => {
});
});

const annualReport2020 = screen.getByText(/Annual Report 2020/i);
const annualReport2020 = screen.getByText(/Annual Report FY2020-2021/i);
const editor2 = screen.getByText(/Editor #2/i);

expect(annualReport2020).toBeInTheDocument();
Expand Down
5 changes: 4 additions & 1 deletion publisher/src/pages/Reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
normalizeString,
printCommaSeparatedList,
printElapsedDaysMonthsYearsSinceDate,
printReportFrequency,
printReportTitle,
removeSnakeCase,
} from "../utils";
Expand Down Expand Up @@ -217,7 +218,9 @@ const Reports: React.FC = () => {
</Cell>

{/* Status */}
<Cell capitalize>{report.frequency.toLowerCase()}</Cell>
<Cell capitalize>
{printReportFrequency(report.month, report.frequency)}
</Cell>

{/* Editors */}
<Cell
Expand Down
4 changes: 3 additions & 1 deletion publisher/src/stores/ReportStore.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ test("displayed reports", async () => {
// Arbitrary report dates included in mockJSON
const april2022 = await screen.findByText(/April 2022/i);
const december2020 = await screen.findByText(/December 2020/i);
const annualReport2019 = await screen.findByText(/Annual Report 2019/i);
const annualReport2019 = await screen.findByText(
/Annual Report FY2019-2020/i
);
expect(april2022).toBeInTheDocument();
expect(december2020).toBeInTheDocument();
expect(annualReport2019).toBeInTheDocument();
Expand Down
28 changes: 25 additions & 3 deletions publisher/src/utils/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,43 @@ export const printDateAsMonthYear = (month: number, year: number): string => {
};

/**
* @returns either "Annual Report [YEAR]" or "[MONTH] [YEAR]" as a string depending on frequency
* @example "Annual Report 2022" or "March 2022"
* @returns either "Annual Report CY[YEAR]", "Annual Report FY[YEAR]-[YEAR+1]" or "[MONTH] [YEAR]"
* as a string depending on frequency.
* @example "Annual Report CY2022" "Annual Report FY2022-2023" or "March 2022"
*/
export const printReportTitle = (
month: number,
year: number,
frequency: ReportFrequency
): string => {
if (frequency === "ANNUAL") {
return `Annual Report ${year}`;
if (month === 1) {
// CY stands for Calendar Year
return `Annual Report CY${year}`;
}
// FY stands for Fiscal Year
return `Annual Report FY${year}-${year + 1}`;
}

return printDateAsMonthYear(month, year);
};

/**
* @returns either "Annual", "Annual ([MONTH])" or "Monthly"
* as a string depending on frequency
* @example "Annual" "Annual (October)" or "March 2022"
*/
export const printReportFrequency = (
month: number,
frequency: ReportFrequency
): string => {
if (frequency === "ANNUAL" && month !== 1) {
return `${frequency.toLowerCase()} (${monthsByName[month]})`;
}

return frequency.toLowerCase();
};

/**
* @returns elapsed number of days since a provided date as a string
* @example 'today', 'yesterday', '2 days ago', '3 months ago', '5 years ago'
Expand Down