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 #44 from ruchernchong/43-refactor-moment-to-date-fns
Refactor moment to date-fns
- Loading branch information
Showing
7 changed files
with
31 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import moment from "moment"; | ||
import { differenceInYears, parse } from "date-fns"; | ||
|
||
export const convertBirthDateToAge = (birthDate: string) => { | ||
const parsedDate = moment(birthDate, "MM/YYYY"); | ||
const currentDate = moment(); | ||
const parsedDate = parse(birthDate, "MM/yyyy", new Date()); | ||
const currentDate = new Date(); | ||
|
||
return currentDate.diff(parsedDate, "years"); | ||
return differenceInYears(currentDate, parsedDate); | ||
}; |
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,29 +1,29 @@ | ||
import moment from "moment"; | ||
import { closestTo, max, parse } from "date-fns"; | ||
import { formatDate } from "./format"; | ||
import { CPFIncomeCeiling } from "../types"; | ||
|
||
export const findLatestIncomeCeilingDate = ( | ||
dates: CPFIncomeCeiling[] | ||
): string => { | ||
const currentDate = moment(); | ||
const currentDate = new Date(); | ||
|
||
const pastDates = dates | ||
.map(({ effectiveDate, ceiling }) => ({ | ||
effectiveDate: moment(effectiveDate, "MM-DD-YYYY"), | ||
effectiveDate: parse(effectiveDate, "MM-dd-yyyy", new Date()), | ||
ceiling, | ||
})) | ||
.filter(({ effectiveDate }) => effectiveDate.isBefore(currentDate)); | ||
.filter(({ effectiveDate }) => effectiveDate < currentDate); | ||
|
||
const closestPastDate = moment.max( | ||
const closestPastDate = closestTo( | ||
currentDate, | ||
pastDates.map(({ effectiveDate }) => effectiveDate) | ||
); | ||
|
||
if (closestPastDate) { | ||
return formatDate(closestPastDate, "MM-DD-YYYY"); | ||
return formatDate(closestPastDate, "MM-dd-yyyy"); | ||
} | ||
|
||
return formatDate( | ||
pastDates.reverse().map(({ effectiveDate }) => effectiveDate)[0], | ||
"MM-DD-YYYY" | ||
); | ||
const latestDate = max(pastDates.map(({ effectiveDate }) => effectiveDate)); | ||
|
||
return formatDate(latestDate, "MM-dd-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