@momo-kits/calendar 0.0.32-beta → 0.0.32

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/src/Util.js CHANGED
@@ -1 +1,225 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _moment=_interopRequireDefault(require("moment"));var _core=require("@momo-kits/core");var _LunarDateConverter=_interopRequireDefault(require("./LunarDateConverter"));var _holidayData=_interopRequireDefault(require("./holidayData"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});}keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var I18N_MAP={en:{w:['','Mon','Tues','Wed','Thur','Fri','Sat','Sun'],weekday:['','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],text:{start:'Start',end:'End',date:'Date',save:'Save',clear:'Reset'},date:'DD / MM'},vi:{w:['','T2','T3','T4','T5','T6','T7','CN'],weekday:['','Thứ hai','Thứ ba','Thứ tư','Thứ năm','Thứ sáu','Thứ bảy','Chủ nhật'],text:{start:'Start',end:'End',date:'Date',save:'Save',clear:'Reset'},date:'DD / MM'}};var Solar=function Solar(momentDate){return{solarDay:momentDate.date(),solarMonth:momentDate.month()+1,solarYear:momentDate.year()};};var formatYYYYMMDD=function formatYYYYMMDD(dd,mm,yyyy){return yyyy+"-"+(mm<10?"0"+mm:mm)+"-"+(dd<10?"0"+dd:dd);};var formatDDMM=function formatDDMM(dd,mm){return(dd<10?"0"+dd:dd)+"/"+(mm<10?"0"+mm:mm);};var groupHolidaysByDate=function groupHolidaysByDate(holidays){var groupedHolidays={};if(holidays&&holidays.length>0){holidays.forEach(function(item){var day=item.day,month=item.month,lunar=item.lunar,label=item.label;var key=formatDDMM(day,month);var holidaysObj=groupedHolidays[key]?_objectSpread({},groupedHolidays[key]):_objectSpread({},item);if(groupedHolidays[key]){if(holidaysObj.lunar&&!lunar){holidaysObj=_objectSpread(_objectSpread({},holidaysObj),{},{label:label,mixedLabel:label+", "+holidaysObj.label});}else if(!holidaysObj.lunar&&lunar){holidaysObj=_objectSpread(_objectSpread({},holidaysObj),{},{label:holidaysObj.lunar,mixedLabel:holidaysObj.lunar+", "+label});}}groupedHolidays[key]=holidaysObj;});}return groupedHolidays;};var sortByDate=function sortByDate(arr){if(arr&&arr.length>1){arr.sort(function(a,b){if(a.month>b.month||a.month===b.month&&a.day>b.day){return 1;}return-1;});}return groupHolidaysByDate(arr);};module.exports={WEEKDAYS:['T2','T3','T4','T5','T6','T7','CN'],WEEKDAYSFROMMOMENT:[_core.SwitchLanguage.sun,_core.SwitchLanguage.mon,_core.SwitchLanguage.tue,_core.SwitchLanguage.wed,_core.SwitchLanguage.thu,_core.SwitchLanguage.fri,_core.SwitchLanguage.sat],WEEKDAYSNAME:['Thứ 2','Thứ 3','Thứ 4','Thứ 5','Thứ 6','Thứ 7','Chủ nhật'],MONTHS:['Tháng 1','Tháng 2','Tháng 3','Tháng 4','Tháng 5','Tháng 6','Tháng 7','Tháng 8','Tháng 9','Tháng 10','Tháng 11','Tháng 12'],MAX_ROWS:7,MAX_COLUMNS:7,mapWeeKDate:function mapWeeKDate(i){var date=['',_core.SwitchLanguage.mon,_core.SwitchLanguage.tue,_core.SwitchLanguage.wed,_core.SwitchLanguage.thu,_core.SwitchLanguage.fri,_core.SwitchLanguage.sat,_core.SwitchLanguage.sun];return date[i];},mapMonth:function mapMonth(i){var month=new Map([[1,_core.SwitchLanguage.jan],[2,_core.SwitchLanguage.feb],[3,_core.SwitchLanguage.mar],[4,_core.SwitchLanguage.apr],[5,_core.SwitchLanguage.may],[6,_core.SwitchLanguage.jun],[7,_core.SwitchLanguage.jul],[8,_core.SwitchLanguage.aug],[9,_core.SwitchLanguage.sep],[10,_core.SwitchLanguage.oct],[11,_core.SwitchLanguage.nov],[12,_core.SwitchLanguage.dec]]);return month.get(i);},mapMonthShorten:function mapMonthShorten(i){var month=new Map([[1,'Jan'],[2,'Feb'],[3,'Mar'],[4,'Apr'],[5,'May'],[6,'Jun'],[7,'Jul'],[8,'Aug'],[9,'Sep'],[10,'Oct'],[11,'Nov'],[12,'Dec']]);return month.get(i);},getDaysInMonth:function getDaysInMonth(month,year){var lastDayOfMonth=new Date(year,month+1,0);return lastDayOfMonth.getDate();},getHolidaysInMonth:function getHolidaysInMonth(headerInfo){if(headerInfo){var today=(0,_moment.default)();var converter=new _LunarDateConverter.default();var startDate=(0,_moment.default)(headerInfo).startOf('month');var endDate=(0,_moment.default)(headerInfo).endOf('month');var minLunarDate=converter.SolarToLunar(Solar(startDate));var maxLunarDate=converter.SolarToLunar(Solar(endDate));var holidays=[];var currentYear=minLunarDate.lunarYear!==maxLunarDate.lunarYear?[minLunarDate.lunarYear,maxLunarDate.lunarYear]:minLunarDate.lunarYear;if(_holidayData.default.solar[headerInfo.month()+1]){_holidayData.default.solar[headerInfo.month()+1].forEach(function(date){var dateAsMoment=(0,_moment.default)({year:headerInfo.year(),month:date.month-1,date:date.day});if(dateAsMoment.isSameOrAfter(today,'date')){holidays.push(date);}});}_holidayData.default.lunar.forEach(function(item){if(currentYear instanceof Array){var solar1=converter.LunarToSolar({lunarDay:item.lunarDay,lunarMonth:item.lunarMonth,lunarYear:currentYear[0]});var solar2=converter.LunarToSolar({lunarDay:item.lunarDay,lunarMonth:item.lunarMonth,lunarYear:currentYear[1]});var solar1AsMoment=(0,_moment.default)(formatYYYYMMDD(solar1.solarDay,solar1.solarMonth,solar1.solarYear));var solar2AsMoment=(0,_moment.default)(formatYYYYMMDD(solar2.solarDay,solar2.solarMonth,solar2.solarYear));if(solar1AsMoment.isBetween(startDate,endDate)&&solar1AsMoment.isSameOrAfter(today,'date')){holidays.push(_objectSpread(_objectSpread({},item),{},{day:solar1.solarDay,month:solar1.solarMonth}));}else if(solar2AsMoment.isBetween(startDate,endDate)&&solar2AsMoment.isSameOrAfter(today,'date')){holidays.push(_objectSpread(_objectSpread({},item),{},{day:solar2.solarDay,month:solar2.solarMonth}));}}else{var solar=converter.LunarToSolar({lunarDay:item.lunarDay,lunarMonth:item.lunarMonth,lunarYear:currentYear});var solarAsMoment=(0,_moment.default)(formatYYYYMMDD(solar.solarDay,solar.solarMonth,solar.solarYear));if(solarAsMoment.isBetween(startDate,endDate)&&solarAsMoment.isSameOrAfter(today,'date')){holidays.push(_objectSpread(_objectSpread({},item),{},{day:solar.solarDay,month:solar.solarMonth}));}}});return sortByDate(holidays);}return[];},I18N_MAP:I18N_MAP};
1
+ import moment from 'moment';
2
+
3
+ import { SwitchLanguage } from '@momo-kits/core';
4
+ import LunarDateConverter from './LunarDateConverter';
5
+ import holiday from './holidayData';
6
+
7
+ const I18N_MAP = {
8
+ en: {
9
+ w: ['', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
10
+ weekday: ['', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
11
+ text: {
12
+ start: 'Start',
13
+ end: 'End',
14
+ date: 'Date',
15
+ save: 'Save',
16
+ clear: 'Reset'
17
+ },
18
+ date: 'DD / MM'
19
+ },
20
+ vi: {
21
+ w: ['', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN'],
22
+ weekday: ['', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm', 'Thứ sáu', 'Thứ bảy', 'Chủ nhật'],
23
+ text: {
24
+ start: 'Start',
25
+ end: 'End',
26
+ date: 'Date',
27
+ save: 'Save',
28
+ clear: 'Reset'
29
+ },
30
+ date: 'DD / MM'
31
+ }
32
+ };
33
+
34
+ const Solar = (momentDate) => ({
35
+ solarDay: momentDate.date(),
36
+ solarMonth: momentDate.month() + 1,
37
+ solarYear: momentDate.year()
38
+ });
39
+
40
+ const formatYYYYMMDD = (dd, mm, yyyy) => `${yyyy}-${mm < 10 ? `0${mm}` : mm}-${dd < 10 ? `0${dd}` : dd}`;
41
+
42
+ const formatDDMM = (dd, mm) => `${dd < 10 ? `0${dd}` : dd}/${mm < 10 ? `0${mm}` : mm}`;
43
+
44
+ const groupHolidaysByDate = (holidays) => {
45
+ const groupedHolidays = {};
46
+ if (holidays && holidays.length > 0) {
47
+ holidays.forEach((item) => {
48
+ const {
49
+ day, month, lunar, label
50
+ } = item;
51
+ const key = formatDDMM(day, month);
52
+ let holidaysObj = groupedHolidays[key] ? { ...groupedHolidays[key] } : { ...item };
53
+ if (groupedHolidays[key]) {
54
+ if (holidaysObj.lunar && !lunar) {
55
+ holidaysObj = {
56
+ ...holidaysObj,
57
+ label,
58
+ mixedLabel: `${label}, ${holidaysObj.label}`
59
+ };
60
+ } else if (!holidaysObj.lunar && lunar) {
61
+ holidaysObj = {
62
+ ...holidaysObj,
63
+ label: holidaysObj.lunar,
64
+ mixedLabel: `${holidaysObj.lunar}, ${label}`
65
+ };
66
+ }
67
+ }
68
+ groupedHolidays[key] = holidaysObj;
69
+ });
70
+ }
71
+
72
+ return groupedHolidays;
73
+ };
74
+
75
+ const sortByDate = (arr) => {
76
+ if (arr && arr.length > 1) {
77
+ arr.sort((a, b) => {
78
+ if (a.month > b.month || (a.month === b.month && a.day > b.day)) {
79
+ return 1;
80
+ }
81
+ return -1;
82
+ });
83
+ }
84
+
85
+ return groupHolidaysByDate(arr);
86
+ };
87
+
88
+ module.exports = {
89
+
90
+ WEEKDAYS: [
91
+ 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN',
92
+ ],
93
+
94
+ WEEKDAYSFROMMOMENT: [SwitchLanguage.sun, SwitchLanguage.mon, SwitchLanguage.tue, SwitchLanguage.wed, SwitchLanguage.thu, SwitchLanguage.fri, SwitchLanguage.sat],
95
+
96
+ WEEKDAYSNAME: [
97
+ 'Thứ 2', 'Thứ 3', 'Thứ 4', 'Thứ 5', 'Thứ 6', 'Thứ 7', 'Chủ nhật',
98
+ ],
99
+
100
+ MONTHS: [
101
+ 'Tháng 1', 'Tháng 2', 'Tháng 3', 'Tháng 4', 'Tháng 5', 'Tháng 6', 'Tháng 7',
102
+ 'Tháng 8', 'Tháng 9', 'Tháng 10', 'Tháng 11', 'Tháng 12'
103
+ ],
104
+
105
+ MAX_ROWS: 7,
106
+
107
+ MAX_COLUMNS: 7,
108
+
109
+ mapWeeKDate(i) {
110
+ const date = ['', SwitchLanguage.mon, SwitchLanguage.tue, SwitchLanguage.wed, SwitchLanguage.thu, SwitchLanguage.fri, SwitchLanguage.sat, SwitchLanguage.sun];
111
+ return date[i];
112
+ },
113
+
114
+ mapMonth(i) {
115
+ const month = new Map([
116
+ [1, SwitchLanguage.jan],
117
+ [2, SwitchLanguage.feb],
118
+ [3, SwitchLanguage.mar],
119
+ [4, SwitchLanguage.apr],
120
+ [5, SwitchLanguage.may],
121
+ [6, SwitchLanguage.jun],
122
+ [7, SwitchLanguage.jul],
123
+ [8, SwitchLanguage.aug],
124
+ [9, SwitchLanguage.sep],
125
+ [10, SwitchLanguage.oct],
126
+ [11, SwitchLanguage.nov],
127
+ [12, SwitchLanguage.dec],
128
+ ]);
129
+ return month.get(i);
130
+ },
131
+
132
+ mapMonthShorten(i) {
133
+ const month = new Map([
134
+ [1, 'Jan'],
135
+ [2, 'Feb'],
136
+ [3, 'Mar'],
137
+ [4, 'Apr'],
138
+ [5, 'May'],
139
+ [6, 'Jun'],
140
+ [7, 'Jul'],
141
+ [8, 'Aug'],
142
+ [9, 'Sep'],
143
+ [10, 'Oct'],
144
+ [11, 'Nov'],
145
+ [12, 'Dec'],
146
+ ]);
147
+ return month.get(i);
148
+ },
149
+
150
+ getDaysInMonth(month, year) {
151
+ const lastDayOfMonth = new Date(year, month + 1, 0);
152
+ return lastDayOfMonth.getDate();
153
+ },
154
+
155
+ getHolidaysInMonth(headerInfo) {
156
+ if (headerInfo) {
157
+ const today = moment();
158
+ const converter = new LunarDateConverter();
159
+ const startDate = moment(headerInfo).startOf('month');
160
+ const endDate = moment(headerInfo).endOf('month');
161
+ const minLunarDate = converter.SolarToLunar(Solar(startDate));
162
+ const maxLunarDate = converter.SolarToLunar(Solar(endDate));
163
+ const holidays = [];
164
+ const currentYear = minLunarDate.lunarYear !== maxLunarDate.lunarYear ? [minLunarDate.lunarYear, maxLunarDate.lunarYear] : minLunarDate.lunarYear;
165
+
166
+ // Handle Solar holidays
167
+ if (holiday.solar[headerInfo.month() + 1]) {
168
+ holiday.solar[headerInfo.month() + 1].forEach((date) => {
169
+ const dateAsMoment = moment({ year: headerInfo.year(), month: date.month - 1, date: date.day });
170
+ if (dateAsMoment.isSameOrAfter(today, 'date')) {
171
+ holidays.push(date);
172
+ }
173
+ });
174
+ }
175
+
176
+ holiday.lunar.forEach((item) => {
177
+ if (currentYear instanceof Array) {
178
+ const solar1 = converter.LunarToSolar({
179
+ lunarDay: item.lunarDay,
180
+ lunarMonth: item.lunarMonth,
181
+ lunarYear: currentYear[0]
182
+ });
183
+ const solar2 = converter.LunarToSolar({
184
+ lunarDay: item.lunarDay,
185
+ lunarMonth: item.lunarMonth,
186
+ lunarYear: currentYear[1]
187
+ });
188
+ const solar1AsMoment = moment(formatYYYYMMDD(solar1.solarDay, solar1.solarMonth, solar1.solarYear));
189
+ const solar2AsMoment = moment(formatYYYYMMDD(solar2.solarDay, solar2.solarMonth, solar2.solarYear));
190
+ if (solar1AsMoment.isBetween(startDate, endDate) && solar1AsMoment.isSameOrAfter(today, 'date')) {
191
+ holidays.push({
192
+ ...item,
193
+ day: solar1.solarDay,
194
+ month: solar1.solarMonth
195
+ });
196
+ } else if (solar2AsMoment.isBetween(startDate, endDate) && solar2AsMoment.isSameOrAfter(today, 'date')) {
197
+ holidays.push({
198
+ ...item,
199
+ day: solar2.solarDay,
200
+ month: solar2.solarMonth
201
+ });
202
+ }
203
+ } else {
204
+ const solar = converter.LunarToSolar({
205
+ lunarDay: item.lunarDay,
206
+ lunarMonth: item.lunarMonth,
207
+ lunarYear: currentYear
208
+ });
209
+ const solarAsMoment = moment(formatYYYYMMDD(solar.solarDay, solar.solarMonth, solar.solarYear));
210
+ if (solarAsMoment.isBetween(startDate, endDate) && solarAsMoment.isSameOrAfter(today, 'date')) {
211
+ holidays.push({
212
+ ...item,
213
+ day: solar.solarDay,
214
+ month: solar.solarMonth
215
+ });
216
+ }
217
+ }
218
+ });
219
+
220
+ return sortByDate(holidays);
221
+ }
222
+ return [];
223
+ },
224
+ I18N_MAP,
225
+ };
@@ -0,0 +1,154 @@
1
+ import React, { Component, } from 'react';
2
+ import { TouchableOpacity, View } from 'react-native';
3
+ import PropTypes from 'prop-types';
4
+ import { Text } from '@momo-kits/core';
5
+ import styles from './styles';
6
+
7
+ export default class Day extends Component {
8
+ processMinDate() {
9
+ const { minDate } = this.props;
10
+ if (minDate) {
11
+ minDate.setHours(0, 0, 0, 0);
12
+ if (this.date < minDate) {
13
+ this.disableTouch = true;
14
+ }
15
+ }
16
+ }
17
+
18
+ processMaxDate() {
19
+ const { maxDate } = this.props;
20
+ if (maxDate) {
21
+ maxDate.setHours(0, 0, 0, 0);
22
+ if (this.date > maxDate) {
23
+ this.disableTouch = true;
24
+ }
25
+ }
26
+ }
27
+
28
+ processDoubleDate() {
29
+ const {
30
+ mode, otherMonth, firstDate, secondDate, tabSelected
31
+ } = this.props;
32
+ const { date } = this;
33
+ if (mode === 'doubleDate' && !otherMonth) {
34
+ if (firstDate && tabSelected === 1) {
35
+ firstDate.setHours(0, 0, 0, 0);
36
+ if (date < firstDate) {
37
+ this.disableTouch = true;
38
+ this.styleDouble = {};
39
+ } else if (date.getTime() === firstDate.getTime()) {
40
+ this.colorCanTouch = '#2eb3e8';
41
+ this.colorText = 'white';
42
+ this.styleDouble = {};
43
+ }
44
+ }
45
+ if (secondDate && firstDate) {
46
+ secondDate.setHours(0, 0, 0, 0);
47
+ if (date > firstDate && date < secondDate) {
48
+ this.colorCanTouch = '#90d6f3';
49
+
50
+ this.styleDouble = styles.styleBetween;
51
+
52
+ this.colorText = 'white';
53
+ }
54
+ if (secondDate.getTime() !== firstDate.getTime()) {
55
+ if (date.getTime() === firstDate.getTime()) {
56
+ this.colorCanTouch = '#2eb3e8';
57
+ this.colorText = 'white';
58
+ this.styleDouble = styles.styleFirstDate;
59
+ }
60
+ if (date.getTime() === secondDate.getTime()) {
61
+ this.styleDouble = styles.styleSecondDate;
62
+ this.colorCanTouch = '#2eb3e8';
63
+ this.colorText = 'white';
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ processSelected() {
71
+ const { selected } = this.props;
72
+ if (selected && !this.disableTouch) {
73
+ this.colorCanTouch = '#2eb3e8';
74
+ this.colorText = 'white';
75
+ }
76
+ }
77
+
78
+ processDateNow() {
79
+ const { selected } = this.props;
80
+ if (!selected && this.date.getTime() === this.dateNow.getTime()) {
81
+ this.colorCanTouch = '#8F8E94';
82
+ this.colorText = 'white';
83
+ }
84
+ }
85
+
86
+ processOtherMonth() {
87
+ const { otherMonth } = this.props;
88
+ if (otherMonth) {
89
+ this.colorTextDisable = 'white';
90
+ }
91
+ }
92
+
93
+ processRender() {
94
+ this.processMinDate();
95
+ this.processMaxDate();
96
+ // this.processDateNow()
97
+ this.processDoubleDate();
98
+ this.processSelected();
99
+ this.processOtherMonth();
100
+ }
101
+
102
+ render() {
103
+ const {
104
+ day, month, year, otherMonth, onDayChange
105
+ } = this.props;
106
+ this.colorCanTouch = 'white';
107
+ this.colorText = '#393939';
108
+ this.colorTextDisable = '#DADADA';
109
+ this.styleDouble = {};
110
+ this.disableTouch = false;
111
+ this.dateNow = new Date();
112
+ this.dateNow.setHours(0, 0, 0, 0);
113
+ this.date = new Date(year, month, day);
114
+ this.date.setHours(0, 0, 0, 0);
115
+ this.processRender();
116
+ return (
117
+
118
+ <View style={styles.dayWrapper}>
119
+ <View style={this.styleDouble} />
120
+ {
121
+ this.disableTouch || otherMonth
122
+ ? (
123
+ <View style={styles.dayButton}>
124
+ <Text.Title style={[styles.dayLabel, { color: this.colorTextDisable }]}>
125
+ {day}
126
+ </Text.Title>
127
+ </View>
128
+ )
129
+ : (
130
+ <View style={[styles.dayButtonSelected, { backgroundColor: this.colorCanTouch }]}>
131
+ <TouchableOpacity
132
+ style={styles.dayButton}
133
+ onPress={() => onDayChange(day, month, year)}
134
+ >
135
+ <Text.Title style={[styles.dayLabel, { color: this.colorText }]}>
136
+ {day}
137
+ </Text.Title>
138
+ </TouchableOpacity>
139
+
140
+ </View>
141
+ )
142
+
143
+ }
144
+ </View>
145
+ );
146
+ }
147
+ }
148
+ Day.propTypes = {
149
+ day: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
150
+ month: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
151
+ year: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
152
+ otherMonth: PropTypes.bool,
153
+ onDayChange: PropTypes.func,
154
+ };
@@ -0,0 +1,203 @@
1
+ import React, { Component, } from 'react';
2
+ import { View, } from 'react-native';
3
+ import styles from './styles';
4
+ import { getDaysInMonth, MAX_COLUMNS, MAX_ROWS, } from './util';
5
+ import Day from './Day';
6
+
7
+ export default class Days extends Component {
8
+ constructor(props) {
9
+ super(props);
10
+ this.state = {
11
+ selectedDay: 0,
12
+ selectedMonth: 0,
13
+ selectedYear: 0,
14
+ };
15
+ this.selectedDate = null;
16
+ }
17
+
18
+ componentDidMount() {
19
+ const { selectedDate } = this.props;
20
+ if (selectedDate) {
21
+ const temp = selectedDate;
22
+ if (typeof temp.getDate === 'function') {
23
+ this.selectedDate = temp;
24
+ } else {
25
+ this.selectedDate = new Date(temp);
26
+ }
27
+ this.updateSelectedStates(
28
+ this.selectedDate.getDate(),
29
+ this.selectedDate.getMonth(),
30
+ this.selectedDate.getFullYear(),
31
+ );
32
+ }
33
+ }
34
+
35
+ updateSelectedStates = (day, month, year) => {
36
+ const { onDayChange } = this.props;
37
+ // const monthTmp = month + 1;
38
+ this.setState({
39
+ selectedDay: day,
40
+ selectedMonth: month,
41
+ selectedYear: year,
42
+ });
43
+ if (onDayChange) {
44
+ onDayChange(day, month, year);
45
+ }
46
+ }
47
+
48
+ onPressDay = (day, month, year) => {
49
+ const { minDate, maxDate } = this.props;
50
+ const selectDate = new Date(year, month, day);
51
+ selectDate.setHours(0, 0, 0, 0);
52
+ if (minDate) {
53
+ minDate.setHours(0, 0, 0, 0);
54
+ if (selectDate < minDate) {
55
+ return;
56
+ }
57
+ }
58
+
59
+ if (maxDate) {
60
+ maxDate.setHours(0, 0, 0, 0);
61
+ if (selectDate > maxDate) {
62
+ return;
63
+ }
64
+ }
65
+ this.updateSelectedStates(day, month, year);
66
+ }
67
+
68
+ getCalendarDays = () => {
69
+ const {
70
+ month, year, mode, minDate, maxDate, firstDate, secondDate, tabSelected
71
+ } = this.props;
72
+ const { selectedMonth, selectedDay, selectedYear } = this.state;
73
+ let columns;
74
+ const matrix = [];
75
+ let i;
76
+ let j;
77
+ let currentDay = 0;
78
+ const thisMonthFirstDay = new Date(year, month, 1);
79
+ let slotsAccumulator = 1;
80
+
81
+ let goNextMonth = false;
82
+ for (i = 0; i < MAX_ROWS; i += 1) { // Week rows
83
+ columns = [];
84
+ if (goNextMonth) { break; }
85
+ for (j = 0; j < MAX_COLUMNS; j += 1) { // Day columns
86
+ // HungHC: getDay() Sunday is 0, Monday is 1, and so on.
87
+ let tmp = thisMonthFirstDay.getDay();
88
+ if (tmp === 0) { tmp = 7; }
89
+ if (slotsAccumulator >= tmp) {
90
+ if (currentDay < getDaysInMonth(month, year)) {
91
+ const day = currentDay + 1;
92
+ const selected = (selectedDay === day
93
+ && selectedMonth === month
94
+ && selectedYear === year);
95
+ const date = Date(year, month, day);
96
+
97
+ columns.push(<Day
98
+ mode={mode}
99
+ key={j.toString()}
100
+ column={j}
101
+ day={day}
102
+ month={month}
103
+ year={year}
104
+ selected={selected}
105
+ date={date}
106
+ minDate={minDate}
107
+ maxDate={maxDate}
108
+ firstDate={firstDate}
109
+ secondDate={secondDate}
110
+ tabSelected={tabSelected}
111
+
112
+ otherMonth={false}
113
+ onDayChange={this.onPressDay}
114
+ />);
115
+ currentDay += 1;
116
+ } else {
117
+ // HungHC: show next month
118
+ goNextMonth = true;
119
+ if (j === 0) {
120
+ break;
121
+ }
122
+
123
+ let nextMonth = month + 1;
124
+ const day = currentDay + 1 - getDaysInMonth(month, year);
125
+ let yearTmp = year;
126
+ if (nextMonth > 11) {
127
+ nextMonth = 0;
128
+ yearTmp = year + 1;
129
+ }
130
+ const date = Date(yearTmp, nextMonth, day);
131
+ const selected = (selectedDay === day
132
+ && selectedMonth === nextMonth
133
+ && selectedYear === yearTmp);
134
+ columns.push(<Day
135
+ mode={mode}
136
+ key={j.toString()}
137
+ column={j}
138
+ day={day}
139
+ month={nextMonth}
140
+ year={yearTmp}
141
+ selected={selected}
142
+ date={date}
143
+ minDate={minDate}
144
+ maxDate={maxDate}
145
+ firstDate={firstDate}
146
+ secondDate={secondDate}
147
+ tabSelected={tabSelected}
148
+ otherMonth
149
+ onDayChange={this.onPressDay}
150
+ />);
151
+ currentDay += 1;
152
+ }
153
+ } else {
154
+ // HungHC: show prev month
155
+ let prevMonth = month - 1;
156
+ let yearTmp = year;
157
+ if (prevMonth < 0) {
158
+ prevMonth = 11;
159
+ yearTmp = year - 1;
160
+ }
161
+ const daysPrev = getDaysInMonth(prevMonth, yearTmp);
162
+ let tmpDay = thisMonthFirstDay.getDay();
163
+ if (tmpDay === 0) { tmpDay = 7; }
164
+ const delta = (slotsAccumulator - tmpDay + 1);
165
+ const day = daysPrev + delta;
166
+
167
+ const selected = (selectedDay === day
168
+ && selectedMonth === prevMonth
169
+ && selectedYear === yearTmp);
170
+
171
+ const date = Date(yearTmp, prevMonth, day);
172
+ columns.push(<Day
173
+ mode={mode}
174
+ key={j.toString()}
175
+ column={j}
176
+ day={day}
177
+ month={prevMonth}
178
+ year={yearTmp}
179
+ selected={selected}
180
+ date={date}
181
+ minDate={minDate}
182
+ maxDate={maxDate}
183
+ firstDate={firstDate}
184
+ secondDate={secondDate}
185
+ tabSelected={tabSelected}
186
+ otherMonth
187
+ onDayChange={this.onPressDay}
188
+ />);
189
+ }
190
+
191
+ slotsAccumulator += 1;
192
+ }
193
+ matrix[i] = [];
194
+ matrix[i].push(<View key={i.toString()} style={styles.weekRow}>{columns}</View>);
195
+ }
196
+
197
+ return matrix;
198
+ }
199
+
200
+ render() {
201
+ return <View style={styles.daysWrapper}>{ this.getCalendarDays()}</View>;
202
+ }
203
+ }