Skip to content

Commit 797608e

Browse files
committed
fix : timeselector, zero value를 failure 처리 하던 현상
version 2.0.5
1 parent deae283 commit 797608e

File tree

5 files changed

+26
-28
lines changed

5 files changed

+26
-28
lines changed

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shinyongjun/react-datepicker",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"main": "./dist/cjs/index.js",
55
"module": "./dist/esm/index.js",
66
"source": "./src/index.tsx",

package/src/components/input/InputUnit.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ function InputUnit({
9696
month,
9797
date,
9898
}: {
99-
year?: string | number | null;
100-
month?: string | number | null;
101-
date?: string | number | null;
99+
year: number | null;
100+
month: number | null;
101+
date: number | null;
102102
}) => {
103103
setDateValue({
104-
year: year ? year : dateValue.year,
105-
month: month ? Number(month) - 1 : dateValue.month,
106-
date: date ? date : dateValue.date,
104+
year: year !== null ? year : dateValue.year,
105+
month: month !== null ? month : dateValue.month,
106+
date: date !== null ? date : dateValue.date,
107107
});
108108
};
109109

@@ -112,14 +112,14 @@ function InputUnit({
112112
minute,
113113
second,
114114
}: {
115-
hour?: string | number | null;
116-
minute?: string | number | null;
117-
second?: string | number | null;
115+
hour: number | null;
116+
minute: number | null;
117+
second: number | null;
118118
}) => {
119119
setTimeValue({
120-
hour: hour ? Number(hour) : timeValue.hour,
121-
minute: minute ? Number(minute) : timeValue.minute,
122-
second: second ? Number(second) : timeValue.second,
120+
hour: hour !== null ? hour : timeValue.hour,
121+
minute: minute !== null ? minute : timeValue.minute,
122+
second: second !== null ? second : timeValue.second,
123123
});
124124
};
125125

@@ -153,28 +153,28 @@ function InputUnit({
153153

154154
switch (type) {
155155
case 'YYYY':
156-
utilSetDateValue({ year: text });
156+
utilSetDateValue({ ...dateValue, year: Number(text) });
157157
setViewDate(
158158
`${text}-${viewDate.split('-')[1]}-${viewDate.split('-')[2]}`
159159
);
160160
return;
161161
case 'MM':
162-
utilSetDateValue({ month: text });
162+
utilSetDateValue({ ...dateValue, month: Number(text) - 1 });
163163
setViewDate(
164164
`${viewDate.split('-')[0]}-${text}-${viewDate.split('-')[2]}`
165165
);
166166
return;
167167
case 'DD':
168-
utilSetDateValue({ date: text });
168+
utilSetDateValue({ ...dateValue, date: Number(text) });
169169
return;
170170
case 'hh':
171-
utilSetTimeValue({ hour: text });
171+
utilSetTimeValue({ ...timeValue, hour: Number(text) });
172172
return;
173173
case 'mm':
174-
utilSetTimeValue({ minute: text });
174+
utilSetTimeValue({ ...timeValue, minute: Number(text) });
175175
return;
176176
case 'ss':
177-
utilSetTimeValue({ second: text });
177+
utilSetTimeValue({ ...timeValue, second: Number(text) });
178178
return;
179179
default:
180180
return;

package/src/components/timeselector/SelectorList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function TimeselectorSelectorList({
4444
onClick={() =>
4545
setTimeValue({
4646
...timeValue,
47-
...{ [timeKey]: item },
47+
[timeKey]: item,
4848
})
4949
}
5050
>

package/src/types/props.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export interface ITimeValue {
1111
}
1212

1313
export interface IDateValue {
14-
year: number | string | null;
15-
month: number | string | null;
16-
date: number | string | null;
14+
year: number | null;
15+
month: number | null;
16+
date: number | null;
1717
}
1818

1919
export type TIsVisible = boolean | 'start' | 'end';

package/src/utils/datetime.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ export const getDateValueUnit = (value: IDateValue, unit: string): string => {
7171
};
7272

7373
export const getTimeValueUnit = (value: ITimeValue, unit: string): string => {
74-
if (!value) return unit;
75-
7674
switch (unit) {
7775
case 'hh':
78-
return value.hour ? addLeadingZero(value.hour) : 'hh';
76+
return addLeadingZero(value.hour);
7977
case 'mm':
80-
return value.minute ? addLeadingZero(value.minute) : 'mm';
78+
return addLeadingZero(value.minute);
8179
case 'ss':
82-
return value.second ? addLeadingZero(value.second) : 'ss';
80+
return addLeadingZero(value.second);
8381
default:
8482
return '';
8583
}

0 commit comments

Comments
 (0)