diff --git a/packages/wow-ui/src/components/Picker/RangeDatePicker.tsx b/packages/wow-ui/src/components/Picker/RangeDatePicker.tsx index 0f69fc61..03d65b42 100644 --- a/packages/wow-ui/src/components/Picker/RangeDatePicker.tsx +++ b/packages/wow-ui/src/components/Picker/RangeDatePicker.tsx @@ -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 & Omit & { @@ -48,8 +48,8 @@ const RangeDatePicker = forwardRef( }; 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 ( diff --git a/packages/wow-ui/src/components/Picker/SingleDatePicker.tsx b/packages/wow-ui/src/components/Picker/SingleDatePicker.tsx index 97bc1e98..6745d393 100644 --- a/packages/wow-ui/src/components/Picker/SingleDatePicker.tsx +++ b/packages/wow-ui/src/components/Picker/SingleDatePicker.tsx @@ -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 & Omit & { @@ -37,7 +37,7 @@ const SingleDatePicker = forwardRef( const selected = context?.selectedDate || propSelected!; const onSelect = context?.setSelectedDate || propOnSelect!; - const { year, month, day } = changeDateToString(selected); + const { year, month, day } = formatDateToString(selected); return ( diff --git a/packages/wow-ui/src/components/Picker/TimePicker.tsx b/packages/wow-ui/src/components/Picker/TimePicker.tsx index 75f0cd25..619c7da8 100644 --- a/packages/wow-ui/src/components/Picker/TimePicker.tsx +++ b/packages/wow-ui/src/components/Picker/TimePicker.tsx @@ -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< @@ -77,23 +75,6 @@ const TimePicker = forwardRef( }); }; - 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 ( diff --git a/packages/wow-ui/src/utils/changeDateToString.ts b/packages/wow-ui/src/utils/changeDateToString.ts deleted file mode 100644 index 89913d68..00000000 --- a/packages/wow-ui/src/utils/changeDateToString.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const changeDateToString = (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 }; -}; diff --git a/packages/wow-ui/src/utils/formatToString.ts b/packages/wow-ui/src/utils/formatToString.ts new file mode 100644 index 00000000..6912427e --- /dev/null +++ b/packages/wow-ui/src/utils/formatToString.ts @@ -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 }; +};