-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: displays CAN obligate_by as MM/DD/YY (#2873)
- Loading branch information
Showing
8 changed files
with
183 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Gets the last day of the fiscal year for a given year. | ||
* @param {number} fiscalYear - The fiscal year | ||
* @returns {Date} The last day of the fiscal year | ||
*/ | ||
const getLastDayOfFiscalYear = (fiscalYear) => { | ||
// Fiscal year ends on September 30 of the previous calendar year | ||
return new Date(fiscalYear - 1, 8, 30); // Month is 0-indexed, so 8 is September | ||
}; | ||
/** | ||
* Formats the obligate by date to the last day of the fiscal year. | ||
* @param {number | undefined} obligateBy - The obligate by value | ||
* @returns {string} Formatted date string or "TBD" | ||
*/ | ||
export const formatObligateBy = (obligateBy) => { | ||
if (!obligateBy) return "TBD"; // Default value | ||
if (typeof obligateBy !== "number" || isNaN(obligateBy)) return "TBD"; // Default if parsing fails | ||
|
||
const lastDay = getLastDayOfFiscalYear(obligateBy); | ||
|
||
// Format as MM/DD/YY | ||
return lastDay.toLocaleDateString("en-US", { | ||
month: "2-digit", | ||
day: "2-digit", | ||
year: "2-digit" | ||
}); | ||
}; |
24 changes: 24 additions & 0 deletions
24
frontend/src/components/CANs/CANTable/CANTable.helpers.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { formatObligateBy } from "./CANTable.helpers"; | ||
|
||
describe("formatObligateBy", () => { | ||
test('returns "TBD" for undefined input', () => { | ||
expect(formatObligateBy(undefined)).toBe("TBD"); | ||
}); | ||
|
||
test('returns "TBD" for non-numeric input', () => { | ||
expect(formatObligateBy("not a number")).toBe("TBD"); | ||
}); | ||
|
||
test('returns "TBD" for NaN input', () => { | ||
expect(formatObligateBy(NaN)).toBe("TBD"); | ||
}); | ||
|
||
test("formats valid fiscal year correctly", () => { | ||
expect(formatObligateBy(2023)).toBe("09/30/22"); | ||
}); | ||
|
||
test("handles different fiscal years", () => { | ||
expect(formatObligateBy(2024)).toBe("09/30/23"); | ||
expect(formatObligateBy(2025)).toBe("09/30/24"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Tooltip from "../../UI/USWDS/Tooltip"; | ||
|
||
const CANTableHead = () => { | ||
const availbleTooltip = | ||
"$ Available is the remaining amount of the total budget that is available to plan from (Total FY Budget minus budget lines in Planned, Executing or Obligated Status)"; | ||
|
||
return ( | ||
<thead> | ||
<tr> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
CAN | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Portfolio | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
FY | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Active Period | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Obligate By | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Transfer | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
FY Budget | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
<Tooltip label={availbleTooltip}> | ||
<span>$ Available</span> | ||
</Tooltip> | ||
</th> | ||
</tr> | ||
</thead> | ||
); | ||
}; | ||
|
||
export default CANTableHead; |
Oops, something went wrong.