react-native-nepali-picker 1.0.4-alpha.2 → 1.0.4-alpha.4

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.
@@ -17,7 +17,7 @@ import {
17
17
  monthsInNepali,
18
18
  } from './calendar/config';
19
19
  import { calcFirstDay, isToday } from './calendar/settings';
20
- import { NepaliToday } from './calendar/functions';
20
+ import { NepaliToday, validateDate } from './calendar/functions';
21
21
  import { ChevronIcon } from './assets/Icons';
22
22
  import DateSyncLogo from './assets/DateSync';
23
23
  import Triangle from './assets/Triangle';
@@ -29,8 +29,8 @@ const CalendarPicker = ({
29
29
  theme = 'light',
30
30
  onDateSelect,
31
31
  language = 'np',
32
+ initialDate = NepaliToday(),
32
33
  brandColor = '#2081b9',
33
-
34
34
  titleTextStyle = {
35
35
  fontSize: 20,
36
36
  fontWeight: 'bold',
@@ -44,7 +44,9 @@ const CalendarPicker = ({
44
44
  fontWeight: '600',
45
45
  },
46
46
  }: CalendarPickerProps) => {
47
- const TodayNepaliDate = NepaliToday();
47
+ const value = validateDate(initialDate);
48
+ console.log('validate value is ', value);
49
+ const TodayNepaliDate = initialDate;
48
50
  const cYear = parseInt(TodayNepaliDate.split('-')[0], 10);
49
51
  const cMonth = parseInt(TodayNepaliDate.split('-')[1], 10);
50
52
  const cDay = parseInt(TodayNepaliDate.split('-')[2], 10);
@@ -120,8 +122,48 @@ const CalendarPicker = ({
120
122
  const dark = theme === 'dark';
121
123
  const weekDays = language === 'en' ? daysInEnglish : daysInNepali;
122
124
 
125
+ if (value !== true) {
126
+ return (
127
+ <Modal visible={visible} onRequestClose={onClose} transparent={true}>
128
+ <Pressable style={styles.outerPressable} onPress={onClose}>
129
+ <Pressable onPress={() => {}} style={styles.innerPressable}>
130
+ <View
131
+ style={{
132
+ ...styles.innerView,
133
+ minHeight: '40%',
134
+ minWidth: '90%',
135
+ justifyContent: 'center',
136
+ alignItems: 'center',
137
+ backgroundColor: dark ? '#383838' : '#ffffff',
138
+ }}
139
+ >
140
+ <Text
141
+ style={{
142
+ color: dark ? 'white' : 'black',
143
+ fontWeight: '600',
144
+ paddingHorizontal: 10,
145
+ paddingVertical: 10,
146
+ }}
147
+ >
148
+ Unsupported date range on initialDate
149
+ </Text>
150
+ <Text
151
+ style={{
152
+ color: dark ? 'white' : 'black',
153
+ paddingHorizontal: 10,
154
+ }}
155
+ >
156
+ {value}
157
+ </Text>
158
+ </View>
159
+ </Pressable>
160
+ </Pressable>
161
+ </Modal>
162
+ );
163
+ }
164
+
123
165
  return (
124
- <Modal visible={visible} onRequestClose={onClose}>
166
+ <Modal visible={visible} onRequestClose={onClose} transparent={true}>
125
167
  <Pressable style={styles.outerPressable} onPress={onClose}>
126
168
  <Pressable onPress={() => {}} style={styles.innerPressable}>
127
169
  <View
@@ -311,7 +353,11 @@ const CalendarPicker = ({
311
353
  </View>
312
354
  </Pressable>
313
355
  </Pressable>
314
- <Modal visible={yearModal} onRequestClose={closeYearView}>
356
+ <Modal
357
+ visible={yearModal}
358
+ onRequestClose={closeYearView}
359
+ transparent={true}
360
+ >
315
361
  <Pressable
316
362
  style={styles.outerPressable}
317
363
  onPress={() => closeYearView()}
@@ -8,6 +8,20 @@ const formatDate = (date: Date) => {
8
8
  return `${year}-${month}-${day}`;
9
9
  };
10
10
 
11
+ export const validateDate = (date: string): string | boolean => {
12
+ const dateArray = date.split('-');
13
+ const [userYear, userMonth, _] = dateArray.map(Number);
14
+ if (dateArray.length !== 3) {
15
+ return 'Invalid date format';
16
+ } else if (userYear < 2000 || userYear >= 2100) {
17
+ return 'Year Range is 2000 to 2099';
18
+ } else if (userMonth < 1 || userMonth > 12) {
19
+ return 'Month Range is 1 to 12';
20
+ } else {
21
+ return true;
22
+ }
23
+ };
24
+
11
25
  const FindDateDifference = (date1: number, date2: number) => {
12
26
  const diffInMs = date2 - date1;
13
27
  const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
package/src/types.ts CHANGED
@@ -12,5 +12,6 @@ export interface CalendarPickerProps {
12
12
  dayTextStyle?: TextStyle;
13
13
  weekTextStyle?: TextStyle;
14
14
  titleTextStyle?: TextStyle;
15
+ initialDate?: DateString;
15
16
  }
16
17
  export type DateString = string;