This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from ruchernchong/41-clean-up-date-format
Clean up date formats
- Loading branch information
Showing
11 changed files
with
51 additions
and
89 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
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
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { differenceInYears, parse } from "date-fns"; | ||
import moment from "moment"; | ||
|
||
export const convertBirthDateToAge = (birthDate: string) => { | ||
const parsedDate = parse(birthDate, "MM/yyyy", new Date()); | ||
const parsedDate = moment(birthDate, "MM/YYYY"); | ||
const currentDate = moment(); | ||
|
||
const currentDate = new Date(); | ||
|
||
return differenceInYears(currentDate, parsedDate); | ||
return currentDate.diff(parsedDate, "years"); | ||
}; |
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 |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import { closestTo, format, parse } from "date-fns"; | ||
import moment from "moment"; | ||
import { formatDate } from "./format"; | ||
import { CPFIncomeCeiling } from "../types"; | ||
|
||
export const findLatestIncomeCeilingDate = ( | ||
dates: CPFIncomeCeiling[] | ||
): string => { | ||
const currentDate = new Date(); | ||
const currentDate = moment(); | ||
|
||
const pastDates = dates | ||
.map(({ effectiveDate, ceiling }) => ({ | ||
effectiveDate: parse(effectiveDate, "MM-yyyy", new Date()), | ||
effectiveDate: moment(effectiveDate, "MM-DD-YYYY"), | ||
ceiling, | ||
})) | ||
.filter(({ effectiveDate }) => effectiveDate < currentDate); | ||
.filter(({ effectiveDate }) => effectiveDate.isBefore(currentDate)); | ||
|
||
const closestPastDate = closestTo( | ||
currentDate, | ||
const closestPastDate = moment.max( | ||
pastDates.map(({ effectiveDate }) => effectiveDate) | ||
); | ||
|
||
if (closestPastDate) { | ||
return formatDateStandard(closestPastDate); | ||
return formatDate(closestPastDate, "MM-DD-YYYY"); | ||
} | ||
|
||
return formatDateStandard( | ||
pastDates.reverse().map(({ effectiveDate }) => effectiveDate)[0] | ||
return formatDate( | ||
pastDates.reverse().map(({ effectiveDate }) => effectiveDate)[0], | ||
"MM-DD-YYYY" | ||
); | ||
}; | ||
|
||
const formatDateStandard = (date: Date) => format(date, "MM-yyyy"); |
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