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"
|
import { testing } from "./getAge"
|
||||||
|
|
||||||
const { birth, dateFormatOption, getAge, ageInt, ageDecimal, isOverBirthDay } =
|
const { birth, getAge, ageInt, ageDecimal, isOverBirthDay } = testing
|
||||||
testing
|
|
||||||
|
|
||||||
describe("getAge tests", () => {
|
describe("getAge tests", () => {
|
||||||
test("birthday to be 2002-07-30", () => {
|
test("birthday to be 2002-07-30", () => {
|
||||||
|
@ -73,15 +72,6 @@ describe("getAge tests", () => {
|
||||||
expect(isOverBirthDay(date)).toEqual(testData.overBD)
|
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", () => {
|
test("ageInt to work", () => {
|
||||||
expect(ageInt(birth)).toEqual(0)
|
expect(ageInt(birth)).toEqual(0)
|
||||||
expect(ageInt(new Date("2023-07-29"))).toEqual(20)
|
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
|
// my birthday in KST :D
|
||||||
const birth = new Date(
|
const birth = new Date("2002-07-30, 00:00:00.000 +09:00")
|
||||||
new Date("2002-07-30, 00:00:00.000 +09:00").toLocaleString(
|
|
||||||
"en-US",
|
|
||||||
dateFormatOption
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets developomp's age with decimal precision
|
* Gets developomp's age with decimal precision
|
||||||
*
|
*
|
||||||
* @param now - current `Date` in KST
|
* @param now - current `Date` in KST
|
||||||
*/
|
*/
|
||||||
export default function getAge(
|
export default function getAge(now: Date = new Date()): number {
|
||||||
now: Date = new Date(new Date().toLocaleString("en-US", dateFormatOption))
|
|
||||||
): number {
|
|
||||||
return ageInt(now) + ageDecimal(now)
|
return ageInt(now) + ageDecimal(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +56,6 @@ function isOverBirthDay(now: Date): boolean {
|
||||||
|
|
||||||
export const testing = {
|
export const testing = {
|
||||||
birth,
|
birth,
|
||||||
dateFormatOption,
|
|
||||||
getAge,
|
getAge,
|
||||||
ageInt,
|
ageInt,
|
||||||
ageDecimal,
|
ageDecimal,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue