@idealyst/datepicker 1.2.42 → 1.2.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/datepicker",
3
- "version": "1.2.42",
3
+ "version": "1.2.44",
4
4
  "description": "Cross-platform date and time picker components for React and React Native",
5
5
  "documentation": "https://github.com/IdealystIO/idealyst-framework/tree/main/packages/datepicker#readme",
6
6
  "readme": "README.md",
@@ -36,7 +36,7 @@
36
36
  "publish:npm": "npm publish"
37
37
  },
38
38
  "peerDependencies": {
39
- "@idealyst/theme": "^1.2.42",
39
+ "@idealyst/theme": "^1.2.44",
40
40
  "@mdi/js": ">=7.0.0",
41
41
  "@mdi/react": ">=1.6.0",
42
42
  "react": ">=16.8.0",
@@ -69,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@idealyst/theme": "^1.2.42",
72
+ "@idealyst/theme": "^1.2.44",
73
73
  "@mdi/js": "^7.4.47",
74
74
  "@mdi/react": "^1.6.1",
75
75
  "@types/react": "^19.1.0",
@@ -41,12 +41,12 @@ export const DateInput: React.FC<DateInputProps> = ({
41
41
  return `${month}/${day}/${year}`;
42
42
  };
43
43
 
44
- // Parse string to date
44
+ // Parse string to date (use noon to avoid timezone issues)
45
45
  const parseDate = (str: string): Date | null => {
46
46
  const match = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
47
47
  if (!match) return null;
48
48
  const [, month, day, year] = match;
49
- const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
49
+ const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), 12, 0, 0, 0);
50
50
  if (isNaN(date.getTime())) return null;
51
51
  return date;
52
52
  };
@@ -56,12 +56,12 @@ export const DateInput: React.FC<DateInputProps> = ({
56
56
  return `${month}/${day}/${year}`;
57
57
  };
58
58
 
59
- // Parse string to date
59
+ // Parse string to date (use noon to avoid timezone issues)
60
60
  const parseDate = (str: string): Date | null => {
61
61
  const match = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
62
62
  if (!match) return null;
63
63
  const [, month, day, year] = match;
64
- const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
64
+ const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), 12, 0, 0, 0);
65
65
  if (isNaN(date.getTime())) return null;
66
66
  return date;
67
67
  };
@@ -94,8 +94,6 @@ export const DateInput: React.FC<DateInputProps> = ({
94
94
  };
95
95
 
96
96
  const handleDateSelect = (date: Date) => {
97
- console.log('[DateInput] handleDateSelect received:', date.toISOString());
98
- console.log('[DateInput] Calling onChange with:', date.toISOString());
99
97
  onChange(date);
100
98
  setOpen(false);
101
99
  };
@@ -56,24 +56,27 @@ export const DatePicker: React.FC<DatePickerProps> = ({
56
56
  const days: Array<{ date: Date; isCurrentMonth: boolean }> = [];
57
57
 
58
58
  // Previous month padding
59
+ // Use noon (12:00) to avoid timezone issues when date crosses day boundaries
59
60
  const prevMonthEnd = new Date(year, month, 0);
60
61
  for (let i = startPadding - 1; i >= 0; i--) {
61
62
  days.push({
62
- date: new Date(year, month - 1, prevMonthEnd.getDate() - i),
63
+ date: new Date(year, month - 1, prevMonthEnd.getDate() - i, 12, 0, 0, 0),
63
64
  isCurrentMonth: false,
64
65
  });
65
66
  }
66
67
 
67
68
  // Current month
69
+ // Use noon (12:00) to avoid timezone issues when date crosses day boundaries
68
70
  for (let day = 1; day <= daysInMonth; day++) {
69
- days.push({ date: new Date(year, month, day), isCurrentMonth: true });
71
+ days.push({ date: new Date(year, month, day, 12, 0, 0, 0), isCurrentMonth: true });
70
72
  }
71
73
 
72
74
  // Next month padding (fill to complete last week)
75
+ // Use noon (12:00) to avoid timezone issues when date crosses day boundaries
73
76
  const remaining = 7 - (days.length % 7);
74
77
  if (remaining < 7) {
75
78
  for (let day = 1; day <= remaining; day++) {
76
- days.push({ date: new Date(year, month + 1, day), isCurrentMonth: false });
79
+ days.push({ date: new Date(year, month + 1, day, 12, 0, 0, 0), isCurrentMonth: false });
77
80
  }
78
81
  }
79
82
 
@@ -100,8 +103,16 @@ export const DatePicker: React.FC<DatePickerProps> = ({
100
103
 
101
104
  const isDisabled = (date: Date): boolean => {
102
105
  if (disabled) return true;
103
- if (minDate && date < new Date(minDate.setHours(0, 0, 0, 0))) return true;
104
- if (maxDate && date > new Date(maxDate.setHours(23, 59, 59, 999))) return true;
106
+ // Normalize dates for comparison without mutating the original props
107
+ const normalizedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
108
+ if (minDate) {
109
+ const min = new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate());
110
+ if (normalizedDate < min) return true;
111
+ }
112
+ if (maxDate) {
113
+ const max = new Date(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate());
114
+ if (normalizedDate > max) return true;
115
+ }
105
116
  return false;
106
117
  };
107
118
 
@@ -115,7 +126,9 @@ export const DatePicker: React.FC<DatePickerProps> = ({
115
126
 
116
127
  const handleDayPress = (date: Date) => {
117
128
  if (!isDisabled(date)) {
118
- onChange(date);
129
+ // Create a new date with noon time to avoid timezone issues
130
+ const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12, 0, 0, 0);
131
+ onChange(newDate);
119
132
  }
120
133
  };
121
134
 
@@ -39,24 +39,27 @@ export const DatePicker: React.FC<DatePickerProps> = ({
39
39
  const days: Array<{ date: Date; isCurrentMonth: boolean }> = [];
40
40
 
41
41
  // Previous month padding
42
+ // Use noon (12:00) to avoid timezone issues when date crosses day boundaries
42
43
  const prevMonthEnd = new Date(year, month, 0);
43
44
  for (let i = startPadding - 1; i >= 0; i--) {
44
45
  days.push({
45
- date: new Date(year, month - 1, prevMonthEnd.getDate() - i),
46
+ date: new Date(year, month - 1, prevMonthEnd.getDate() - i, 12, 0, 0, 0),
46
47
  isCurrentMonth: false,
47
48
  });
48
49
  }
49
50
 
50
51
  // Current month
52
+ // Use noon (12:00) to avoid timezone issues when date crosses day boundaries
51
53
  for (let day = 1; day <= daysInMonth; day++) {
52
- days.push({ date: new Date(year, month, day), isCurrentMonth: true });
54
+ days.push({ date: new Date(year, month, day, 12, 0, 0, 0), isCurrentMonth: true });
53
55
  }
54
56
 
55
57
  // Next month padding (fill to complete last week)
58
+ // Use noon (12:00) to avoid timezone issues when date crosses day boundaries
56
59
  const remaining = 7 - (days.length % 7);
57
60
  if (remaining < 7) {
58
61
  for (let day = 1; day <= remaining; day++) {
59
- days.push({ date: new Date(year, month + 1, day), isCurrentMonth: false });
62
+ days.push({ date: new Date(year, month + 1, day, 12, 0, 0, 0), isCurrentMonth: false });
60
63
  }
61
64
  }
62
65
 
@@ -105,12 +108,9 @@ export const DatePicker: React.FC<DatePickerProps> = ({
105
108
  };
106
109
 
107
110
  const handleDayPress = (date: Date) => {
108
- console.log('[DatePicker] handleDayPress called with:', date.toISOString());
109
- console.log('[DatePicker] isDisabled:', isDisabled(date));
110
111
  if (!isDisabled(date)) {
111
- // Create a new date to avoid mutating the calendar's date objects
112
- const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
113
- console.log('[DatePicker] Calling onChange with:', newDate.toISOString());
112
+ // Create a new date with noon time to avoid timezone issues
113
+ const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12, 0, 0, 0);
114
114
  onChange(newDate);
115
115
  }
116
116
  };
@@ -31,8 +31,15 @@ export const DateTimePicker: React.FC<DateTimePickerProps> = ({
31
31
  // Preserve time from current value, or use noon as default
32
32
  const hours = value?.getHours() ?? 12;
33
33
  const minutes = value?.getMinutes() ?? 0;
34
- const updated = new Date(date);
35
- updated.setHours(hours, minutes, 0, 0);
34
+ const updated = new Date(
35
+ date.getFullYear(),
36
+ date.getMonth(),
37
+ date.getDate(),
38
+ hours,
39
+ minutes,
40
+ 0,
41
+ 0
42
+ );
36
43
  onChange(updated);
37
44
  };
38
45
 
@@ -40,8 +47,15 @@ export const DateTimePicker: React.FC<DateTimePickerProps> = ({
40
47
  if (!time) {
41
48
  // Only clear time component, keep date if it exists
42
49
  if (value) {
43
- const updated = new Date(value);
44
- updated.setHours(12, 0, 0, 0);
50
+ const updated = new Date(
51
+ value.getFullYear(),
52
+ value.getMonth(),
53
+ value.getDate(),
54
+ 12,
55
+ 0,
56
+ 0,
57
+ 0
58
+ );
45
59
  onChange(updated);
46
60
  }
47
61
  return;
@@ -26,8 +26,6 @@ export const DateTimePicker: React.FC<DateTimePickerProps> = ({
26
26
  const inputColumnStyle = (styles.inputColumn as any)({});
27
27
 
28
28
  const handleDateChange = (date: Date | null) => {
29
- console.log('[DateTimePicker] handleDateChange received:', date?.toISOString());
30
- console.log('[DateTimePicker] Current value:', value?.toISOString());
31
29
  if (!date) {
32
30
  onChange(null);
33
31
  return;
@@ -35,23 +33,31 @@ export const DateTimePicker: React.FC<DateTimePickerProps> = ({
35
33
  // Preserve time from current value, or use noon as default
36
34
  const hours = value?.getHours() ?? 12;
37
35
  const minutes = value?.getMinutes() ?? 0;
38
- console.log('[DateTimePicker] Preserving hours:', hours, 'minutes:', minutes);
39
- const updated = new Date(date);
40
- console.log('[DateTimePicker] After new Date(date):', updated.toISOString());
41
- updated.setHours(hours, minutes, 0, 0);
42
- console.log('[DateTimePicker] After setHours:', updated.toISOString());
43
- console.log('[DateTimePicker] Calling onChange with:', updated.toISOString());
36
+ const updated = new Date(
37
+ date.getFullYear(),
38
+ date.getMonth(),
39
+ date.getDate(),
40
+ hours,
41
+ minutes,
42
+ 0,
43
+ 0
44
+ );
44
45
  onChange(updated);
45
46
  };
46
47
 
47
48
  const handleTimeChange = (time: Date | null) => {
48
- console.log('[DateTimePicker] handleTimeChange received:', time?.toISOString());
49
- console.log('[DateTimePicker] Current value:', value?.toISOString());
50
49
  if (!time) {
51
50
  // Only clear time component, keep date if it exists
52
51
  if (value) {
53
- const updated = new Date(value);
54
- updated.setHours(12, 0, 0, 0);
52
+ const updated = new Date(
53
+ value.getFullYear(),
54
+ value.getMonth(),
55
+ value.getDate(),
56
+ 12,
57
+ 0,
58
+ 0,
59
+ 0
60
+ );
55
61
  onChange(updated);
56
62
  }
57
63
  return;
@@ -67,7 +73,6 @@ export const DateTimePicker: React.FC<DateTimePickerProps> = ({
67
73
  0,
68
74
  0
69
75
  );
70
- console.log('[DateTimePicker] Time change - calling onChange with:', updated.toISOString());
71
76
  onChange(updated);
72
77
  };
73
78