react-native-paper-dates 0.8.2 → 0.8.6
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/README.md +4 -1
- package/lib/commonjs/Date/CalendarEdit.js +4 -4
- package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
- package/lib/commonjs/Date/dateUtils.js +4 -3
- package/lib/commonjs/Date/dateUtils.js.map +1 -1
- package/lib/commonjs/Date/inputUtils.js +3 -2
- package/lib/commonjs/Date/inputUtils.js.map +1 -1
- package/lib/commonjs/index.js +10 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Date/CalendarEdit.js +4 -4
- package/lib/module/Date/CalendarEdit.js.map +1 -1
- package/lib/module/Date/dateUtils.js +4 -3
- package/lib/module/Date/dateUtils.js.map +1 -1
- package/lib/module/Date/inputUtils.js +3 -2
- package/lib/module/Date/inputUtils.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Date/dateUtils.d.ts +2 -1
- package/lib/typescript/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Date/CalendarEdit.tsx +37 -39
- package/src/Date/dateUtils.tsx +4 -2
- package/src/Date/inputUtils.ts +5 -2
- package/src/index.tsx +1 -0
package/README.md
CHANGED
|
@@ -57,14 +57,16 @@ npm install react-native-paper-dates --save
|
|
|
57
57
|
|
|
58
58
|
## Import some localized strings
|
|
59
59
|
Ideally you do this somewhere in your `index.js` before `react-native-paper-dates` is used.
|
|
60
|
-
Currently we
|
|
60
|
+
Currently we have en/nl/de/pl/pt translations but it's really easy to add one extra since it are only some labels and error messages.
|
|
61
61
|
|
|
62
62
|
```tsx
|
|
63
63
|
// e.g in your index.js
|
|
64
64
|
import {
|
|
65
65
|
// en,
|
|
66
66
|
// nl,
|
|
67
|
+
// de,
|
|
67
68
|
// pl,
|
|
69
|
+
// pt,
|
|
68
70
|
enGB,
|
|
69
71
|
registerTranslation,
|
|
70
72
|
} from 'react-native-paper-dates'
|
|
@@ -72,6 +74,7 @@ import {
|
|
|
72
74
|
// registerTranslation('nl', nl)
|
|
73
75
|
// registerTranslation('pl', pl)
|
|
74
76
|
// registerTranslation('pt', pt)
|
|
77
|
+
// registerTranslation('de', de)
|
|
75
78
|
registerTranslation('en-GB', enGB)
|
|
76
79
|
```
|
|
77
80
|
|
|
@@ -59,8 +59,6 @@ function CalendarEdit(_ref) {
|
|
|
59
59
|
}, []);
|
|
60
60
|
return /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
61
61
|
style: styles.root
|
|
62
|
-
}, /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
63
|
-
style: styles.inner
|
|
64
62
|
}, mode === 'single' ? /*#__PURE__*/React.createElement(_DatePickerInput.default, {
|
|
65
63
|
inputMode: "start",
|
|
66
64
|
ref: dateInput,
|
|
@@ -74,7 +72,9 @@ function CalendarEdit(_ref) {
|
|
|
74
72
|
locale: locale,
|
|
75
73
|
withModal: false,
|
|
76
74
|
autoComplete: 'off'
|
|
77
|
-
}) : null, mode === 'range' ? /*#__PURE__*/React.createElement(
|
|
75
|
+
}) : null, mode === 'range' ? /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
76
|
+
style: styles.inner
|
|
77
|
+
}, /*#__PURE__*/React.createElement(_DatePickerInput.default, {
|
|
78
78
|
inputMode: "start",
|
|
79
79
|
ref: startInput,
|
|
80
80
|
label: startLabel,
|
|
@@ -103,7 +103,7 @@ function CalendarEdit(_ref) {
|
|
|
103
103
|
locale: locale,
|
|
104
104
|
withModal: false,
|
|
105
105
|
autoComplete: "off"
|
|
106
|
-
})) : null)
|
|
106
|
+
})) : null);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const styles = _reactNative.StyleSheet.create({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CalendarEdit.tsx"],"names":["CalendarEdit","mode","state","label","startLabel","endLabel","collapsed","onChange","validRange","locale","dateInput","React","useRef","startInput","endInput","useEffect","Keyboard","dismiss","inputsToFocus","current","filter","n","inputsToBlur","forEach","ip","blur","focus","onSubmitStartInput","useCallback","onSubmitEndInput","onSubmitInput","styles","root","
|
|
1
|
+
{"version":3,"sources":["CalendarEdit.tsx"],"names":["CalendarEdit","mode","state","label","startLabel","endLabel","collapsed","onChange","validRange","locale","dateInput","React","useRef","startInput","endInput","useEffect","Keyboard","dismiss","inputsToFocus","current","filter","n","inputsToBlur","forEach","ip","blur","focus","onSubmitStartInput","useCallback","onSubmitEndInput","onSubmitInput","styles","root","date","inner","startDate","separator","endDate","StyleSheet","create","padding","flexDirection","inputContainer","flex","input","width","memo"],"mappings":";;;;;;;AAAA;;AACA;;AAUA;;;;;;;;AAEA,SAASA,YAAT,OAoBG;AAAA,MApBmB;AACpBC,IAAAA,IADoB;AAEpBC,IAAAA,KAFoB;AAGpBC,IAAAA,KAAK,GAAG,EAHY;AAIpBC,IAAAA,UAAU,GAAG,OAJO;AAKpBC,IAAAA,QAAQ,GAAG,KALS;AAMpBC,IAAAA,SANoB;AAOpBC,IAAAA,QAPoB;AAQpBC,IAAAA,UARoB;AASpBC,IAAAA;AAToB,GAoBnB;AACD,QAAMC,SAAS,GAAGC,KAAK,CAACC,MAAN,CAAqC,IAArC,CAAlB;AACA,QAAMC,UAAU,GAAGF,KAAK,CAACC,MAAN,CAAqC,IAArC,CAAnB;AACA,QAAME,QAAQ,GAAGH,KAAK,CAACC,MAAN,CAAqC,IAArC,CAAjB,CAHC,CAKD;;AACAD,EAAAA,KAAK,CAACI,SAAN,CAAgB,MAAM;AACpB;AACA,QAAIT,SAAJ,EAAe;AACbU,4BAASC,OAAT;AACD;;AAED,UAAMC,aAAa,GAAG,CAACR,SAAS,CAACS,OAAX,EAAoBN,UAAU,CAACM,OAA/B,EAAwCC,MAAxC,CACnBC,CAAD,IAAOA,CADa,CAAtB;AAIA,UAAMC,YAAY,GAAG,CACnBZ,SAAS,CAACS,OADS,EAEnBN,UAAU,CAACM,OAFQ,EAGnBL,QA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OAAO,EAAE;AAAX,GADyB;AAE/BN,EAAAA,KAAK,EAAE;AAAEO,IAAAA,aAAa,EAAE;AAAjB,GAFwB;AAG/BC,EAAAA,cAAc,EAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAHe;AAI/BC,EAAAA,KAAK,EAAE;AAAED,IAAAA,IAAI,EAAE;AAAR,GAJwB;AAK/BP,EAAAA,SAAS,EAAE;AAAES,IAAAA,KAAK,EAAE;AAAT;AALoB,CAAlB,CAAf;;4BAQelC,KAAK,CAACmC,IAAN,CAAW9C,YAAX,C","sourcesContent":["import * as React from 'react'\nimport {\n View,\n StyleSheet,\n TextInput as TextInputNative,\n Keyboard,\n} from 'react-native'\n\nimport type { ModeType, ValidRangeType } from './Calendar'\nimport type { LocalState } from './DatePickerModalContent'\n\nimport DatePickerInput from './DatePickerInput'\n\nfunction CalendarEdit({\n mode,\n state,\n label = '',\n startLabel = 'Start',\n endLabel = 'End',\n collapsed,\n onChange,\n validRange,\n locale,\n}: {\n mode: ModeType\n label?: string\n startLabel?: string\n endLabel?: string\n state: LocalState\n collapsed: boolean\n onChange: (s: LocalState) => any\n validRange: ValidRangeType | undefined\n locale: string\n}) {\n const dateInput = React.useRef<TextInputNative | null>(null)\n const startInput = React.useRef<TextInputNative | null>(null)\n const endInput = React.useRef<TextInputNative | null>(null)\n\n // when switching views focus, or un-focus text input\n React.useEffect(() => {\n // hide open keyboard\n if (collapsed) {\n Keyboard.dismiss()\n }\n\n const inputsToFocus = [dateInput.current, startInput.current].filter(\n (n) => n\n ) as TextInputNative[]\n\n const inputsToBlur = [\n dateInput.current,\n startInput.current,\n endInput.current,\n ].filter((n) => n) as TextInputNative[]\n\n if (collapsed) {\n inputsToBlur.forEach((ip) => ip.blur())\n } else {\n inputsToFocus.forEach((ip) => ip.focus())\n }\n }, [mode, startInput, endInput, dateInput, collapsed])\n\n const onSubmitStartInput = React.useCallback(() => {\n if (endInput.current) {\n endInput.current.focus()\n }\n }, [endInput])\n\n const onSubmitEndInput = React.useCallback(() => {\n // TODO: close modal and persist range\n }, [])\n\n const onSubmitInput = React.useCallback(() => {\n // TODO: close modal and persist range\n }, [])\n\n return (\n <View style={styles.root}>\n {mode === 'single' ? (\n <DatePickerInput\n inputMode=\"start\"\n ref={dateInput}\n label={label}\n value={state.date}\n onChange={(date) => onChange({ ...state, date })}\n onSubmitEditing={onSubmitInput}\n validRange={validRange}\n locale={locale}\n withModal={false}\n autoComplete={'off'}\n />\n ) : null}\n {mode === 'range' ? (\n <View style={styles.inner}>\n <DatePickerInput\n inputMode=\"start\"\n ref={startInput}\n label={startLabel}\n value={state.startDate}\n onChange={(startDate) => onChange({ ...state, startDate })}\n returnKeyType={'next'}\n onSubmitEditing={onSubmitStartInput}\n validRange={validRange}\n locale={locale}\n withModal={false}\n autoComplete={'off'}\n />\n <View style={styles.separator} />\n <DatePickerInput\n inputMode=\"end\"\n ref={endInput}\n label={endLabel}\n value={state.endDate}\n onChange={(endDate) => onChange({ ...state, endDate })}\n onSubmitEditing={onSubmitEndInput}\n validRange={validRange}\n locale={locale}\n withModal={false}\n autoComplete=\"off\"\n />\n </View>\n ) : null}\n </View>\n )\n}\n\nconst styles = StyleSheet.create({\n root: { padding: 12 },\n inner: { flexDirection: 'row' },\n inputContainer: { flex: 1 },\n input: { flex: 1 },\n separator: { width: 12 },\n})\n\nexport default React.memo(CalendarEdit)\n"]}
|
|
@@ -229,13 +229,14 @@ function getEndOfDay(d) {
|
|
|
229
229
|
|
|
230
230
|
function useInputFormat(_ref7) {
|
|
231
231
|
let {
|
|
232
|
-
formatter
|
|
232
|
+
formatter,
|
|
233
|
+
locale
|
|
233
234
|
} = _ref7;
|
|
234
235
|
return React.useMemo(() => {
|
|
235
236
|
// TODO: something cleaner and more universal?
|
|
236
237
|
const inputDate = formatter.format(new Date(2020, 10 - 1, 1));
|
|
237
|
-
return inputDate.replace('2020', 'YYYY').replace('10', 'MM').replace('01', 'DD');
|
|
238
|
-
}, [formatter]);
|
|
238
|
+
return inputDate.replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY').replace('10', 'MM').replace('01', 'DD');
|
|
239
|
+
}, [formatter, locale]);
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
function differenceInMonths(firstDate, secondDate) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["dateUtils.tsx"],"names":["showWeekDay","dayIndex","disableWeekDays","some","di","dateToUnix","d","Math","round","getTime","addMonths","date","count","n","getDate","n2","Date","setDate","setMonth","getMonth","min","getDaysInMonth","year","getFullYear","month","isLeapYear","getFirstDayOfMonth","getDay","useRangeChecker","validRange","validStart","startDate","validEnd","endDate","startUnix","getStartOfDay","undefined","endUnix","getEndOfDay","validDisabledDatesRef","disabledDates","isWithinValidRange","React","useCallback","day","isDateWithinOptionalRange","isDisabled","current","disabledDate","areDatesOnSameDay","a","b","isDateBetween","dateUnix","daySize","estimatedMonthHeight","startAtIndex","totalMonths","beginOffset","gridCounts","Array","getGridCount","index","cHeight","monthDate","getRealIndex","h","getGridCountForDate","daysInMonth","dayOfWeek","ceil","getInitialIndex","today","months","differenceInMonths","useInputFormatter","locale","useMemo","Intl","DateTimeFormat","useInputFormat","formatter","inputDate","format","replace","firstDate","secondDate","diffMonths"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;;;;;AAKO,SAASA,WAAT,CACLC,QADK,EAELC,eAFK,EAGI;AACT,SAAO,EAAEA,eAAe,IAAIA,eAAe,CAACC,IAAhB,CAAsBC,EAAD,IAAQA,EAAE,KAAKH,QAApC,CAArB,CAAP;AACD;;AAEM,SAASI,UAAT,CAAoBC,CAApB,EAAqC;AAC1C,SAAOC,IAAI,CAACC,KAAL,CAAWF,CAAC,CAACG,OAAF,KAAc,IAAzB,CAAP;AACD;;AAEM,SAASC,SAAT,CAAmBC,IAAnB,EAA+BC,KAA/B,EAA8C;AACnD,MAAIC,CAAC,GAAGF,IAAI,CAACG,OAAL,EAAR;AACA,MAAIC,EA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CAAP;AAOD;;AACM,SAASzC,aAAT,CAAuB7B,CAAvB,EAAsC;AAC3C,SAAO,IAAIU,IAAJ,CAASV,CAAC,CAACiB,WAAF,EAAT,EAA0BjB,CAAC,CAACa,QAAF,EAA1B,EAAwCb,CAAC,CAACQ,OAAF,EAAxC,EAAqD,CAArD,EAAwD,CAAxD,EAA2D,CAA3D,CAAP;AACD;;AACM,SAASwB,WAAT,CAAqBhC,CAArB,EAAoC;AACzC,SAAO,IAAIU,IAAJ,CAASV,CAAC,CAACiB,WAAF,EAAT,EAA0BjB,CAAC,CAACa,QAAF,EAA1B,EAAwCb,CAAC,CAACQ,OAAF,EAAxC,EAAqD,EAArD,EAAyD,EAAzD,EAA6D,EAA7D,CAAP;AACD;;AACM,SAASkE,cAAT,QAIJ;AAAA,MAJ4B;AAC7BC,IAAAA;AAD6B,GAI5B;AACD,SAAOvC,KAAK,CAACmC,OAAN,CAAc,MAAM;AACzB;AACA,UAAMK,SAAS,GAAGD,SAAS,CAACE,MAAV,CAAiB,IAAInE,IAAJ,CAAS,IAAT,EAAe,KAAK,CAApB,EAAuB,CAAvB,CAAjB,CAAlB;AACA,WAAOkE,SAAS,CACbE,OADI,CACI,MADJ,EACY,MADZ,EAEJA,OAFI,CAEI,IAFJ,EAEU,IAFV,EAGJA,OAHI,CAGI,IAHJ,EAGU,IAHV,CAAP;AAID,GAPM,EAOJ,CAACH,SAAD,CAPI,CAAP;AAQD;;AAEM,SAASP,kBAAT,CAA4BW,SAA5B,EAA6CC,UAA7C,EAA+D;AACpE,MAAIC,UAAU,GAAG,CAACD,UAAU,CAAC/D,WAAX,KAA2B8D,SAAS,CAAC9D,WAAV,EAA5B,IAAuD,EAAxE;AACAgE,EAAAA,UAAU,IAAIF,SAAS,CAAClE,QAAV,EAAd;AACAoE,EAAAA,UAAU,IAAID,UAAU,CAACnE,QAAX,EAAd;AACA,SAAOoE,UAAP;AACD","sourcesContent":["import * as React from 'react'\nimport { useLatest } from '../utils'\nimport type { ValidRangeType } from './Calendar'\n\nexport type DisableWeekDaysType = number[]\n\nexport function showWeekDay(\n dayIndex: number,\n disableWeekDays?: DisableWeekDaysType\n): boolean {\n return !(disableWeekDays && disableWeekDays.some((di) => di === dayIndex))\n}\n\nexport function dateToUnix(d: Date): number {\n return Math.round(d.getTime() / 1000)\n}\n\nexport function addMonths(date: Date, count: number) {\n let n = date.getDate()\n let n2 = new Date(date.getTime())\n n2.setDate(1)\n n2.setMonth(n2.getMonth() + count)\n n2.setDate(\n Math.min(\n n,\n getDaysInMonth({ year: n2.getFullYear(), month: n2.getMonth() })\n )\n )\n\n return n2\n}\n\n// https://stackoverflow.com/a/1185068/2508481\n// pass in any date as parameter anyDateInMonth based on dayjs\nexport function getDaysInMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return [\n 31,\n isLeapYear({ year }) ? 29 : 28,\n 31,\n 30,\n 31,\n 30,\n 31,\n 31,\n 30,\n 31,\n 30,\n 31,\n ][month]\n}\n\nexport function getFirstDayOfMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return new Date(year, month, 1).getDay()\n}\n\nexport function useRangeChecker(validRange: ValidRangeType | undefined) {\n const validStart = validRange?.startDate\n const validEnd = validRange?.endDate\n const startUnix =\n validStart instanceof Date\n ? dateToUnix(getStartOfDay(validStart))\n : undefined\n\n const endUnix =\n validEnd instanceof Date ? dateToUnix(getEndOfDay(validEnd)) : undefined\n\n const validDisabledDatesRef = useLatest(validRange?.disabledDates)\n\n const isWithinValidRange = React.useCallback(\n (day: Date) => {\n return isDateWithinOptionalRange(day, {\n startUnix: startUnix,\n endUnix: endUnix,\n })\n },\n [startUnix, endUnix]\n )\n\n const isDisabled = React.useCallback(\n (day: Date) => {\n return validDisabledDatesRef.current\n ? validDisabledDatesRef.current.some((disabledDate) =>\n areDatesOnSameDay(disabledDate, day)\n )\n : false\n },\n [validDisabledDatesRef]\n )\n\n return { isDisabled, isWithinValidRange, validStart, validEnd }\n}\n\nexport function areDatesOnSameDay(a: Date, b?: Date | null | undefined) {\n if (!b) {\n return false\n }\n\n return (\n a.getFullYear() === b.getFullYear() &&\n a.getMonth() === b.getMonth() &&\n a.getDate() === b.getDate()\n )\n}\n\nexport function isDateBetween(\n date: Date,\n {\n startDate,\n endDate,\n }: {\n startDate?: Date | null | undefined\n endDate?: Date | null | undefined\n }\n): boolean {\n if (!startDate || !endDate) {\n return false\n }\n return date <= endDate && date >= startDate\n}\n\n/**\n * Check if a date is within an optional range.\n *\n * If the range doesn't exist, it defaults to `true`.\n */\nexport function isDateWithinOptionalRange(\n date: Date,\n {\n startUnix,\n endUnix,\n }: { startUnix: number | undefined; endUnix: number | undefined }\n) {\n const dateUnix = dateToUnix(date)\n // if startUnix is provided and date is before start\n if (startUnix && dateUnix < startUnix) {\n return false\n }\n\n // if endUnix is provided and date is after end\n if (endUnix && dateUnix > endUnix) {\n return false\n }\n\n return true\n}\n\nexport function isLeapYear({ year }: { year: number }) {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n}\n\nexport const daySize = 46\nexport const estimatedMonthHeight = 360\nexport const startAtIndex = 1200\nexport const totalMonths = startAtIndex * 2\nexport const beginOffset = estimatedMonthHeight * startAtIndex\nexport const gridCounts = new Array<number | undefined>(totalMonths)\n\nexport function getGridCount(index: number) {\n const cHeight = gridCounts[index]\n if (cHeight) {\n return cHeight\n }\n const monthDate = addMonths(new Date(), getRealIndex(index))\n const h = getGridCountForDate(monthDate)\n gridCounts[index] = h\n return h\n}\n\nexport function getGridCountForDate(date: Date) {\n const year = date.getFullYear()\n const month = date.getMonth()\n const daysInMonth = getDaysInMonth({ year, month })\n const dayOfWeek = getFirstDayOfMonth({ year, month })\n return Math.ceil((daysInMonth + dayOfWeek) / 7)\n}\n\nexport function getRealIndex(index: number) {\n return index - startAtIndex\n}\n\nexport function getInitialIndex(date: Date | undefined) {\n if (!date) {\n return startAtIndex\n }\n\n const today = new Date()\n const months = differenceInMonths(today, date)\n\n return startAtIndex + months\n}\n\nexport function useInputFormatter({ locale }: { locale: string | undefined }) {\n return React.useMemo(() => {\n return new Intl.DateTimeFormat(locale, {\n month: '2-digit',\n day: '2-digit',\n year: 'numeric',\n })\n }, [locale])\n}\nexport function getStartOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0)\n}\nexport function getEndOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59)\n}\nexport function useInputFormat({\n formatter,\n}: {\n formatter: Intl.DateTimeFormat\n}) {\n return React.useMemo(() => {\n // TODO: something cleaner and more universal?\n const inputDate = formatter.format(new Date(2020, 10 - 1, 1))\n return inputDate\n .replace('2020', 'YYYY')\n .replace('10', 'MM')\n .replace('01', 'DD')\n }, [formatter])\n}\n\nexport function differenceInMonths(firstDate: Date, secondDate: Date) {\n let diffMonths = (secondDate.getFullYear() - firstDate.getFullYear()) * 12\n diffMonths -= firstDate.getMonth()\n diffMonths += secondDate.getMonth()\n return diffMonths\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["dateUtils.tsx"],"names":["showWeekDay","dayIndex","disableWeekDays","some","di","dateToUnix","d","Math","round","getTime","addMonths","date","count","n","getDate","n2","Date","setDate","setMonth","getMonth","min","getDaysInMonth","year","getFullYear","month","isLeapYear","getFirstDayOfMonth","getDay","useRangeChecker","validRange","validStart","startDate","validEnd","endDate","startUnix","getStartOfDay","undefined","endUnix","getEndOfDay","validDisabledDatesRef","disabledDates","isWithinValidRange","React","useCallback","day","isDateWithinOptionalRange","isDisabled","current","disabledDate","areDatesOnSameDay","a","b","isDateBetween","dateUnix","daySize","estimatedMonthHeight","startAtIndex","totalMonths","beginOffset","gridCounts","Array","getGridCount","index","cHeight","monthDate","getRealIndex","h","getGridCountForDate","daysInMonth","dayOfWeek","ceil","getInitialIndex","today","months","differenceInMonths","useInputFormatter","locale","useMemo","Intl","DateTimeFormat","useInputFormat","formatter","inputDate","format","replace","firstDate","secondDate","diffMonths"],"mappings":";;;;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AK,IAAX,GAAkB,MAAlB,GAA2B,MADvC,EAEJQ,OAFI,CAEI,IAFJ,EAEU,IAFV,EAGJA,OAHI,CAGI,IAHJ,EAGU,IAHV,CAAP;AAID,GAPM,EAOJ,CAACH,SAAD,EAAYL,MAAZ,CAPI,CAAP;AAQD;;AAEM,SAASF,kBAAT,CAA4BW,SAA5B,EAA6CC,UAA7C,EAA+D;AACpE,MAAIC,UAAU,GAAG,CAACD,UAAU,CAAC/D,WAAX,KAA2B8D,SAAS,CAAC9D,WAAV,EAA5B,IAAuD,EAAxE;AACAgE,EAAAA,UAAU,IAAIF,SAAS,CAAClE,QAAV,EAAd;AACAoE,EAAAA,UAAU,IAAID,UAAU,CAACnE,QAAX,EAAd;AACA,SAAOoE,UAAP;AACD","sourcesContent":["import * as React from 'react'\nimport { useLatest } from '../utils'\nimport type { ValidRangeType } from './Calendar'\n\nexport type DisableWeekDaysType = number[]\n\nexport function showWeekDay(\n dayIndex: number,\n disableWeekDays?: DisableWeekDaysType\n): boolean {\n return !(disableWeekDays && disableWeekDays.some((di) => di === dayIndex))\n}\n\nexport function dateToUnix(d: Date): number {\n return Math.round(d.getTime() / 1000)\n}\n\nexport function addMonths(date: Date, count: number) {\n let n = date.getDate()\n let n2 = new Date(date.getTime())\n n2.setDate(1)\n n2.setMonth(n2.getMonth() + count)\n n2.setDate(\n Math.min(\n n,\n getDaysInMonth({ year: n2.getFullYear(), month: n2.getMonth() })\n )\n )\n\n return n2\n}\n\n// https://stackoverflow.com/a/1185068/2508481\n// pass in any date as parameter anyDateInMonth based on dayjs\nexport function getDaysInMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return [\n 31,\n isLeapYear({ year }) ? 29 : 28,\n 31,\n 30,\n 31,\n 30,\n 31,\n 31,\n 30,\n 31,\n 30,\n 31,\n ][month]\n}\n\nexport function getFirstDayOfMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return new Date(year, month, 1).getDay()\n}\n\nexport function useRangeChecker(validRange: ValidRangeType | undefined) {\n const validStart = validRange?.startDate\n const validEnd = validRange?.endDate\n const startUnix =\n validStart instanceof Date\n ? dateToUnix(getStartOfDay(validStart))\n : undefined\n\n const endUnix =\n validEnd instanceof Date ? dateToUnix(getEndOfDay(validEnd)) : undefined\n\n const validDisabledDatesRef = useLatest(validRange?.disabledDates)\n\n const isWithinValidRange = React.useCallback(\n (day: Date) => {\n return isDateWithinOptionalRange(day, {\n startUnix: startUnix,\n endUnix: endUnix,\n })\n },\n [startUnix, endUnix]\n )\n\n const isDisabled = React.useCallback(\n (day: Date) => {\n return validDisabledDatesRef.current\n ? validDisabledDatesRef.current.some((disabledDate) =>\n areDatesOnSameDay(disabledDate, day)\n )\n : false\n },\n [validDisabledDatesRef]\n )\n\n return { isDisabled, isWithinValidRange, validStart, validEnd }\n}\n\nexport function areDatesOnSameDay(a: Date, b?: Date | null | undefined) {\n if (!b) {\n return false\n }\n\n return (\n a.getFullYear() === b.getFullYear() &&\n a.getMonth() === b.getMonth() &&\n a.getDate() === b.getDate()\n )\n}\n\nexport function isDateBetween(\n date: Date,\n {\n startDate,\n endDate,\n }: {\n startDate?: Date | null | undefined\n endDate?: Date | null | undefined\n }\n): boolean {\n if (!startDate || !endDate) {\n return false\n }\n return date <= endDate && date >= startDate\n}\n\n/**\n * Check if a date is within an optional range.\n *\n * If the range doesn't exist, it defaults to `true`.\n */\nexport function isDateWithinOptionalRange(\n date: Date,\n {\n startUnix,\n endUnix,\n }: { startUnix: number | undefined; endUnix: number | undefined }\n) {\n const dateUnix = dateToUnix(date)\n // if startUnix is provided and date is before start\n if (startUnix && dateUnix < startUnix) {\n return false\n }\n\n // if endUnix is provided and date is after end\n if (endUnix && dateUnix > endUnix) {\n return false\n }\n\n return true\n}\n\nexport function isLeapYear({ year }: { year: number }) {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n}\n\nexport const daySize = 46\nexport const estimatedMonthHeight = 360\nexport const startAtIndex = 1200\nexport const totalMonths = startAtIndex * 2\nexport const beginOffset = estimatedMonthHeight * startAtIndex\nexport const gridCounts = new Array<number | undefined>(totalMonths)\n\nexport function getGridCount(index: number) {\n const cHeight = gridCounts[index]\n if (cHeight) {\n return cHeight\n }\n const monthDate = addMonths(new Date(), getRealIndex(index))\n const h = getGridCountForDate(monthDate)\n gridCounts[index] = h\n return h\n}\n\nexport function getGridCountForDate(date: Date) {\n const year = date.getFullYear()\n const month = date.getMonth()\n const daysInMonth = getDaysInMonth({ year, month })\n const dayOfWeek = getFirstDayOfMonth({ year, month })\n return Math.ceil((daysInMonth + dayOfWeek) / 7)\n}\n\nexport function getRealIndex(index: number) {\n return index - startAtIndex\n}\n\nexport function getInitialIndex(date: Date | undefined) {\n if (!date) {\n return startAtIndex\n }\n\n const today = new Date()\n const months = differenceInMonths(today, date)\n\n return startAtIndex + months\n}\n\nexport function useInputFormatter({ locale }: { locale: string | undefined }) {\n return React.useMemo(() => {\n return new Intl.DateTimeFormat(locale, {\n month: '2-digit',\n day: '2-digit',\n year: 'numeric',\n })\n }, [locale])\n}\nexport function getStartOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0)\n}\nexport function getEndOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59)\n}\nexport function useInputFormat({\n formatter,\n locale,\n}: {\n formatter: Intl.DateTimeFormat\n locale: string | undefined\n}) {\n return React.useMemo(() => {\n // TODO: something cleaner and more universal?\n const inputDate = formatter.format(new Date(2020, 10 - 1, 1))\n return inputDate\n .replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY')\n .replace('10', 'MM')\n .replace('01', 'DD')\n }, [formatter, locale])\n}\n\nexport function differenceInMonths(firstDate: Date, secondDate: Date) {\n let diffMonths = (secondDate.getFullYear() - firstDate.getFullYear()) * 12\n diffMonths -= firstDate.getMonth()\n diffMonths += secondDate.getMonth()\n return diffMonths\n}\n"]}
|
|
@@ -34,14 +34,15 @@ function useDateInput(_ref) {
|
|
|
34
34
|
locale
|
|
35
35
|
});
|
|
36
36
|
const inputFormat = (0, _dateUtils.useInputFormat)({
|
|
37
|
-
formatter
|
|
37
|
+
formatter,
|
|
38
|
+
locale
|
|
38
39
|
});
|
|
39
40
|
const formattedValue = formatter.format(value);
|
|
40
41
|
|
|
41
42
|
const onChangeText = date => {
|
|
42
43
|
const dayIndex = inputFormat.indexOf('DD');
|
|
43
44
|
const monthIndex = inputFormat.indexOf('MM');
|
|
44
|
-
const yearIndex = inputFormat.indexOf('YYYY');
|
|
45
|
+
const yearIndex = locale === 'pt' ? inputFormat.indexOf('AAAA') : inputFormat.indexOf('YYYY');
|
|
45
46
|
const day = Number(date.slice(dayIndex, dayIndex + 2));
|
|
46
47
|
const year = Number(date.slice(yearIndex, yearIndex + 4));
|
|
47
48
|
const month = Number(date.slice(monthIndex, monthIndex + 2));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["inputUtils.ts"],"names":["useDateInput","locale","value","validRange","inputMode","onChange","isDisabled","isWithinValidRange","validStart","validEnd","error","setError","React","useState","formatter","inputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","finalDate","Date","errors","filter","n","join"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;;;AAEe,SAASA,YAAT,OAYZ;AAAA,MAZkC;AACnCC,IAAAA,MADmC;AAEnCC,IAAAA,KAFmC;AAGnCC,IAAAA,UAHmC;AAInCC,IAAAA,SAJmC;AAKnCC,IAAAA;AALmC,GAYlC;AACD,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,kBAAd;AAAkCC,IAAAA,UAAlC;AAA8CC,IAAAA;AAA9C,MACJ,gCAAgBN,UAAhB,CADF;AAEA,QAAM,CAACO,KAAD,EAAQC,QAAR,IAAoBC,KAAK,CAACC,QAAN,CAA8B,IAA9B,CAA1B;AACA,QAAMC,SAAS,GAAG,kCAAkB;AAAEb,IAAAA;AAAF,GAAlB,CAAlB;AACA,QAAMc,WAAW,GAAG,+BAAe;AAAED,IAAAA;
|
|
1
|
+
{"version":3,"sources":["inputUtils.ts"],"names":["useDateInput","locale","value","validRange","inputMode","onChange","isDisabled","isWithinValidRange","validStart","validEnd","error","setError","React","useState","formatter","inputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","finalDate","Date","errors","filter","n","join"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;;;AAEe,SAASA,YAAT,OAYZ;AAAA,MAZkC;AACnCC,IAAAA,MADmC;AAEnCC,IAAAA,KAFmC;AAGnCC,IAAAA,UAHmC;AAInCC,IAAAA,SAJmC;AAKnCC,IAAAA;AALmC,GAYlC;AACD,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,kBAAd;AAAkCC,IAAAA,UAAlC;AAA8CC,IAAAA;AAA9C,MACJ,gCAAgBN,UAAhB,CADF;AAEA,QAAM,CAACO,KAAD,EAAQC,QAAR,IAAoBC,KAAK,CAACC,QAAN,CAA8B,IAA9B,CAA1B;AACA,QAAMC,SAAS,GAAG,kCAAkB;AAAEb,IAAAA;AAAF,GAAlB,CAAlB;AACA,QAAMc,WAAW,GAAG,+BAAe;AAAED,IAAAA,SAAF;AAAab,IAAAA;AAAb,GAAf,CAApB;AACA,QAAMe,cAAc,GAAGF,SAAS,CAACG,MAAV,CAAiBf,KAAjB,CAAvB;;AACA,QAAMgB,YAAY,GAAIC,IAAD,IAAkB;AACrC,UAAMC,QAAQ,GAAGL,WAAW,CAACM,OAAZ,CAAoB,IAApB,CAAjB;AACA,UAAMC,UAAU,GAAGP,WAAW,CAACM,OAAZ,CAAoB,IAApB,CAAnB;AACA,UAAME,SAAS,GACbtB,MAAM,KAAK,IAAX,GACIc,WAAW,CAACM,OAAZ,CAAoB,MAApB,CADJ,GAEIN,WAAW,CAACM,OAAZ,CAAoB,MAApB,CAHN;AAKA,UAAMG,GAAG,GAAG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GACN,2CACEP,MADF,EAEE,kBAFF,EAGE,MAAM,kBAHR,EAIEa,SAAS,CAACG,MAAV,CAAiBT,UAAjB,CAJF,CADM,GAMN,EAPN,EAQEC,QAAQ,GACJ,2CACER,MADF,EAEE,iBAFF,EAGE,MAAM,iBAHR,EAIEa,SAAS,CAACG,MAAV,CAAiBR,QAAjB,CAJF,CADI,GAMJ,EAdN,CATN;AAyBAE,MAAAA,QAAQ,CAACqB,MAAM,CAACC,MAAP,CAAeC,CAAD,IAAOA,CAArB,EAAwBC,IAAxB,CAA6B,GAA7B,CAAD,CAAR;AACA;AACD;;AAEDxB,IAAAA,QAAQ,CAAC,IAAD,CAAR;;AACA,QAAIP,SAAS,KAAK,KAAlB,EAAyB;AACvBC,MAAAA,QAAQ,CAACyB,SAAD,CAAR;AACD,KAFD,MAEO;AACLzB,MAAAA,QAAQ,CAACyB,SAAD,CAAR;AACD;AACF,GApED;;AAqEA,SAAO;AACLzB,IAAAA,QADK;AAELK,IAAAA,KAFK;AAGLM,IAAAA,cAHK;AAILE,IAAAA,YAJK;AAKLH,IAAAA;AALK,GAAP;AAOD","sourcesContent":["import { useInputFormat, useInputFormatter, useRangeChecker } from './dateUtils'\nimport * as React from 'react'\nimport type { ValidRangeType } from './Calendar'\nimport { getTranslation } from 'react-native-paper-dates'\n\nexport default function useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n}: {\n onChange: (d: Date) => void\n locale: undefined | string\n value: Date | undefined\n validRange: ValidRangeType | undefined\n inputMode: 'start' | 'end'\n}) {\n const { isDisabled, isWithinValidRange, validStart, validEnd } =\n useRangeChecker(validRange)\n const [error, setError] = React.useState<null | string>(null)\n const formatter = useInputFormatter({ locale })\n const inputFormat = useInputFormat({ formatter, locale })\n const formattedValue = formatter.format(value)\n const onChangeText = (date: string) => {\n const dayIndex = inputFormat.indexOf('DD')\n const monthIndex = inputFormat.indexOf('MM')\n const yearIndex =\n locale === 'pt'\n ? inputFormat.indexOf('AAAA')\n : inputFormat.indexOf('YYYY')\n\n const day = Number(date.slice(dayIndex, dayIndex + 2))\n const year = Number(date.slice(yearIndex, yearIndex + 4))\n const month = Number(date.slice(monthIndex, monthIndex + 2))\n\n if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {\n setError(\n getTranslation(\n locale,\n 'notAccordingToDateFormat',\n () => 'notAccordingToDateFormat'\n )(inputFormat)\n )\n return\n }\n\n const finalDate =\n inputMode === 'end'\n ? new Date(year, month - 1, day, 23, 59, 59)\n : new Date(year, month - 1, day)\n\n if (isDisabled(finalDate)) {\n setError(getTranslation(locale, 'dateIsDisabled'))\n return\n }\n if (!isWithinValidRange(finalDate)) {\n let errors =\n validStart && validEnd\n ? [\n `${getTranslation(\n locale,\n 'mustBeBetween',\n () => 'mustBeBetween'\n )(formatter.format(validStart), formatter.format(validEnd))}`,\n ]\n : [\n validStart\n ? getTranslation(\n locale,\n 'mustBeHigherThan',\n () => 'mustBeHigherThan'\n )(formatter.format(validStart))\n : '',\n validEnd\n ? getTranslation(\n locale,\n 'mustBeLowerThan',\n () => 'mustBeLowerThan'\n )(formatter.format(validEnd))\n : '',\n ]\n setError(errors.filter((n) => n).join(' '))\n return\n }\n\n setError(null)\n if (inputMode === 'end') {\n onChange(finalDate)\n } else {\n onChange(finalDate)\n }\n }\n return {\n onChange,\n error,\n formattedValue,\n onChangeText,\n inputFormat,\n }\n}\n"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -16,7 +16,8 @@ var _exportNames = {
|
|
|
16
16
|
en: true,
|
|
17
17
|
pl: true,
|
|
18
18
|
pt: true,
|
|
19
|
-
enGB: true
|
|
19
|
+
enGB: true,
|
|
20
|
+
de: true
|
|
20
21
|
};
|
|
21
22
|
Object.defineProperty(exports, "Calendar", {
|
|
22
23
|
enumerable: true,
|
|
@@ -54,6 +55,12 @@ Object.defineProperty(exports, "TimePickerModal", {
|
|
|
54
55
|
return _TimePickerModal.default;
|
|
55
56
|
}
|
|
56
57
|
});
|
|
58
|
+
Object.defineProperty(exports, "de", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _de.default;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
57
64
|
Object.defineProperty(exports, "en", {
|
|
58
65
|
enumerable: true,
|
|
59
66
|
get: function () {
|
|
@@ -133,6 +140,8 @@ var _pt = _interopRequireDefault(require("./translations/pt"));
|
|
|
133
140
|
|
|
134
141
|
var _enGB = _interopRequireDefault(require("./translations/enGB"));
|
|
135
142
|
|
|
143
|
+
var _de = _interopRequireDefault(require("./translations/de"));
|
|
144
|
+
|
|
136
145
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
137
146
|
|
|
138
147
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["export { default as Calendar } from './Date/Calendar'\nexport { default as DatePickerModal } from './Date/DatePickerModal'\nexport * from './Date/DatePickerModal'\nexport { default as DatePickerModalContent } from './Date/DatePickerModalContent'\nexport { default as TimePickerModal } from './Time/TimePickerModal'\nexport { default as TimePicker } from './Time/TimePicker'\nexport { default as DatePickerInput } from './Date/DatePickerInput'\nexport type { TranslationsType } from './translations/utils'\nexport { registerTranslation, getTranslation } from './translations/utils'\nexport { default as nl } from './translations/nl'\nexport { default as en } from './translations/en'\nexport { default as pl } from './translations/pl'\nexport { default as pt } from './translations/pt'\nexport { default as enGB } from './translations/enGB'\nexport { default as de } from './translations/de'\n"]}
|
|
@@ -44,8 +44,6 @@ function CalendarEdit(_ref) {
|
|
|
44
44
|
}, []);
|
|
45
45
|
return /*#__PURE__*/React.createElement(View, {
|
|
46
46
|
style: styles.root
|
|
47
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
48
|
-
style: styles.inner
|
|
49
47
|
}, mode === 'single' ? /*#__PURE__*/React.createElement(DatePickerInput, {
|
|
50
48
|
inputMode: "start",
|
|
51
49
|
ref: dateInput,
|
|
@@ -59,7 +57,9 @@ function CalendarEdit(_ref) {
|
|
|
59
57
|
locale: locale,
|
|
60
58
|
withModal: false,
|
|
61
59
|
autoComplete: 'off'
|
|
62
|
-
}) : null, mode === 'range' ? /*#__PURE__*/React.createElement(
|
|
60
|
+
}) : null, mode === 'range' ? /*#__PURE__*/React.createElement(View, {
|
|
61
|
+
style: styles.inner
|
|
62
|
+
}, /*#__PURE__*/React.createElement(DatePickerInput, {
|
|
63
63
|
inputMode: "start",
|
|
64
64
|
ref: startInput,
|
|
65
65
|
label: startLabel,
|
|
@@ -88,7 +88,7 @@ function CalendarEdit(_ref) {
|
|
|
88
88
|
locale: locale,
|
|
89
89
|
withModal: false,
|
|
90
90
|
autoComplete: "off"
|
|
91
|
-
})) : null)
|
|
91
|
+
})) : null);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
const styles = StyleSheet.create({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CalendarEdit.tsx"],"names":["React","View","StyleSheet","Keyboard","DatePickerInput","CalendarEdit","mode","state","label","startLabel","endLabel","collapsed","onChange","validRange","locale","dateInput","useRef","startInput","endInput","useEffect","dismiss","inputsToFocus","current","filter","n","inputsToBlur","forEach","ip","blur","focus","onSubmitStartInput","useCallback","onSubmitEndInput","onSubmitInput","styles","root","
|
|
1
|
+
{"version":3,"sources":["CalendarEdit.tsx"],"names":["React","View","StyleSheet","Keyboard","DatePickerInput","CalendarEdit","mode","state","label","startLabel","endLabel","collapsed","onChange","validRange","locale","dateInput","useRef","startInput","endInput","useEffect","dismiss","inputsToFocus","current","filter","n","inputsToBlur","forEach","ip","blur","focus","onSubmitStartInput","useCallback","onSubmitEndInput","onSubmitInput","styles","root","date","inner","startDate","separator","endDate","create","padding","flexDirection","inputContainer","flex","input","width","memo"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,IADF,EAEEC,UAFF,EAIEC,QAJF,QAKO,cALP;AAUA,OAAOC,eAAP,MAA4B,mBAA5B;;AAEA,SAASC,YAAT,OAoBG;AAAA,MApBmB;AACpBC,IAAAA,IADoB;AAEpBC,IAAAA,KAFoB;AAGpBC,IAAAA,KAAK,GAAG,EAHY;AAIpBC,IAAAA,UAAU,GAAG,OAJO;AAKpBC,IAAAA,QAAQ,GAAG,KALS;AAMpBC,IAAAA,SANoB;AAOpBC,IAAAA,QAPoB;AAQpBC,IAAAA,UARoB;AASpBC,IAAAA;AAToB,GAoBnB;AACD,QAAMC,SAAS,GAAGf,KAAK,CAACgB,MAAN,CAAqC,IAArC,CAAlB;AACA,QA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FP;AAGE,IAAA,KAAK,EAAER,QAHT;AAIE,IAAA,KAAK,EAAEH,KAAK,CAACiC,OAJf;AAKE,IAAA,QAAQ,EAAGA,OAAD,IAAa5B,QAAQ,CAAC,EAAE,GAAGL,KAAL;AAAYiC,MAAAA;AAAZ,KAAD,CALjC;AAME,IAAA,eAAe,EAAER,gBANnB;AAOE,IAAA,UAAU,EAAEnB,UAPd;AAQE,IAAA,MAAM,EAAEC,MARV;AASE,IAAA,SAAS,EAAE,KATb;AAUE,IAAA,YAAY,EAAC;AAVf,IAfF,CADD,GA6BG,IA5CN,CADF;AAgDD;;AAED,MAAMoB,MAAM,GAAGhC,UAAU,CAACuC,MAAX,CAAkB;AAC/BN,EAAAA,IAAI,EAAE;AAAEO,IAAAA,OAAO,EAAE;AAAX,GADyB;AAE/BL,EAAAA,KAAK,EAAE;AAAEM,IAAAA,aAAa,EAAE;AAAjB,GAFwB;AAG/BC,EAAAA,cAAc,EAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAHe;AAI/BC,EAAAA,KAAK,EAAE;AAAED,IAAAA,IAAI,EAAE;AAAR,GAJwB;AAK/BN,EAAAA,SAAS,EAAE;AAAEQ,IAAAA,KAAK,EAAE;AAAT;AALoB,CAAlB,CAAf;AAQA,4BAAe/C,KAAK,CAACgD,IAAN,CAAW3C,YAAX,CAAf","sourcesContent":["import * as React from 'react'\nimport {\n View,\n StyleSheet,\n TextInput as TextInputNative,\n Keyboard,\n} from 'react-native'\n\nimport type { ModeType, ValidRangeType } from './Calendar'\nimport type { LocalState } from './DatePickerModalContent'\n\nimport DatePickerInput from './DatePickerInput'\n\nfunction CalendarEdit({\n mode,\n state,\n label = '',\n startLabel = 'Start',\n endLabel = 'End',\n collapsed,\n onChange,\n validRange,\n locale,\n}: {\n mode: ModeType\n label?: string\n startLabel?: string\n endLabel?: string\n state: LocalState\n collapsed: boolean\n onChange: (s: LocalState) => any\n validRange: ValidRangeType | undefined\n locale: string\n}) {\n const dateInput = React.useRef<TextInputNative | null>(null)\n const startInput = React.useRef<TextInputNative | null>(null)\n const endInput = React.useRef<TextInputNative | null>(null)\n\n // when switching views focus, or un-focus text input\n React.useEffect(() => {\n // hide open keyboard\n if (collapsed) {\n Keyboard.dismiss()\n }\n\n const inputsToFocus = [dateInput.current, startInput.current].filter(\n (n) => n\n ) as TextInputNative[]\n\n const inputsToBlur = [\n dateInput.current,\n startInput.current,\n endInput.current,\n ].filter((n) => n) as TextInputNative[]\n\n if (collapsed) {\n inputsToBlur.forEach((ip) => ip.blur())\n } else {\n inputsToFocus.forEach((ip) => ip.focus())\n }\n }, [mode, startInput, endInput, dateInput, collapsed])\n\n const onSubmitStartInput = React.useCallback(() => {\n if (endInput.current) {\n endInput.current.focus()\n }\n }, [endInput])\n\n const onSubmitEndInput = React.useCallback(() => {\n // TODO: close modal and persist range\n }, [])\n\n const onSubmitInput = React.useCallback(() => {\n // TODO: close modal and persist range\n }, [])\n\n return (\n <View style={styles.root}>\n {mode === 'single' ? (\n <DatePickerInput\n inputMode=\"start\"\n ref={dateInput}\n label={label}\n value={state.date}\n onChange={(date) => onChange({ ...state, date })}\n onSubmitEditing={onSubmitInput}\n validRange={validRange}\n locale={locale}\n withModal={false}\n autoComplete={'off'}\n />\n ) : null}\n {mode === 'range' ? (\n <View style={styles.inner}>\n <DatePickerInput\n inputMode=\"start\"\n ref={startInput}\n label={startLabel}\n value={state.startDate}\n onChange={(startDate) => onChange({ ...state, startDate })}\n returnKeyType={'next'}\n onSubmitEditing={onSubmitStartInput}\n validRange={validRange}\n locale={locale}\n withModal={false}\n autoComplete={'off'}\n />\n <View style={styles.separator} />\n <DatePickerInput\n inputMode=\"end\"\n ref={endInput}\n label={endLabel}\n value={state.endDate}\n onChange={(endDate) => onChange({ ...state, endDate })}\n onSubmitEditing={onSubmitEndInput}\n validRange={validRange}\n locale={locale}\n withModal={false}\n autoComplete=\"off\"\n />\n </View>\n ) : null}\n </View>\n )\n}\n\nconst styles = StyleSheet.create({\n root: { padding: 12 },\n inner: { flexDirection: 'row' },\n inputContainer: { flex: 1 },\n input: { flex: 1 },\n separator: { width: 12 },\n})\n\nexport default React.memo(CalendarEdit)\n"]}
|
|
@@ -169,13 +169,14 @@ export function getEndOfDay(d) {
|
|
|
169
169
|
}
|
|
170
170
|
export function useInputFormat(_ref7) {
|
|
171
171
|
let {
|
|
172
|
-
formatter
|
|
172
|
+
formatter,
|
|
173
|
+
locale
|
|
173
174
|
} = _ref7;
|
|
174
175
|
return React.useMemo(() => {
|
|
175
176
|
// TODO: something cleaner and more universal?
|
|
176
177
|
const inputDate = formatter.format(new Date(2020, 10 - 1, 1));
|
|
177
|
-
return inputDate.replace('2020', 'YYYY').replace('10', 'MM').replace('01', 'DD');
|
|
178
|
-
}, [formatter]);
|
|
178
|
+
return inputDate.replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY').replace('10', 'MM').replace('01', 'DD');
|
|
179
|
+
}, [formatter, locale]);
|
|
179
180
|
}
|
|
180
181
|
export function differenceInMonths(firstDate, secondDate) {
|
|
181
182
|
let diffMonths = (secondDate.getFullYear() - firstDate.getFullYear()) * 12;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["dateUtils.tsx"],"names":["React","useLatest","showWeekDay","dayIndex","disableWeekDays","some","di","dateToUnix","d","Math","round","getTime","addMonths","date","count","n","getDate","n2","Date","setDate","setMonth","getMonth","min","getDaysInMonth","year","getFullYear","month","isLeapYear","getFirstDayOfMonth","getDay","useRangeChecker","validRange","validStart","startDate","validEnd","endDate","startUnix","getStartOfDay","undefined","endUnix","getEndOfDay","validDisabledDatesRef","disabledDates","isWithinValidRange","useCallback","day","isDateWithinOptionalRange","isDisabled","current","disabledDate","areDatesOnSameDay","a","b","isDateBetween","dateUnix","daySize","estimatedMonthHeight","startAtIndex","totalMonths","beginOffset","gridCounts","Array","getGridCount","index","cHeight","monthDate","getRealIndex","h","getGridCountForDate","daysInMonth","dayOfWeek","ceil","getInitialIndex","today","months","differenceInMonths","useInputFormatter","locale","useMemo","Intl","DateTimeFormat","useInputFormat","formatter","inputDate","format","replace","firstDate","secondDate","diffMonths"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,SAAT,QAA0B,UAA1B;AAKA,OAAO,SAASC,WAAT,CACLC,QADK,EAELC,eAFK,EAGI;AACT,SAAO,EAAEA,eAAe,IAAIA,eAAe,CAACC,IAAhB,CAAsBC,EAAD,IAAQA,EAAE,KAAKH,QAApC,CAArB,CAAP;AACD;AAED,OAAO,SAASI,UAAT,CAAoBC,CAApB,EAAqC;AAC1C,SAAOC,IAAI,CAACC,KAAL,CAAWF,CAAC,CAACG,OAAF,KAAc,IAAzB,CAAP;AACD;AAED,OAAO,SAASC,SAAT,CAAmBC,IAAnB,EAA+BC,KAA/B,EAA8C;AACnD,MAAIC,CAAC,GAAGF,IAAI,CAACG,OAAL,EAAR;AACA,MAAIC,EAAE,GAAG,IAAIC,IAAJ,CAASL,IAAI,CAACF,OAAL,EAAT,CAAT;AACAM,EAAAA,EAAE,CAACE,OAAH,CAAW,CAAX;AACAF,EAAAA,EAAE,CAACG,QAAH,CAAYH,EAAE,CAACI,QAAH,KAAgBP,KAA5B;AACAG,EAAAA,EAAE,CAACE,OAAH,CACEV,IAAI,CAACa,GAAL,CACEP,CADF,EAEEQ,cAAc,CAAC;AAAEC,IAAAA,IAAI,EAAEP,EAAE,CAACQ,WAAH,EAAR;AAA0BC,IAAAA,KAAK,EAAET,EAAE,CAACI,QAAH;AAAjC,GAAD,CAFhB,CADF;AAOA,SAAOJ,EAAP;AACD,C,CAED;AACA;;AACA,OAAO,SAASM,cAAT,OAMI;AAAA,MANoB;AAC7BC,IAAAA,IAD6B;AAE7BE,IAAAA;AAF6B,GAMpB;AACT,SAAO,CACL,EADK,EAELC,UAAU,CAAC;AAAEH,IAAAA;AAAF,GAAD,CAAV,GAAuB,EAAvB,GAA4B,EAFvB,EAGL,EAHK,EAIL,EAJK,EAKL,EALK,EAML,E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AAN,CAAc,MAAM;AACzB;AACA,UAAMK,SAAS,GAAGD,SAAS,CAACE,MAAV,CAAiB,IAAIlE,IAAJ,CAAS,IAAT,EAAe,KAAK,CAApB,EAAuB,CAAvB,CAAjB,CAAlB;AACA,WAAOiE,SAAS,CACbE,OADI,CACI,MADJ,EACY,MADZ,EAEJA,OAFI,CAEI,IAFJ,EAEU,IAFV,EAGJA,OAHI,CAGI,IAHJ,EAGU,IAHV,CAAP;AAID,GAPM,EAOJ,CAACH,SAAD,CAPI,CAAP;AAQD;AAED,OAAO,SAASP,kBAAT,CAA4BW,SAA5B,EAA6CC,UAA7C,EAA+D;AACpE,MAAIC,UAAU,GAAG,CAACD,UAAU,CAAC9D,WAAX,KAA2B6D,SAAS,CAAC7D,WAAV,EAA5B,IAAuD,EAAxE;AACA+D,EAAAA,UAAU,IAAIF,SAAS,CAACjE,QAAV,EAAd;AACAmE,EAAAA,UAAU,IAAID,UAAU,CAAClE,QAAX,EAAd;AACA,SAAOmE,UAAP;AACD","sourcesContent":["import * as React from 'react'\nimport { useLatest } from '../utils'\nimport type { ValidRangeType } from './Calendar'\n\nexport type DisableWeekDaysType = number[]\n\nexport function showWeekDay(\n dayIndex: number,\n disableWeekDays?: DisableWeekDaysType\n): boolean {\n return !(disableWeekDays && disableWeekDays.some((di) => di === dayIndex))\n}\n\nexport function dateToUnix(d: Date): number {\n return Math.round(d.getTime() / 1000)\n}\n\nexport function addMonths(date: Date, count: number) {\n let n = date.getDate()\n let n2 = new Date(date.getTime())\n n2.setDate(1)\n n2.setMonth(n2.getMonth() + count)\n n2.setDate(\n Math.min(\n n,\n getDaysInMonth({ year: n2.getFullYear(), month: n2.getMonth() })\n )\n )\n\n return n2\n}\n\n// https://stackoverflow.com/a/1185068/2508481\n// pass in any date as parameter anyDateInMonth based on dayjs\nexport function getDaysInMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return [\n 31,\n isLeapYear({ year }) ? 29 : 28,\n 31,\n 30,\n 31,\n 30,\n 31,\n 31,\n 30,\n 31,\n 30,\n 31,\n ][month]\n}\n\nexport function getFirstDayOfMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return new Date(year, month, 1).getDay()\n}\n\nexport function useRangeChecker(validRange: ValidRangeType | undefined) {\n const validStart = validRange?.startDate\n const validEnd = validRange?.endDate\n const startUnix =\n validStart instanceof Date\n ? dateToUnix(getStartOfDay(validStart))\n : undefined\n\n const endUnix =\n validEnd instanceof Date ? dateToUnix(getEndOfDay(validEnd)) : undefined\n\n const validDisabledDatesRef = useLatest(validRange?.disabledDates)\n\n const isWithinValidRange = React.useCallback(\n (day: Date) => {\n return isDateWithinOptionalRange(day, {\n startUnix: startUnix,\n endUnix: endUnix,\n })\n },\n [startUnix, endUnix]\n )\n\n const isDisabled = React.useCallback(\n (day: Date) => {\n return validDisabledDatesRef.current\n ? validDisabledDatesRef.current.some((disabledDate) =>\n areDatesOnSameDay(disabledDate, day)\n )\n : false\n },\n [validDisabledDatesRef]\n )\n\n return { isDisabled, isWithinValidRange, validStart, validEnd }\n}\n\nexport function areDatesOnSameDay(a: Date, b?: Date | null | undefined) {\n if (!b) {\n return false\n }\n\n return (\n a.getFullYear() === b.getFullYear() &&\n a.getMonth() === b.getMonth() &&\n a.getDate() === b.getDate()\n )\n}\n\nexport function isDateBetween(\n date: Date,\n {\n startDate,\n endDate,\n }: {\n startDate?: Date | null | undefined\n endDate?: Date | null | undefined\n }\n): boolean {\n if (!startDate || !endDate) {\n return false\n }\n return date <= endDate && date >= startDate\n}\n\n/**\n * Check if a date is within an optional range.\n *\n * If the range doesn't exist, it defaults to `true`.\n */\nexport function isDateWithinOptionalRange(\n date: Date,\n {\n startUnix,\n endUnix,\n }: { startUnix: number | undefined; endUnix: number | undefined }\n) {\n const dateUnix = dateToUnix(date)\n // if startUnix is provided and date is before start\n if (startUnix && dateUnix < startUnix) {\n return false\n }\n\n // if endUnix is provided and date is after end\n if (endUnix && dateUnix > endUnix) {\n return false\n }\n\n return true\n}\n\nexport function isLeapYear({ year }: { year: number }) {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n}\n\nexport const daySize = 46\nexport const estimatedMonthHeight = 360\nexport const startAtIndex = 1200\nexport const totalMonths = startAtIndex * 2\nexport const beginOffset = estimatedMonthHeight * startAtIndex\nexport const gridCounts = new Array<number | undefined>(totalMonths)\n\nexport function getGridCount(index: number) {\n const cHeight = gridCounts[index]\n if (cHeight) {\n return cHeight\n }\n const monthDate = addMonths(new Date(), getRealIndex(index))\n const h = getGridCountForDate(monthDate)\n gridCounts[index] = h\n return h\n}\n\nexport function getGridCountForDate(date: Date) {\n const year = date.getFullYear()\n const month = date.getMonth()\n const daysInMonth = getDaysInMonth({ year, month })\n const dayOfWeek = getFirstDayOfMonth({ year, month })\n return Math.ceil((daysInMonth + dayOfWeek) / 7)\n}\n\nexport function getRealIndex(index: number) {\n return index - startAtIndex\n}\n\nexport function getInitialIndex(date: Date | undefined) {\n if (!date) {\n return startAtIndex\n }\n\n const today = new Date()\n const months = differenceInMonths(today, date)\n\n return startAtIndex + months\n}\n\nexport function useInputFormatter({ locale }: { locale: string | undefined }) {\n return React.useMemo(() => {\n return new Intl.DateTimeFormat(locale, {\n month: '2-digit',\n day: '2-digit',\n year: 'numeric',\n })\n }, [locale])\n}\nexport function getStartOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0)\n}\nexport function getEndOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59)\n}\nexport function useInputFormat({\n formatter,\n}: {\n formatter: Intl.DateTimeFormat\n}) {\n return React.useMemo(() => {\n // TODO: something cleaner and more universal?\n const inputDate = formatter.format(new Date(2020, 10 - 1, 1))\n return inputDate\n .replace('2020', 'YYYY')\n .replace('10', 'MM')\n .replace('01', 'DD')\n }, [formatter])\n}\n\nexport function differenceInMonths(firstDate: Date, secondDate: Date) {\n let diffMonths = (secondDate.getFullYear() - firstDate.getFullYear()) * 12\n diffMonths -= firstDate.getMonth()\n diffMonths += secondDate.getMonth()\n return diffMonths\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["dateUtils.tsx"],"names":["React","useLatest","showWeekDay","dayIndex","disableWeekDays","some","di","dateToUnix","d","Math","round","getTime","addMonths","date","count","n","getDate","n2","Date","setDate","setMonth","getMonth","min","getDaysInMonth","year","getFullYear","month","isLeapYear","getFirstDayOfMonth","getDay","useRangeChecker","validRange","validStart","startDate","validEnd","endDate","startUnix","getStartOfDay","undefined","endUnix","getEndOfDay","validDisabledDatesRef","disabledDates","isWithinValidRange","useCallback","day","isDateWithinOptionalRange","isDisabled","current","disabledDate","areDatesOnSameDay","a","b","isDateBetween","dateUnix","daySize","estimatedMonthHeight","startAtIndex","totalMonths","beginOffset","gridCounts","Array","getGridCount","index","cHeight","monthDate","getRealIndex","h","getGridCountForDate","daysInMonth","dayOfWeek","ceil","getInitialIndex","today","months","differenceInMonths","useInputFormatter","locale","useMemo","Intl","DateTimeFormat","useInputFormat","formatter","inputDate","format","replace","firstDate","secondDate","diffMonths"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,SAAT,QAA0B,UAA1B;AAKA,OAAO,SAASC,WAAT,CACLC,QADK,EAELC,eAFK,EAGI;AACT,SAAO,EAAEA,eAAe,IAAIA,eAAe,CAACC,IAAhB,CAAsBC,EAAD,IAAQA,EAAE,KAAKH,QAApC,CAArB,CAAP;AACD;AAED,OAAO,SAASI,UAAT,CAAoBC,CAApB,EAAqC;AAC1C,SAAOC,IAAI,CAACC,KAAL,CAAWF,CAAC,CAACG,OAAF,KAAc,IAAzB,CAAP;AACD;AAED,OAAO,SAASC,SAAT,CAAmBC,IAAnB,EAA+BC,KAA/B,EAA8C;AACnD,MAAIC,CAAC,GAAGF,IAAI,CAACG,OAAL,EAAR;AACA,MAAIC,EAAE,GAAG,IAAIC,IAAJ,CAASL,IAAI,CAACF,OAAL,EAAT,CAAT;AACAM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AAA,UAAU,IAAID,UAAU,CAAClE,QAAX,EAAd;AACA,SAAOmE,UAAP;AACD","sourcesContent":["import * as React from 'react'\nimport { useLatest } from '../utils'\nimport type { ValidRangeType } from './Calendar'\n\nexport type DisableWeekDaysType = number[]\n\nexport function showWeekDay(\n dayIndex: number,\n disableWeekDays?: DisableWeekDaysType\n): boolean {\n return !(disableWeekDays && disableWeekDays.some((di) => di === dayIndex))\n}\n\nexport function dateToUnix(d: Date): number {\n return Math.round(d.getTime() / 1000)\n}\n\nexport function addMonths(date: Date, count: number) {\n let n = date.getDate()\n let n2 = new Date(date.getTime())\n n2.setDate(1)\n n2.setMonth(n2.getMonth() + count)\n n2.setDate(\n Math.min(\n n,\n getDaysInMonth({ year: n2.getFullYear(), month: n2.getMonth() })\n )\n )\n\n return n2\n}\n\n// https://stackoverflow.com/a/1185068/2508481\n// pass in any date as parameter anyDateInMonth based on dayjs\nexport function getDaysInMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return [\n 31,\n isLeapYear({ year }) ? 29 : 28,\n 31,\n 30,\n 31,\n 30,\n 31,\n 31,\n 30,\n 31,\n 30,\n 31,\n ][month]\n}\n\nexport function getFirstDayOfMonth({\n year,\n month,\n}: {\n year: number\n month: number\n}): number {\n return new Date(year, month, 1).getDay()\n}\n\nexport function useRangeChecker(validRange: ValidRangeType | undefined) {\n const validStart = validRange?.startDate\n const validEnd = validRange?.endDate\n const startUnix =\n validStart instanceof Date\n ? dateToUnix(getStartOfDay(validStart))\n : undefined\n\n const endUnix =\n validEnd instanceof Date ? dateToUnix(getEndOfDay(validEnd)) : undefined\n\n const validDisabledDatesRef = useLatest(validRange?.disabledDates)\n\n const isWithinValidRange = React.useCallback(\n (day: Date) => {\n return isDateWithinOptionalRange(day, {\n startUnix: startUnix,\n endUnix: endUnix,\n })\n },\n [startUnix, endUnix]\n )\n\n const isDisabled = React.useCallback(\n (day: Date) => {\n return validDisabledDatesRef.current\n ? validDisabledDatesRef.current.some((disabledDate) =>\n areDatesOnSameDay(disabledDate, day)\n )\n : false\n },\n [validDisabledDatesRef]\n )\n\n return { isDisabled, isWithinValidRange, validStart, validEnd }\n}\n\nexport function areDatesOnSameDay(a: Date, b?: Date | null | undefined) {\n if (!b) {\n return false\n }\n\n return (\n a.getFullYear() === b.getFullYear() &&\n a.getMonth() === b.getMonth() &&\n a.getDate() === b.getDate()\n )\n}\n\nexport function isDateBetween(\n date: Date,\n {\n startDate,\n endDate,\n }: {\n startDate?: Date | null | undefined\n endDate?: Date | null | undefined\n }\n): boolean {\n if (!startDate || !endDate) {\n return false\n }\n return date <= endDate && date >= startDate\n}\n\n/**\n * Check if a date is within an optional range.\n *\n * If the range doesn't exist, it defaults to `true`.\n */\nexport function isDateWithinOptionalRange(\n date: Date,\n {\n startUnix,\n endUnix,\n }: { startUnix: number | undefined; endUnix: number | undefined }\n) {\n const dateUnix = dateToUnix(date)\n // if startUnix is provided and date is before start\n if (startUnix && dateUnix < startUnix) {\n return false\n }\n\n // if endUnix is provided and date is after end\n if (endUnix && dateUnix > endUnix) {\n return false\n }\n\n return true\n}\n\nexport function isLeapYear({ year }: { year: number }) {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n}\n\nexport const daySize = 46\nexport const estimatedMonthHeight = 360\nexport const startAtIndex = 1200\nexport const totalMonths = startAtIndex * 2\nexport const beginOffset = estimatedMonthHeight * startAtIndex\nexport const gridCounts = new Array<number | undefined>(totalMonths)\n\nexport function getGridCount(index: number) {\n const cHeight = gridCounts[index]\n if (cHeight) {\n return cHeight\n }\n const monthDate = addMonths(new Date(), getRealIndex(index))\n const h = getGridCountForDate(monthDate)\n gridCounts[index] = h\n return h\n}\n\nexport function getGridCountForDate(date: Date) {\n const year = date.getFullYear()\n const month = date.getMonth()\n const daysInMonth = getDaysInMonth({ year, month })\n const dayOfWeek = getFirstDayOfMonth({ year, month })\n return Math.ceil((daysInMonth + dayOfWeek) / 7)\n}\n\nexport function getRealIndex(index: number) {\n return index - startAtIndex\n}\n\nexport function getInitialIndex(date: Date | undefined) {\n if (!date) {\n return startAtIndex\n }\n\n const today = new Date()\n const months = differenceInMonths(today, date)\n\n return startAtIndex + months\n}\n\nexport function useInputFormatter({ locale }: { locale: string | undefined }) {\n return React.useMemo(() => {\n return new Intl.DateTimeFormat(locale, {\n month: '2-digit',\n day: '2-digit',\n year: 'numeric',\n })\n }, [locale])\n}\nexport function getStartOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0)\n}\nexport function getEndOfDay(d: Date): Date {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59)\n}\nexport function useInputFormat({\n formatter,\n locale,\n}: {\n formatter: Intl.DateTimeFormat\n locale: string | undefined\n}) {\n return React.useMemo(() => {\n // TODO: something cleaner and more universal?\n const inputDate = formatter.format(new Date(2020, 10 - 1, 1))\n return inputDate\n .replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY')\n .replace('10', 'MM')\n .replace('01', 'DD')\n }, [formatter, locale])\n}\n\nexport function differenceInMonths(firstDate: Date, secondDate: Date) {\n let diffMonths = (secondDate.getFullYear() - firstDate.getFullYear()) * 12\n diffMonths -= firstDate.getMonth()\n diffMonths += secondDate.getMonth()\n return diffMonths\n}\n"]}
|
|
@@ -20,14 +20,15 @@ export default function useDateInput(_ref) {
|
|
|
20
20
|
locale
|
|
21
21
|
});
|
|
22
22
|
const inputFormat = useInputFormat({
|
|
23
|
-
formatter
|
|
23
|
+
formatter,
|
|
24
|
+
locale
|
|
24
25
|
});
|
|
25
26
|
const formattedValue = formatter.format(value);
|
|
26
27
|
|
|
27
28
|
const onChangeText = date => {
|
|
28
29
|
const dayIndex = inputFormat.indexOf('DD');
|
|
29
30
|
const monthIndex = inputFormat.indexOf('MM');
|
|
30
|
-
const yearIndex = inputFormat.indexOf('YYYY');
|
|
31
|
+
const yearIndex = locale === 'pt' ? inputFormat.indexOf('AAAA') : inputFormat.indexOf('YYYY');
|
|
31
32
|
const day = Number(date.slice(dayIndex, dayIndex + 2));
|
|
32
33
|
const year = Number(date.slice(yearIndex, yearIndex + 4));
|
|
33
34
|
const month = Number(date.slice(monthIndex, monthIndex + 2));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["inputUtils.ts"],"names":["useInputFormat","useInputFormatter","useRangeChecker","React","getTranslation","useDateInput","locale","value","validRange","inputMode","onChange","isDisabled","isWithinValidRange","validStart","validEnd","error","setError","useState","formatter","inputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","finalDate","Date","errors","filter","n","join"],"mappings":"AAAA,SAASA,cAAT,EAAyBC,iBAAzB,EAA4CC,eAA5C,QAAmE,aAAnE;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,SAASC,cAAT,QAA+B,0BAA/B;AAEA,eAAe,SAASC,YAAT,OAYZ;AAAA,MAZkC;AACnCC,IAAAA,MADmC;AAEnCC,IAAAA,KAFmC;AAGnCC,IAAAA,UAHmC;AAInCC,IAAAA,SAJmC;AAKnCC,IAAAA;AALmC,GAYlC;AACD,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,kBAAd;AAAkCC,IAAAA,UAAlC;AAA8CC,IAAAA;AAA9C,MACJZ,eAAe,CAACM,UAAD,CADjB;AAEA,QAAM,CAACO,KAAD,EAAQC,QAAR,IAAoBb,KAAK,CAACc,QAAN,CAA8B,IAA9B,CAA1B;AACA,QAAMC,SAAS,GAAGjB,iBAAiB,CAAC;AAAEK,IAAAA;AAAF,GAAD,CAAnC;AACA,QAAMa,WAAW,GAAGnB,cAAc,CAAC;AAAEkB,IAAAA;
|
|
1
|
+
{"version":3,"sources":["inputUtils.ts"],"names":["useInputFormat","useInputFormatter","useRangeChecker","React","getTranslation","useDateInput","locale","value","validRange","inputMode","onChange","isDisabled","isWithinValidRange","validStart","validEnd","error","setError","useState","formatter","inputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","finalDate","Date","errors","filter","n","join"],"mappings":"AAAA,SAASA,cAAT,EAAyBC,iBAAzB,EAA4CC,eAA5C,QAAmE,aAAnE;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,SAASC,cAAT,QAA+B,0BAA/B;AAEA,eAAe,SAASC,YAAT,OAYZ;AAAA,MAZkC;AACnCC,IAAAA,MADmC;AAEnCC,IAAAA,KAFmC;AAGnCC,IAAAA,UAHmC;AAInCC,IAAAA,SAJmC;AAKnCC,IAAAA;AALmC,GAYlC;AACD,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,kBAAd;AAAkCC,IAAAA,UAAlC;AAA8CC,IAAAA;AAA9C,MACJZ,eAAe,CAACM,UAAD,CADjB;AAEA,QAAM,CAACO,KAAD,EAAQC,QAAR,IAAoBb,KAAK,CAACc,QAAN,CAA8B,IAA9B,CAA1B;AACA,QAAMC,SAAS,GAAGjB,iBAAiB,CAAC;AAAEK,IAAAA;AAAF,GAAD,CAAnC;AACA,QAAMa,WAAW,GAAGnB,cAAc,CAAC;AAAEkB,IAAAA,SAAF;AAAaZ,IAAAA;AAAb,GAAD,CAAlC;AACA,QAAMc,cAAc,GAAGF,SAAS,CAACG,MAAV,CAAiBd,KAAjB,CAAvB;;AACA,QAAMe,YAAY,GAAIC,IAAD,IAAkB;AACrC,UAAMC,QAAQ,GAAGL,WAAW,CAACM,OAAZ,CAAoB,IAApB,CAAjB;AACA,UAAMC,UAAU,GAAGP,WAAW,CAACM,OAAZ,CAAoB,IAApB,CAAnB;AACA,UAAME,SAAS,GACbrB,MAAM,KAAK,IAAX,GACIa,WAAW,CAACM,OAAZ,CAAoB,MAApB,CADJ,GAEIN,WAAW,CAACM,OAAZ,CAAoB,MAApB,CAHN;AAKA,UAAMG,GAAG,GAAGC,MAAM,CAACN,IAAI,CAACO,KAAL,CAAWN,QAAX,EAAqBA,QAAQ,GAAG,CAAhC,CAAD,CA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BAHM,CAAd,CAIEY,SAAS,CAACG,MAAV,CAAiBR,UAAjB,CAJF,CADM,GAMN,EAPN,EAQEC,QAAQ,GACJV,cAAc,CACZE,MADY,EAEZ,iBAFY,EAGZ,MAAM,iBAHM,CAAd,CAIEY,SAAS,CAACG,MAAV,CAAiBP,QAAjB,CAJF,CADI,GAMJ,EAdN,CATN;AAyBAE,MAAAA,QAAQ,CAACoB,MAAM,CAACC,MAAP,CAAeC,CAAD,IAAOA,CAArB,EAAwBC,IAAxB,CAA6B,GAA7B,CAAD,CAAR;AACA;AACD;;AAEDvB,IAAAA,QAAQ,CAAC,IAAD,CAAR;;AACA,QAAIP,SAAS,KAAK,KAAlB,EAAyB;AACvBC,MAAAA,QAAQ,CAACwB,SAAD,CAAR;AACD,KAFD,MAEO;AACLxB,MAAAA,QAAQ,CAACwB,SAAD,CAAR;AACD;AACF,GApED;;AAqEA,SAAO;AACLxB,IAAAA,QADK;AAELK,IAAAA,KAFK;AAGLK,IAAAA,cAHK;AAILE,IAAAA,YAJK;AAKLH,IAAAA;AALK,GAAP;AAOD","sourcesContent":["import { useInputFormat, useInputFormatter, useRangeChecker } from './dateUtils'\nimport * as React from 'react'\nimport type { ValidRangeType } from './Calendar'\nimport { getTranslation } from 'react-native-paper-dates'\n\nexport default function useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n}: {\n onChange: (d: Date) => void\n locale: undefined | string\n value: Date | undefined\n validRange: ValidRangeType | undefined\n inputMode: 'start' | 'end'\n}) {\n const { isDisabled, isWithinValidRange, validStart, validEnd } =\n useRangeChecker(validRange)\n const [error, setError] = React.useState<null | string>(null)\n const formatter = useInputFormatter({ locale })\n const inputFormat = useInputFormat({ formatter, locale })\n const formattedValue = formatter.format(value)\n const onChangeText = (date: string) => {\n const dayIndex = inputFormat.indexOf('DD')\n const monthIndex = inputFormat.indexOf('MM')\n const yearIndex =\n locale === 'pt'\n ? inputFormat.indexOf('AAAA')\n : inputFormat.indexOf('YYYY')\n\n const day = Number(date.slice(dayIndex, dayIndex + 2))\n const year = Number(date.slice(yearIndex, yearIndex + 4))\n const month = Number(date.slice(monthIndex, monthIndex + 2))\n\n if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {\n setError(\n getTranslation(\n locale,\n 'notAccordingToDateFormat',\n () => 'notAccordingToDateFormat'\n )(inputFormat)\n )\n return\n }\n\n const finalDate =\n inputMode === 'end'\n ? new Date(year, month - 1, day, 23, 59, 59)\n : new Date(year, month - 1, day)\n\n if (isDisabled(finalDate)) {\n setError(getTranslation(locale, 'dateIsDisabled'))\n return\n }\n if (!isWithinValidRange(finalDate)) {\n let errors =\n validStart && validEnd\n ? [\n `${getTranslation(\n locale,\n 'mustBeBetween',\n () => 'mustBeBetween'\n )(formatter.format(validStart), formatter.format(validEnd))}`,\n ]\n : [\n validStart\n ? getTranslation(\n locale,\n 'mustBeHigherThan',\n () => 'mustBeHigherThan'\n )(formatter.format(validStart))\n : '',\n validEnd\n ? getTranslation(\n locale,\n 'mustBeLowerThan',\n () => 'mustBeLowerThan'\n )(formatter.format(validEnd))\n : '',\n ]\n setError(errors.filter((n) => n).join(' '))\n return\n }\n\n setError(null)\n if (inputMode === 'end') {\n onChange(finalDate)\n } else {\n onChange(finalDate)\n }\n }\n return {\n onChange,\n error,\n formattedValue,\n onChangeText,\n inputFormat,\n }\n}\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -11,4 +11,5 @@ export { default as en } from './translations/en';
|
|
|
11
11
|
export { default as pl } from './translations/pl';
|
|
12
12
|
export { default as pt } from './translations/pt';
|
|
13
13
|
export { default as enGB } from './translations/enGB';
|
|
14
|
+
export { default as de } from './translations/de';
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["default","Calendar","DatePickerModal","DatePickerModalContent","TimePickerModal","TimePicker","DatePickerInput","registerTranslation","getTranslation","nl","en","pl","pt","enGB"],"mappings":"AAAA,SAASA,OAAO,IAAIC,QAApB,QAAoC,iBAApC;AACA,SAASD,OAAO,IAAIE,eAApB,QAA2C,wBAA3C;AACA,cAAc,wBAAd;AACA,SAASF,OAAO,IAAIG,sBAApB,QAAkD,+BAAlD;AACA,SAASH,OAAO,IAAII,eAApB,QAA2C,wBAA3C;AACA,SAASJ,OAAO,IAAIK,UAApB,QAAsC,mBAAtC;AACA,SAASL,OAAO,IAAIM,eAApB,QAA2C,wBAA3C;AAEA,SAASC,mBAAT,EAA8BC,cAA9B,QAAoD,sBAApD;AACA,SAASR,OAAO,IAAIS,EAApB,QAA8B,mBAA9B;AACA,SAAST,OAAO,IAAIU,EAApB,QAA8B,mBAA9B;AACA,SAASV,OAAO,IAAIW,EAApB,QAA8B,mBAA9B;AACA,SAASX,OAAO,IAAIY,EAApB,QAA8B,mBAA9B;AACA,SAASZ,OAAO,IAAIa,IAApB,QAAgC,qBAAhC","sourcesContent":["export { default as Calendar } from './Date/Calendar'\nexport { default as DatePickerModal } from './Date/DatePickerModal'\nexport * from './Date/DatePickerModal'\nexport { default as DatePickerModalContent } from './Date/DatePickerModalContent'\nexport { default as TimePickerModal } from './Time/TimePickerModal'\nexport { default as TimePicker } from './Time/TimePicker'\nexport { default as DatePickerInput } from './Date/DatePickerInput'\nexport type { TranslationsType } from './translations/utils'\nexport { registerTranslation, getTranslation } from './translations/utils'\nexport { default as nl } from './translations/nl'\nexport { default as en } from './translations/en'\nexport { default as pl } from './translations/pl'\nexport { default as pt } from './translations/pt'\nexport { default as enGB } from './translations/enGB'\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["default","Calendar","DatePickerModal","DatePickerModalContent","TimePickerModal","TimePicker","DatePickerInput","registerTranslation","getTranslation","nl","en","pl","pt","enGB","de"],"mappings":"AAAA,SAASA,OAAO,IAAIC,QAApB,QAAoC,iBAApC;AACA,SAASD,OAAO,IAAIE,eAApB,QAA2C,wBAA3C;AACA,cAAc,wBAAd;AACA,SAASF,OAAO,IAAIG,sBAApB,QAAkD,+BAAlD;AACA,SAASH,OAAO,IAAII,eAApB,QAA2C,wBAA3C;AACA,SAASJ,OAAO,IAAIK,UAApB,QAAsC,mBAAtC;AACA,SAASL,OAAO,IAAIM,eAApB,QAA2C,wBAA3C;AAEA,SAASC,mBAAT,EAA8BC,cAA9B,QAAoD,sBAApD;AACA,SAASR,OAAO,IAAIS,EAApB,QAA8B,mBAA9B;AACA,SAAST,OAAO,IAAIU,EAApB,QAA8B,mBAA9B;AACA,SAASV,OAAO,IAAIW,EAApB,QAA8B,mBAA9B;AACA,SAASX,OAAO,IAAIY,EAApB,QAA8B,mBAA9B;AACA,SAASZ,OAAO,IAAIa,IAApB,QAAgC,qBAAhC;AACA,SAASb,OAAO,IAAIc,EAApB,QAA8B,mBAA9B","sourcesContent":["export { default as Calendar } from './Date/Calendar'\nexport { default as DatePickerModal } from './Date/DatePickerModal'\nexport * from './Date/DatePickerModal'\nexport { default as DatePickerModalContent } from './Date/DatePickerModalContent'\nexport { default as TimePickerModal } from './Time/TimePickerModal'\nexport { default as TimePicker } from './Time/TimePicker'\nexport { default as DatePickerInput } from './Date/DatePickerInput'\nexport type { TranslationsType } from './translations/utils'\nexport { registerTranslation, getTranslation } from './translations/utils'\nexport { default as nl } from './translations/nl'\nexport { default as en } from './translations/en'\nexport { default as pl } from './translations/pl'\nexport { default as pt } from './translations/pt'\nexport { default as enGB } from './translations/enGB'\nexport { default as de } from './translations/de'\n"]}
|
|
@@ -49,7 +49,8 @@ export declare function useInputFormatter({ locale }: {
|
|
|
49
49
|
}): Intl.DateTimeFormat;
|
|
50
50
|
export declare function getStartOfDay(d: Date): Date;
|
|
51
51
|
export declare function getEndOfDay(d: Date): Date;
|
|
52
|
-
export declare function useInputFormat({ formatter, }: {
|
|
52
|
+
export declare function useInputFormat({ formatter, locale, }: {
|
|
53
53
|
formatter: Intl.DateTimeFormat;
|
|
54
|
+
locale: string | undefined;
|
|
54
55
|
}): string;
|
|
55
56
|
export declare function differenceInMonths(firstDate: Date, secondDate: Date): number;
|
package/package.json
CHANGED
|
@@ -76,52 +76,50 @@ function CalendarEdit({
|
|
|
76
76
|
|
|
77
77
|
return (
|
|
78
78
|
<View style={styles.root}>
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
{mode === 'single' ? (
|
|
80
|
+
<DatePickerInput
|
|
81
|
+
inputMode="start"
|
|
82
|
+
ref={dateInput}
|
|
83
|
+
label={label}
|
|
84
|
+
value={state.date}
|
|
85
|
+
onChange={(date) => onChange({ ...state, date })}
|
|
86
|
+
onSubmitEditing={onSubmitInput}
|
|
87
|
+
validRange={validRange}
|
|
88
|
+
locale={locale}
|
|
89
|
+
withModal={false}
|
|
90
|
+
autoComplete={'off'}
|
|
91
|
+
/>
|
|
92
|
+
) : null}
|
|
93
|
+
{mode === 'range' ? (
|
|
94
|
+
<View style={styles.inner}>
|
|
81
95
|
<DatePickerInput
|
|
82
96
|
inputMode="start"
|
|
83
|
-
ref={
|
|
84
|
-
label={
|
|
85
|
-
value={state.
|
|
86
|
-
onChange={(
|
|
87
|
-
|
|
97
|
+
ref={startInput}
|
|
98
|
+
label={startLabel}
|
|
99
|
+
value={state.startDate}
|
|
100
|
+
onChange={(startDate) => onChange({ ...state, startDate })}
|
|
101
|
+
returnKeyType={'next'}
|
|
102
|
+
onSubmitEditing={onSubmitStartInput}
|
|
88
103
|
validRange={validRange}
|
|
89
104
|
locale={locale}
|
|
90
105
|
withModal={false}
|
|
91
106
|
autoComplete={'off'}
|
|
92
107
|
/>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/>
|
|
109
|
-
<View style={styles.separator} />
|
|
110
|
-
<DatePickerInput
|
|
111
|
-
inputMode="end"
|
|
112
|
-
ref={endInput}
|
|
113
|
-
label={endLabel}
|
|
114
|
-
value={state.endDate}
|
|
115
|
-
onChange={(endDate) => onChange({ ...state, endDate })}
|
|
116
|
-
onSubmitEditing={onSubmitEndInput}
|
|
117
|
-
validRange={validRange}
|
|
118
|
-
locale={locale}
|
|
119
|
-
withModal={false}
|
|
120
|
-
autoComplete="off"
|
|
121
|
-
/>
|
|
122
|
-
</>
|
|
123
|
-
) : null}
|
|
124
|
-
</View>
|
|
108
|
+
<View style={styles.separator} />
|
|
109
|
+
<DatePickerInput
|
|
110
|
+
inputMode="end"
|
|
111
|
+
ref={endInput}
|
|
112
|
+
label={endLabel}
|
|
113
|
+
value={state.endDate}
|
|
114
|
+
onChange={(endDate) => onChange({ ...state, endDate })}
|
|
115
|
+
onSubmitEditing={onSubmitEndInput}
|
|
116
|
+
validRange={validRange}
|
|
117
|
+
locale={locale}
|
|
118
|
+
withModal={false}
|
|
119
|
+
autoComplete="off"
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
) : null}
|
|
125
123
|
</View>
|
|
126
124
|
)
|
|
127
125
|
}
|
package/src/Date/dateUtils.tsx
CHANGED
|
@@ -218,17 +218,19 @@ export function getEndOfDay(d: Date): Date {
|
|
|
218
218
|
}
|
|
219
219
|
export function useInputFormat({
|
|
220
220
|
formatter,
|
|
221
|
+
locale,
|
|
221
222
|
}: {
|
|
222
223
|
formatter: Intl.DateTimeFormat
|
|
224
|
+
locale: string | undefined
|
|
223
225
|
}) {
|
|
224
226
|
return React.useMemo(() => {
|
|
225
227
|
// TODO: something cleaner and more universal?
|
|
226
228
|
const inputDate = formatter.format(new Date(2020, 10 - 1, 1))
|
|
227
229
|
return inputDate
|
|
228
|
-
.replace('2020', 'YYYY')
|
|
230
|
+
.replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY')
|
|
229
231
|
.replace('10', 'MM')
|
|
230
232
|
.replace('01', 'DD')
|
|
231
|
-
}, [formatter])
|
|
233
|
+
}, [formatter, locale])
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
export function differenceInMonths(firstDate: Date, secondDate: Date) {
|
package/src/Date/inputUtils.ts
CHANGED
|
@@ -20,12 +20,15 @@ export default function useDateInput({
|
|
|
20
20
|
useRangeChecker(validRange)
|
|
21
21
|
const [error, setError] = React.useState<null | string>(null)
|
|
22
22
|
const formatter = useInputFormatter({ locale })
|
|
23
|
-
const inputFormat = useInputFormat({ formatter })
|
|
23
|
+
const inputFormat = useInputFormat({ formatter, locale })
|
|
24
24
|
const formattedValue = formatter.format(value)
|
|
25
25
|
const onChangeText = (date: string) => {
|
|
26
26
|
const dayIndex = inputFormat.indexOf('DD')
|
|
27
27
|
const monthIndex = inputFormat.indexOf('MM')
|
|
28
|
-
const yearIndex =
|
|
28
|
+
const yearIndex =
|
|
29
|
+
locale === 'pt'
|
|
30
|
+
? inputFormat.indexOf('AAAA')
|
|
31
|
+
: inputFormat.indexOf('YYYY')
|
|
29
32
|
|
|
30
33
|
const day = Number(date.slice(dayIndex, dayIndex + 2))
|
|
31
34
|
const year = Number(date.slice(yearIndex, yearIndex + 4))
|
package/src/index.tsx
CHANGED