refactor: remove unnecessary code
This commit is contained in:
parent
08a0f967e3
commit
2a0a78bd3e
2 changed files with 3 additions and 34 deletions
|
@ -1,7 +1,6 @@
|
|||
import { testing } from "./getAge"
|
||||
|
||||
const { birth, dateFormatOption, getAge, ageInt, ageDecimal, isOverBirthDay } =
|
||||
testing
|
||||
const { birth, getAge, ageInt, ageDecimal, isOverBirthDay } = testing
|
||||
|
||||
describe("getAge tests", () => {
|
||||
test("birthday to be 2002-07-30", () => {
|
||||
|
@ -73,15 +72,6 @@ describe("getAge tests", () => {
|
|||
expect(isOverBirthDay(date)).toEqual(testData.overBD)
|
||||
})
|
||||
|
||||
test("dateFormatOption to work properly", () => {
|
||||
expect(
|
||||
new Date("2002-07-30, 00:00:00.000 +09:00").toLocaleString(
|
||||
"en-US",
|
||||
dateFormatOption
|
||||
)
|
||||
).toEqual("7/30/2002, 00:00:00.000 GMT+09:00")
|
||||
})
|
||||
|
||||
test("ageInt to work", () => {
|
||||
expect(ageInt(birth)).toEqual(0)
|
||||
expect(ageInt(new Date("2023-07-29"))).toEqual(20)
|
||||
|
|
|
@ -1,32 +1,12 @@
|
|||
const dateFormatOption: Intl.DateTimeFormatOptions = {
|
||||
timeZone: "Asia/Seoul",
|
||||
timeZoneName: "longOffset",
|
||||
hourCycle: "h23",
|
||||
year: "numeric",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
second: "numeric",
|
||||
fractionalSecondDigits: 3,
|
||||
}
|
||||
|
||||
// my birthday in KST :D
|
||||
const birth = new Date(
|
||||
new Date("2002-07-30, 00:00:00.000 +09:00").toLocaleString(
|
||||
"en-US",
|
||||
dateFormatOption
|
||||
)
|
||||
)
|
||||
const birth = new Date("2002-07-30, 00:00:00.000 +09:00")
|
||||
|
||||
/**
|
||||
* Gets developomp's age with decimal precision
|
||||
*
|
||||
* @param now - current `Date` in KST
|
||||
*/
|
||||
export default function getAge(
|
||||
now: Date = new Date(new Date().toLocaleString("en-US", dateFormatOption))
|
||||
): number {
|
||||
export default function getAge(now: Date = new Date()): number {
|
||||
return ageInt(now) + ageDecimal(now)
|
||||
}
|
||||
|
||||
|
@ -76,7 +56,6 @@ function isOverBirthDay(now: Date): boolean {
|
|||
|
||||
export const testing = {
|
||||
birth,
|
||||
dateFormatOption,
|
||||
getAge,
|
||||
ageInt,
|
||||
ageDecimal,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue