简体   繁体   English

在SQL PHP中重复日历事件

[英]Repeating calendar events in SQL PHP

I have a loop that loops through all the days in a given month that a person can create events from a start date/time and specify an ending date/time. 我有一个循环,循环遍历给定月份中的所有天,一个人可以从开始日期/时间创建事件并指定结束日期/时间。 I am incorporating where events can be repeated every xx days, xx months or xx years. 我将合并的事件每隔xx天,xx个月或xx年重复一次。

I have no idea how to match up the current day in the loop to see if the repeating has started. 我不知道如何在循环中匹配当前日期以查看重复是否已经开始。 Say I had the event "Pickup Silver" that was 3 days long. 假设我参加了为期3天的“ Pickup Silver”活动。 I want this to happen every 7 days starting on the 2nd. 我希望从第二天开始每7天发生一次。 The calendar should show this event every 7 days from the starting date/time. 日历应从开始日期/时间起每7天显示一次此事件。 Starting on the days 2,9,16,30 and so on. 从第2、9、16、30天开始,依此类推。

#Loop starts and math calulates the current unix start of each day
##The SQL QUERY to lookup if there are any events starting or ending on this day 
#$SQL =" 
#SELECT
# Name as OutputTitle,
# ID
# FROM
#safe_calendar
#WHERE
#AutherID = '[AccountID]'
#AND
#AutherTable = '[TableName]'
#AND
#(UnixFrom - 86400) <  [UnixThisDay] 
#AND
#UnixEnd >= [UnixThisDay]
#";

I would suggest taking a look at iCalendar RRULEs . 我建议您看一下iCalendar规则 If you are doing a pretty basic recurrence pattern, then don't bother with the bulk of this because it's quite large but very comprehensive. 如果您正在做一个非常基本的重复模式,那么就不用多管它了,因为它很大,但是很全面。 This will at least give you a good idea, that is a standard, on how to structure your data and what you need to store. 这至少会给您一个关于如何构造数据以及需要存储什么的好主意,这是一个标准。 Specifically, in your case, it sounds like you'd need to store the start and end date of the recurrence as well as the start date and length of the event. 具体来说,您可能需要存储重复发生的开始和结束日期以及事件的开始日期和时长。 From that, you can deduce if your current day intersects with a recurrence day. 据此,您可以推断出当前日期是否与重复日期相交。

Something to keep in mind is calendar calculations are actually quite difficult. 要记住的一点是,日历计算实际上非常困难。 You need to account for timezone differences, daylight savings (not only on what days but how to deal with the extra or missing hour), leap years, etc. Even what appears to be simple can become quite complex if you factor in all the outlier situations. 您需要考虑时区差异,夏令时(不仅在哪几天,以及如何处理多余或丢失的小时数),leap年等。如果将所有异常因素都考虑在内,那么即使看起来很简单的事情也可能变得非常复杂。情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM