全天活动日历宝石
我正在使用下面的内容设置一个事件,以使用icalendar gem 导出到ical。
@calendar = Icalendar::Calendar.new
event = Icalendar::Event.new
event.dtstart = ev.start_at.strftime("%Y%m%d")
event.dtend = ev.end_at.strftime("%Y%m%d")
event.summary = ev.summary
@calendar.add
为了全天举办一个活动,它需要看起来像这样:
DTSTART;VALUE=DATE:20101117
DTEND;VALUE=DATE:20101119
现在我正在使用
event.dtstart = "$VALUE=DATE:"+ev.start_at.strftime("%Y%m%d")"
This will 输出
DTSTART:$VALUE=DATE:20101117
,然后我将所有“:$”替换为“;”有
@allday = @calendar.to_ical.gsub(":$", ";")
没有更直接的方法将日期保存为全天?
I am using the below to setup an event to export to ical with the icalendar gem.
@calendar = Icalendar::Calendar.new
event = Icalendar::Event.new
event.dtstart = ev.start_at.strftime("%Y%m%d")
event.dtend = ev.end_at.strftime("%Y%m%d")
event.summary = ev.summary
@calendar.add
In order to make an event all day it needs to look like this:
DTSTART;VALUE=DATE:20101117
DTEND;VALUE=DATE:20101119
Right now I am using
event.dtstart = "$VALUE=DATE:"+ev.start_at.strftime("%Y%m%d")"
This will output
DTSTART:$VALUE=DATE:20101117
and then I replace all ":$" with ";" with
@allday = @calendar.to_ical.gsub(":$", ";")
Is there a more direct way to save dates as all day?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对此进行了研究并找到了一种方法。您可以以键值对的形式为事件日期分配属性。所以你可以像这样分配 VALUE 属性:
现在是有趣的部分。给定一个日历,您可以创建一个事件并传入一个块,该块用其属性初始化日期:
I played around with this and figured out one way. You can assign properties to the event dates, in the form of key-value pairs. so you could assign the VALUE property like so:
Now the fun part. Given a calendar you can create an event and pass in a block which initializes the date with its properties:
所以这个线程看起来很旧(并且没有解决最新版本的icalendar gem - 2.3.0 的问题)。我最近不得不以 ics 格式创建“全天”日历事件。我发现这是一个更好的解决方案(并且似乎按照您期望日历处理它的方式工作) - 请参阅下面的代码片段 上面的
代码产生以下输出:
请注意,日期没有关联的时间与它。先前回复中的代码当前生成时间。我必须深入研究icalendar的源代码才能找到这个解决方案。
我希望这对其他人有帮助。
干杯!
So this thread seems quite old (and did not solve the problem with the most recent version of the icalendar gem - 2.3.0). I've recently had to create "all day" calendar events in ics format. I've found this to be a much better solution (and seems to work the way you'd expect calendars to handle it) - see the snippet below
The above code produces the following output:
Note that the Date does not have a time associated with it. The code in the prior reply currently produces the time. I had to dig into the source code for icalendar to figure out this solution.
I hope this helps someone else.
Cheers!