我正在根据指示其重复发生的原始约会来生成重复的日历约会。我当前使用的数据库是SQL Server。 Web应用程序的后端是ASP.Net Core 2.0 MVC。
我正在使用对控制器的Ajax调用来从数据库中检索数据。返回数据后,我将遍历数据并根据是否重复出现对约会进行排序。如果约会具有重复性,我会将约会传递给一个函数,然后该函数将数据放入可用的JavaScript值中。这时,将数据放入RRule JS对象,该对象应根据规则的构造方式生成重复日期。
当我最初发现iPhone没有显示日历时,我想知道错误出在哪里,我添加了一些代码
window.addEventListener("error", handleError, true);
function handleError(evt) {
if (evt.message) { // Chrome sometimes provides this
alert("error: " + evt.message + " at linenumber: " + evt.lineno + " of file: " + evt.filename);
} else {
alert("error: " + evt.type + " from element: " + (evt.srcElement || evt.target));
}
}
这打印了我正在出现的错误,以便我可以获得更多信息。错误为“错误:错误:无效选项:dtstart在文件http://.../.../rrule/dist/es5/rrule-tz.min.js的行号1”
这似乎没有太大帮助。
我尝试使用remotedebug-ios-webkit-adapter 基于这两个网站 1)https://github.com/RemoteDebug/remotedebug-ios-webkit-adapter
2)https://washamdev.com/debug-a-website-in-ios-safari-on-windows/
由于某种原因,这似乎无法向我显示比我已有的更多信息。
这是我编写的用于处理RRule的功能,该功能然后生成重复的开始日期和时间。
功能规则(事件){
if (event.isRemoved) {
return;
}
var dayCheck = []; // holds the values of the days of the week for the recurrence
var dateTime = event.recurrance.occuranceStartTime.split('T'); // this will be used to get the end dateTime of the appointment
var startDateTime = event.startDateTime;
var dt = new Date();
var d0 = new Date(Date.UTC(dateTime));
var d1 = new Date(dateTime);
var d2 = new Date(startDateTime);
var infragisticsDaysEnumValue = event.recurrance.patternDaysOfWeek;
if (infragisticsDaysEnumValue == 127) { //is everyday.
dayCheck.push(0);
dayCheck.push(1);
dayCheck.push(2);
dayCheck.push(3);
dayCheck.push(4);
dayCheck.push(5);
dayCheck.push(6);
} else {
if (infragisticsDaysEnumValue >= 64) { // is Saturday or contains Saturday
dayCheck.push(5);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 64;
}
if (infragisticsDaysEnumValue >= 32) { // is Friday or contains Friday
dayCheck.push(4);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 32;
}
if (infragisticsDaysEnumValue >= 16) { // is Thursday or contains Thursday
dayCheck.push(3);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 16;
}
if (infragisticsDaysEnumValue >= 8) { // is Wednesday or contains Wednesday
dayCheck.push(2);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 8;
}
if (infragisticsDaysEnumValue >= 4) { // is Tuesday or contains Tuesday
dayCheck.push(1);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 4;
}
if (infragisticsDaysEnumValue >= 2) { // is Monday or contains Monday
dayCheck.push(0);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 2;
}
if (infragisticsDaysEnumValue >= 1) { // is Sunday or contains Sunday
dayCheck.push(6);
infragisticsDaysEnumValue = infragisticsDaysEnumValue - 1;
}
}
if (d2 > d1) { // this checks to see if the startDate of the appointments is later then the occurrence StartDateTime and sets the start of the recurrence generation accordingly.
dt = d2;
}
else {
dt = d1;
}
var thisYear = new Date();
//var oneYearAgo = new Date(thisYear.getFullYear() - 1);
var oneYearAgo = new Date((thisYear.getFullYear() - 1), thisYear.getMonth(), thisYear.getDate());
var number = getNumberOfAppointments(event, dayCheck);
if (dt < oneYearAgo) {
switch (event.recurrance.patternFrequency) {
case 0: //Daily
var check = dt.toISOString().split('T');
var first = check[0].split('-');
var second = check[1].split(':');
var dStart = `${first[0]}${first[1]}${first[2]}T${second[0]}${second[1]}00Z`;
var checkTwo = oneYearAgo.toISOString().split('T');
var firstTwo = checkTwo[0].split('-');
var secondTwo = checkTwo[1].split(':');
var dEnd = `${firstTwo[0]}${firstTwo[1]}${firstTwo[2]}T${secondTwo[0]}${secondTwo[1]}00Z`;
var rule = rrule.RRule.fromString(`DTSTART:${dStart};FREQ=${rrule.RRule.DAILY};INTERVAL=${event.recurrance.patternInterval};UNTIL=${dEnd};`);
//var rule = new rrule.RRule({
// freq: rrule.RRule.DAILY,
// interval: parseInt(event.recurrance.patternInterval),
// //count: numberOfOccurences,
// dtstart: dt,
// until: oneYearAgo
//});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
dt = recurrence[rule.length - 1];
break;
case 1: //Weekly
dt.setYear(oneYearAgo.getFullYear() - 1);
break;
case 2: //Monthly
if (event.recurrance.patternInterval == 1) { // The appointment is once a month
dt.setYear(oneYearAgo.getFullYear());
}
else { // if the appointment isn't once a month but rather once every two or more months
var check = dt.toISOString().split('T');
var first = check[0].split('-');
var second = check[1].split(':');
var dStart = `${first[0]}${first[1]}${first[2]}T${second[0]}${second[1]}00Z`;
var checkTwo = oneYearAgo.toISOString().split('T');
var firstTwo = checkTwo[0].split('-');
var secondTwo = checkTwo[1].split(':');
var dEnd = `${firstTwo[0]}${firstTwo[1]}${firstTwo[2]}T${secondTwo[0]}${secondTwo[1]}00Z`;
var sven = "2019-06-08T08:00:00"
var steven = sven.getUTCHours();
//var rule = rrule.RRule.fromString(`DTSTART:${dStart};FREQ:${rrule.RRule.MONTHLY};interval:${event.recurrance.patternInterval};bysetpos:${event.recurrance.patternOccuranceOfDayInMonth};byweekday:${dayCheck};UNTIL:${dEnd};`);
//rule.options(`FREQ:${rrule.RRule.MONTHLY};interval:${event.recurrance.patternInterval};bysetpos:${event.recurrance.patternOccuranceOfDayInMonth};byweekday:${dayCheck};UNTIL:${dEnd};`)
var rule = new rrule.RRule({
freq: rrule.RRule.MONTHLY,
interval: parseInt(event.recurrance.patternInterval),
bysetpos: event.recurrance.patternOccuranceOfDayInMonth,
byweekday: dayCheck,
//count: numberOfOccurrences,
dtstart: dStart,
until: dEnd
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
dt = recurrence[recurrence.length - 1];
}
break;
case 3: //Yearly
dt.setYear(oneYearAgo.getFullYear()-1);
break;
}
}
if (event.recurrance.patternFrequency == 3) { //yearly
if (event.recurrance.patternType == 0) { // the recurrance happens on the nth day of the ith month of every year
var rule = new rrule.RRule({
freq: rrule.RRule.YEARLY, //the frequency, so in this case yearly
//interval: parseInt(event.recurrance.patternInterval), // the spacing in between the recurrances
bymonth: event.recurrance.patternMonthOfYear, //the month that the recurrance happens in
bymonthday: event.recurrance.patternDayOfMonth, // the number of the day of the month that the recurrance happens on
count: number, // number of times the recurrance happends
dtstart: dt // the day that the recurrance starts happening.
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
return recurrence; // returns either a list or an array not sure which to the method that called it.
}
if (event.recurrance.patternType == 1) { // the recurrance happens on the nth occurance of the ith weekday of the uth month
var rule = new rrule.RRule({
freq: rrule.RRule.YEARLY, //the frequency, so in this case yearly
//interval: parseInt(event.recurrance.patternInterval), // the spacing in between the recurrances
bysetpos: event.recurrance.patternOccuranceOfDayInMonth,
bymonth: event.recurrance.patternMonthOfYear, //the month that the recurrance happens in
byweekday: dayCheck, // the weekday so like tuesday or something
count: number, // number of times the recurrance happends
dtstart: dt // the day that the recurrance starts happening.
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
return recurrence; // returns either a list or an array not sure which to the method that called it.
}
}
if (event.recurrance.patternFrequency == 2) { // monthly
//if recurrence pattern type is 1 its the nth tuesday(can be any day) of the month
if (event.recurrance.patternType == 1) {
var check = dt.toISOString().split('T');
var first = check[0].split('-');
var second = check[1].split(':');
var dStart = `${first[0]}${first[1]}${first[2]}T${second[0]}${second[1]}00z`;
//var rule = rrule.RRule.fromString(`DTSTART:${dStart}\nRRULE: FREQ=MONTHLY;INTERVAL=${event.recurrance.patternInterval};bysetpos=${event.recurrance.patternOccuranceOfDayInMonth};byweekday=${dayCheck};count=${number};`);
var rule = new rrule.RRule({
freq: rrule.RRule.MONTHLY,
interval: parseInt(event.recurrance.patternInterval),
bysetpos: event.recurrance.patternOccuranceOfDayInMonth,
byweekday: dayCheck,
count: number,
dtstart: dStart
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
return recurrence; // returns either a list or an array not sure which to the method that called it.
}
//if recurrence pattern type is 0 its the day of the month so like the 16 of every month.
if (event.recurrance.patternType == 0) {
var check = dt.toISOString().split('T');
var first = check[0].split('-');
var second = check[1].split(':');
//var dStart = `${first[0]}${first[1]}${first[2]}T${second[0]}${second[1]}00Z`;
var dStart = `${first[0]}${first[1]}${first[2]}T${second[0]}${second[1]}00z`;
//var rule = rrule.RRule.fromString(`DTSTART:${dStart};FREQ=${rrule.RRule.MONTHLY};INTERVAL=${event.recurrance.patternInterval};bymonthday=${event.recurrance.patternDayOfMonth};count=${number};`);
var rule = new rrule.RRule({
freq: rrule.RRule.MONTHLY,
interval: parseInt(event.recurrance.patternInterval),
bymonthday: 16,
count: number,
dtstart: dStart
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
return recurrence; // returns either a list or an array not sure which to the method that called it.
}
}
if (event.recurrance.patternFrequency == 1) { // weekly
var check = dt.toISOString().split('T');
var first = check[0].split('-');
var second = check[1].split(':');
var dStart = `${first[0]}${first[1]}${first[2]}T${second[0]}${second[1]}00z`;
var steve = dt.getUTCHours();
//var rule = rrule.RRule.fromString(`DTSTART:${dStart};FREQ=${rrule.RRule.WEEKLY};INTERVAL=${event.recurrance.patternInterval};byweekday=${dayCheck};count=${number};`);
var rule = new rrule.RRule({
freq: rrule.RRule.WEEKLY,
interval: parseInt(event.recurrance.patternInterval),
byweekday: dayCheck,
count:number,
dtstart: dStart
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
return recurrence; // returns either a list or an array not sure which to the method that called it.
}
if (event.recurrance.patternFrequency == 0) { // daily
var rule = new rrule.RRule({
freq: rrule.RRule.DAILY,
interval: parseInt(event.recurrance.patternInterval),
count: number,
dtstart: dt
});
var recurrence = rule.all(); // generated the desired amount of recurrence start DateTimes
return recurrence; // returns either a list or an array not sure which to the method that called it.
}
}
我从中收到错误的RRule库中的代码是
function initializeOptions(options) {
var invalid = [];
var keys = Object.keys(options);
var initializedOptions = {};
// Shallow copy for options and origOptions and check for invalid
keys.forEach(function (key) {
var value = options[key];
initializedOptions[key] = value;
if (!Object(helpers["c" /* includes */])(rrule_defaultKeys, key))
invalid.push(key);
if (src_dateutil.isDate(value) && !src_dateutil.isValidDate(value))
invalid.push(key);
});
if (invalid.length) {
throw new Error('Invalid options: ' + invalid.join(', '));
}
return initializedOptions;
}
我没有写这个,我是直接从rrule-tz.js文件中得到的。
当我在Windows上运行程序以及在Android设备上测试日历时,所有这些都可以正常工作。我遇到的问题是,当我在iPhone上测试日历时,出现错误
“错误:错误:无效的选项:dtstart从文件http://.../.../rrule/dist/es5/rrule-tz.min.js的亚麻编号1开始”
或者当我使用未缩小的js文件执行此操作时,会出现此错误
“错误:错误:无效的选项:dtstart在文件的行号938 http://.../.../rrule/dist/es5/rrule-tz.js”
这使我感到困惑,因为错误仅发生在IOS上。
理想情况下,我想知道在IOS和Android / Windows上处理日期的方式是否有所不同。