Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{text: '继续', style: 'warning', onPress: async () => {
// 时间跨度超过 5 年,就不能获取到了...
const startDate = moment().subtract(4, 'years').toISOString();
const endDate = moment().add(1, 'years').toISOString();
const allEvents = await RNCalendarEvents.fetchAllEvents(startDate, endDate);
await allEvents.forEach(async item => {
console.log(item);
if (item.notes === '由应用UESTC创建') {
await RNCalendarEvents.removeEvent(item.id, {
futureEvents: true
});
}
});
await this.props.rootStore.UserStore.toast('success', '🎉 已从系统日历中删除所有课程');
await this.props.rootStore.UserStore.clearToast();
}
}
async removeExist() {
const startDate = moment(`${this.state.startDate}`, 'YYYY-MM-DD').toISOString();
const endDate = moment(`${this.state.startDate}`, 'YYYY-MM-DD').add(6, 'months').toISOString();
const allEvents = await RNCalendarEvents.fetchAllEvents(startDate, endDate);
await allEvents.forEach(async item => {
if (item.notes === '由应用UESTC创建') {
await RNCalendarEvents.removeEvent(item.id, {
futureEvents: true
});
}
});
};
.then(accessGranted => {
if (accessGranted) {
const startDate = new Date();
const endDate = new Date();
startDate.setDate(startDate.getDate() + FETCH_START_DAYS);
endDate.setDate(endDate.getDate() + FETCH_END_DAYS);
RNCalendarEvents.fetchAllEvents(
startDate.getTime(),
endDate.getTime(),
[])
.then(_updateCalendarEntries.bind(store))
.catch(error =>
logger.error('Error fetching calendar.', error));
} else {
logger.warn('Calendar access not granted.');
}
})
.catch(reason => logger.error('Error accessing calendar.', reason));