Skip to content

Commit

Permalink
refactor: format~ 함수 util로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Aug 26, 2024
1 parent fd61907 commit c78f1fb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages/wow-ui/src/components/Picker/RangeDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DayPicker } from "react-day-picker";
import DateDropDown from "@/components/Picker/DateDropDown";
import pickerClassNames from "@/components/Picker/pickerClassNames";
import pickerComponents from "@/components/Picker/pickerComponents";
import { changeDateToString } from "@/utils/changeDateToString";
import { formatDateToString } from "@/utils/formatToString";

export type DatePickerProps = Omit<PropsBase, "mode"> &
Omit<PropsRange, "mode"> & {
Expand Down Expand Up @@ -48,8 +48,8 @@ const RangeDatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
};

const strDate = prevSelected && {
from: prevSelected.from && changeDateToString(prevSelected.from),
to: prevSelected.to && changeDateToString(prevSelected?.to),
from: prevSelected.from && formatDateToString(prevSelected.from),
to: prevSelected.to && formatDateToString(prevSelected?.to),
};

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/wow-ui/src/components/Picker/SingleDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { pickerButtonStyle } from "@/components/Picker/pickerButtonStyle.css";
import pickerClassNames from "@/components/Picker/pickerClassNames";
import pickerComponents from "@/components/Picker/pickerComponents";
import { usePicker } from "@/components/Picker/PickerContext";
import { changeDateToString } from "@/utils/changeDateToString";
import { formatDateToString } from "@/utils/formatToString";

export type DatePickerProps = Omit<PropsBase, "mode"> &
Omit<PropsSingle, "mode"> & {
Expand All @@ -37,7 +37,7 @@ const SingleDatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
const selected = context?.selectedDate || propSelected!;
const onSelect = context?.setSelectedDate || propOnSelect!;

const { year, month, day } = changeDateToString(selected);
const { year, month, day } = formatDateToString(selected);

return (
<Flex direction="column" gap="0.75rem" ref={ref} width="19.75rem">
Expand Down
23 changes: 2 additions & 21 deletions packages/wow-ui/src/components/Picker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { forwardRef, useMemo, useState } from "react";
import DropDown from "@/components/DropDown";
import DropDownOption from "@/components/DropDown/DropDownOption";
import { pickerButtonStyle } from "@/components/Picker/pickerButtonStyle.css";
import type {
PickerContextProps,
Time,
} from "@/components/Picker/PickerContext";
import type { PickerContextProps } from "@/components/Picker/PickerContext";
import { usePicker } from "@/components/Picker/PickerContext";
import { formatTimeToString } from "@/utils/formatToString";

interface TimePickerProps
extends Partial<
Expand Down Expand Up @@ -77,23 +75,6 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
});
};

const formatNumberToStirng = (number: number) => {
return number.toString().padStart(2, "0");
};

const formatTimeToString = (time: Time) => {
const transformedHour = () => {
if (time.hour === 0) return 12;
if (time.hour > 12) return time.hour - 12;
return time.hour;
};

const hour = formatNumberToStirng(transformedHour());
const minute = formatNumberToStirng(time.minute);

return { hour, minute };
};

const strTime = formatTimeToString(selectedTime);

return (
Expand Down
8 changes: 0 additions & 8 deletions packages/wow-ui/src/utils/changeDateToString.ts

This file was deleted.

27 changes: 27 additions & 0 deletions packages/wow-ui/src/utils/formatToString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Time } from "@/components/Picker/PickerContext";

export const formatNumberToStirng = (number: number) => {
return number.toString().padStart(2, "0");
};

export const formatTimeToString = (time: Time) => {
const transformedHour = () => {
if (time.hour === 0) return 12;
if (time.hour > 12) return time.hour - 12;
return time.hour;
};

const hour = formatNumberToStirng(transformedHour());
const minute = formatNumberToStirng(time.minute);

return { hour, minute };
};

export const formatDateToString = (selected: Date) => {
const year = selected?.getFullYear().toString();
const month =
selected && (selected.getMonth() + 1).toString().padStart(2, "0");
const day = selected?.getDate().toString().padStart(2, "0");

return { year, month, day };
};

0 comments on commit c78f1fb

Please sign in to comment.