Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3123|回复: 6
打印 上一主题 下一主题

iCalendar

[复制链接]

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
跳转到指定楼层
楼主
发表于 2018-4-27 11:29:12 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 java 于 2018-5-7 15:11 编辑

iCalendar,简称“iCal”,是“日历数据交换”的标准(RFC 2445),该标准提供了一种公共的数据格式用于存储关于日历方面的信息,比如事件、约定、待办事项等。它不仅允许用户通过电子邮件发送会议或者待办事件等,也允许独立使用,而不局限于某种传输协议。

iCal又称iCalendar,是一种标准的互联网日历格式,让用户能够在各种计算机和各种程序之间创建和共享电子日历。
  随着这种格式日益普及,许多公司都选择了使用iCal标准。苹果公司的iCal(一种在Mac OS X操作系统上运行的个人日历应用程序)就是使用该格式的众多程序之一。这类程序还有Mozilla Sunbird和Microsoft Outlook。
iCalendar是“日历数据交换”的标准(RFC 2445)。 此标准有时指的是“iCal”,即苹果公司的出品的一款同名日历软件(见iCal),这个软件也是此标准的一种实现方式。

iCalendar允许用户通过电子邮件的方式发送“会议请求”或“任务”。收信人使用支持iCalendar邮件客户端,便可以很方便地回应发件人,接受请求或另外提议一个新的会议时间。

iCalendar已得到很多产品的支持。通常情况下,iCalendar数据是使用电子邮件交换,但它也可以独立使用,而不局限於某种传输协议。例如,可以通过WebDav服务器或SyncML来进行共享与修改。简单的网页服务器(只使用HTTP协议)也常常被用来分发公共事件的iCalendar数据,或发布个人的时间谋划安排。发布者可以使用hCalendar把iCalendar数据嵌入到网页中。(hCalendar是一种通过(X)HTML来表现iCalendar的微格式)

vCalendar
vCalendar也是一种日历数据交换格式,乃iCalendar的前身,为因特网邮件联盟(IMC)所发布。



iCalendar是“日历数据交换”的标准(RFC 2445)。 此标准有时指的是“iCal”,即苹果公司的出品的一款同名日历软件(见iCal),这个软件也是此标准的一种实现方式。


软件名称icalendar开发商苹果公司软件平台WebDav服务器或SyncML软件版本RFC 5545
iCalendar允许用户通过电子邮件的方式发送“会议请求”或“任务”。收信人使用支持iCalendar邮件客户端,便可以很方便地回应发件人,接受请求或另外提议一个新的会议时间。
iCalendar已得到很多产品的支持。通常情况下,iCalendar数据是使用电子邮件交换,但它也可以独立使用,而不局限于某种传输协议。例如,可以通过WebDav服务器或SyncML来进行共享与修改。简单的网页服务器(只使用HTTP协议)也常常被用来分发公共事件的iCalendar数据,或发布个人的时间谋划安排。发布者可以使用hCalendar把iCalendar数据嵌入到网页中。(hCalendar是一种通过(X)HTML来表现iCalendar的微格式
在2009年9月,RFC 5545替换 RFC 2445 作为最新的标准。

https://en.wikipedia.org/wiki/ICalendar

iCalendar 日历文件格式 扩展名: .ics       the file format is specified in a proposed internet standard (RFC 5545) for calendar data exchange.
iCalendar is used and supported by a large number of products, including Google Calendar, Apple Calendar (formerly iCal), IBM Notes (formerly Lotus Notes),[2] Yahoo! Calendar, Evolution (software), eM Client, Lightning extension for Mozilla Thunderbird and SeaMonkey, and partially by Microsoft Outlook and Novell GroupWise.

iCalendar is heavily based on the earlier vCalendar by the Internet Mail Consortium (IMC). iCalendar data files are plain text files with the extension .ics or .ifb (for files containing availability information only). RFC 5545replaced RFC 2445 in September 2009 and now defines the standard.


iCal 是苹果电脑公司出品的一个日程管理应用程序.





The first line must be BEGIN:VCALENDAR, and the last line must be END:VCALENDAR; the contents between these lines is called the "icalbody".
The second line VERSION:2.0 indicates that the data is in iCalendar format. VERSION:1.0 was used to specify that data is in the old vCalendar format.
The body of the iCalendar object (the icalbody) is made up of a list of calendar properties and one or more calendar components. The calendar properties apply to the entire calendar. The calendar components are several calendar properties which create a calendar schematic (design). For example, the calendar component can specify an event, a to-do list, a journal entry, time zone information, or free/busy time information, or an alarm. Empty lines are not allowed in some versions of usage (Google calendar).
Here is a simple example of an iCalendar object, "Bastille Day Party" event which occurs July 14, 1997 17:00 (UTC) through July 15, 1997 03:59:59 (UTC):

  1. BEGIN:VCALENDAR
  2. VERSION:2.0
  3. PRODID:-//hacksw/handcal//NONSGML v1.0//EN
  4. BEGIN:VEVENT
  5. UID:uid1@example.com
  6. DTSTAMP:19970714T170000Z
  7. ORGANIZER:CN=John Doe:MAILTO:john.doe@example.com
  8. DTSTART:19970714T170000Z
  9. DTEND:19970715T035959Z
  10. SUMMARY:Bastille Day Party
  11. END:VEVENT
  12. END:VCALENDAR
复制代码
There are many different types of components which can be used in iCalendar, as described below.

Events (VEVENT)
  1. Events (VEVENT)[edit]
  2. VEVENT describes an event, which has a scheduled amount of time on a calendar. Normally, when a user accepts the calendar event, this will cause that time to be considered busy.[13] A VEVENT may include a VALARM which allows an alarm. Such events have a DTSTART which sets a starting time, and a DTEND which sets an ending time. If the calendar event is recurring, DTSTART sets up the start of the first event.

  3. A VALARM code (reminder 1 day before):

  4. BEGIN:VALARM
  5. TRIGGER:-PT1440M
  6. ACTION:DISPLAY
  7. DESCRIPTION:Reminder
  8. END:VALARM
  9. VEVENT also is used for calendar events without a specific time, such as anniversaries and daily reminders.[14] If the user needs to send in a cancellation for an event, the UID should be the same as the original event, and the component properties should be set to cancel Ex.

  10. METHOD:CANCEL
  11. STATUS:CANCELLED
  12. For sending an UPDATE for an event the UID should match the original UID. The other component property to be set is:

  13. SEQUENCE:<Num of Update>
  14. I.e., for the first update:

  15. SEQUENCE:1
  16. In Microsoft Outlook, the SUMMARY corresponds to the "Subject" entry in the "Appointment" form, and DESCRIPTION to the descriptive text below it. In addition, Outlook 2002 and Outlook 2003 demand a UID and a DTSTAMP.

复制代码

To-do (VTODO)


Journal entry (VJOURNAL)


Free/busy time (VFREEBUSY)


Other component types
Other component types include VTIMEZONE (time zones) and VALARM (alarms). Some components can include other components (VALARM is often included in other components).

Distributing updates
The UID field distributes updates when a scheduled event changes. When the event is first generated a globally unique identifier is created. If a later event is distributed with the same UID, it replaces the original one.[20]
Calendar extensions
vCalendar and iCalendar support private software extensions, with a "X-" prefix, a number of which are in common usage.

Representations

xCal
Main article: xCal
xCal is an XML representation of iCalendar data, as defined in RFC 6321.
jCal
jCal is a JSON representation of iCalendar data, as defined in RFC 7265.



回复

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
沙发
 楼主| 发表于 2018-4-27 11:31:28 | 只看该作者
本帖最后由 java 于 2018-5-7 17:53 编辑

iCalendar 编程基础:了解和使用 iCal4j
iCalendar 简介
iCalendar,简称“iCal”,是“日历数据交换”的标准(RFC 2445),该标准提供了一种公共的数据格式用于存储关于日历方面的信息,比如事件、约定、待办事项等。它不仅允许用户通过电子邮件发送会议或者待办事件等,也允许独立使用,而不局限于某种传输协议。
目前,所有流行日历工具比如:Lotus Notes、Outlook、GMail 和 Apple 的 iCal 都支持 iCalendar 标准,其文件扩展名为 .ical、.ics、.ifb 或者 .icalendar。C&S(Calendaring and Scheduling) 核心对象是一系列日历和行程安排信息。通常情况下,这些日历和行程信息仅仅包含一个 iCalendar 组件(iCalendar 组件分为 Events(VEVENT)、To-do(VTODO)、Journal(VJOURNAL)、Free/busy time (VFREEBUSY)、VTIMEZONE (time zones) 和 VALARM (alarms)),但是多个 iCalendar 组件可以被组织在一起。
C&S 核心对象第一行必须是“BEGIN:VCALENDAR”, 并且最后行必须是“END:VCALENDAR”。在这两行之间主要是由一系列日历属性和一个或者多个 iCalendar 组件组成。
下面看一个例子,它表示发生在 1997 年七月十四日下午五点与 1997 年七月十五日四点之间的事件“Bastille Day Party”。

  1. BEGIN:VCALENDAR                   ------ 起始
  2. VERSION:2.0                       ------ 版本
  3. PRODID:iCal4j v1.0//EN            ------ 创建该对象的标志符
  4. BEGIN:VEVENT                      ------ 事件开始
  5. DTSTART:19970714T170000Z          ------ 事件起始时间
  6. DTEND:19970715T040000Z            ------ 事件结束时间
  7. SUMMARY:Bastille Day Party        ------ 事件概要
  8. END:VEVENT                        ------ 事件结束
  9. END:VCALENDAR                     ------ 结束
复制代码





iCalendar 编程基础
iCal4j 简介
iCal4j(产生于 2004 年 4 月,目前是 2.0 版本),是一组读写 iCalendar 数据流的 Java API,支持 iCalendar 规范 RFC 2445,主要包括解析器、对象模型以及生成器。
文件读写
任何一种文件格式读写都是最基本的操作,清单 1 向我们演示了这两项基本操作。CalendarBuilder 对象是用来通过输入流解析和构造 iCalendar 模型。值得注意的是, CalendarBuilder 并不是 线程安全的。

RFC 2445 定义了很多关联组件属性,例如 Attendee、Contact、Organizer、Recurrence ID、UID 等。在这里,着重介绍一下组件(VEVENT、VTODO、VJOURNAL、VFREEBUSY)属性 – 唯一标志符 UID。UID 必须是一个全球唯一标志符,在 iCal4j 中可以使用 UidGenerator 来生成唯一标志符。UID 是用来代表一个日历组件,经常被应用程序用来匹配后来的各种请求,例如修改、删除、 回复等,对应用程序之间通讯起着非常重要的作用。举个简单的例子,GMail 用户 A 创建了一个会议,并邀请一个 Lotus Notes 用户 B 参加。这时,B 将收到一封来自 GMail 的邮件,决定是否接受会议邀请并通知用户 A。GMail 系统如何知道来自 B 的通知(Notification)是关于哪个会议的呢?答案是 UID。


循环事件
iCalendar 规范支持循环事件,即事件不止一次发生,通常使用一系列的日期(RDATE)或者一个循环规则(RRULE)。现在列举一个简单的 RRULE 例子。
事件每间隔一月,在每个月的 29 日发生。
RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=29
注意:非闰年二月份只有 28 天,因此这条规则将表示事件在上一年的 12 月份和 4 月之间将有一个跳跃。


时间和时区
iCal4j 提供了自己的 Date/Time 和 TimeZone 实现,与之相关的类主要有 Date、DateTime、TimeZone、TimeZoneRegistry、ZoneInfo 和 TzUrl 等。
Date 对象表示一个日期(不包括时间),而 DateTime 对象则表示日期(包含时间)。如果表示一个 UTC 时间,则只需要在时间之后加上一个“Z ”,如 DTSTART:19980119T070000Z。另外,也可以对一个时间指定一个时区,
例如 DTSTART;TZID=US-Eastern:19980119T020000。
或 DTSTART;TZID=GMT+0800:20180507T160000



https://github.com/ical4j/ical4j/wiki/Examples
ical4j 实现ICS文件的生成和解析



回复 支持 反对

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
板凳
 楼主| 发表于 2018-5-7 18:12:32 | 只看该作者
本帖最后由 java 于 2018-5-7 18:13 编辑

协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC
不属于任意时区   
中国大陆、中国香港、中国澳门、中国台湾、蒙古国、新加坡、马来西亚、菲律宾、西澳大利亚州的时间与UTC的时差均为+8,也就是UTC+8。


世界时
本初子午线的平子夜起算的平太阳时
英文:UT(Universal Time)
以本初子午线的平子夜起算的平太阳时。又称格林尼治平时格林尼治时间。各地的地方平时与世界时之差等于该地的地理经度。1960年以前曾作为基本时间计量系统被广泛应用。由于地球自转速度变化的影响,它不是一种均匀的时间系统。后来世界时先后被历书时原子时所取代,但在日常生活、天文导航、大地测量和宇宙飞行等方面仍属必需;同时,世界时反映地球自转速率的变化,是地球自转参数之一,仍为天文学和地球物理学的基本资料。

回复 支持 反对

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
地板
 楼主| 发表于 2018-5-9 15:40:53 | 只看该作者
本帖最后由 java 于 2018-5-10 10:18 编辑


RECURRecurrence Rule 递归循环规则
recur           = recur-rule-part *( ";" recur-rule-part )
规则的出现是无序的。
FREQ(freq)必须,且只出现一次,
UNTIL和COUNT是可选的,但不能同时出现在同一个规则中,当然也可以两个都不出现。
其它的规则也都是可选的,且也最多出现一次。
INTERVAL : 间隔多少个FREQ, The INTERVAL rule part contains a positive integer representing at  which intervals the recurrence rule repeats.  The default value is "1"。
COUNT  :  定义发生次数
WKST: week start  每周从哪一天开始

示例1:每年5月7号
RRULE:FREQ=YEARLY;BYMONTH=5;BYMONTHDAY=7;INTERVAL=1
示例2:
RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH
示例3:
DTSTART;TZID=America/New_York:19970105T083000
RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;
        BYMINUTE=30

https://tools.ietf.org/html/rfc5545#page-39
  1. 3.3.10.  Recurrence Rule

  2.    Value Name:  RECUR

  3.    Purpose:  This value type is used to identify properties that contain
  4.       a recurrence rule specification.

  5.    Format Definition:  This value type is defined by the following
  6.       notation:

  7.        recur           = recur-rule-part *( ";" recur-rule-part )
  8.                        ;
  9.                        ; The rule parts are not ordered in any
  10.                        ; particular sequence.
  11.                        ;
  12.                        ; The FREQ rule part is REQUIRED,
  13.                        ; but MUST NOT occur more than once.
  14.                        ;
  15.                        ; The UNTIL or COUNT rule parts are OPTIONAL,
  16.                        ; but they MUST NOT occur in the same 'recur'.
  17.                        ;
  18.                        ; The other rule parts are OPTIONAL,
  19.                        ; but MUST NOT occur more than once.

  20.        recur-rule-part = ( "FREQ" "=" freq )
  21.                        / ( "UNTIL" "=" enddate )
  22.                        / ( "COUNT" "=" 1*DIGIT )
  23.                        / ( "INTERVAL" "=" 1*DIGIT )
  24.                        / ( "BYSECOND" "=" byseclist )
  25.                        / ( "BYMINUTE" "=" byminlist )
  26.                        / ( "BYHOUR" "=" byhrlist )
  27.                        / ( "BYDAY" "=" bywdaylist )
  28.                        / ( "BYMONTHDAY" "=" bymodaylist )
  29.                        / ( "BYYEARDAY" "=" byyrdaylist )
  30.                        / ( "BYWEEKNO" "=" bywknolist )
  31.                        / ( "BYMONTH" "=" bymolist )
  32.                        / ( "BYSETPOS" "=" bysplist )
  33.                        / ( "WKST" "=" weekday )

  34.        freq        = "SECONDLY" / "MINUTELY" / "HOURLY" / "DAILY"
  35.                    / "WEEKLY" / "MONTHLY" / "YEARLY"

  36.        enddate     = date / date-time

  37.        byseclist   = ( seconds *("," seconds) )

  38.        seconds     = 1*2DIGIT       ;0 to 60

  39.        byminlist   = ( minutes *("," minutes) )

  40.        minutes     = 1*2DIGIT       ;0 to 59

  41.        byhrlist    = ( hour *("," hour) )

  42.        hour        = 1*2DIGIT       ;0 to 23

  43.        bywdaylist  = ( weekdaynum *("," weekdaynum) )

  44.        weekdaynum  = [[plus / minus] ordwk] weekday

  45.        plus        = "+"

  46.        minus       = "-"

  47.        ordwk       = 1*2DIGIT       ;1 to 53

  48.        weekday     = "SU" / "MO" / "TU" / "WE" / "TH" / "FR" / "SA"
  49.        ;Corresponding to SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY,
  50.        ;FRIDAY, and SATURDAY days of the week.
  51.       
  52.               bymodaylist = ( monthdaynum *("," monthdaynum) )

  53.               monthdaynum = [plus / minus] ordmoday

  54.               ordmoday    = 1*2DIGIT       ;1 to 31

  55.               byyrdaylist = ( yeardaynum *("," yeardaynum) )

  56.               yeardaynum  = [plus / minus] ordyrday

  57.               ordyrday    = 1*3DIGIT      ;1 to 366

  58.               bywknolist  = ( weeknum *("," weeknum) )

  59.               weeknum     = [plus / minus] ordwk

  60.               bymolist    = ( monthnum *("," monthnum) )

  61.               monthnum    = 1*2DIGIT       ;1 to 12

  62.               bysplist    = ( setposday *("," setposday) )

  63.               setposday   = yeardaynum
  64.       
复制代码
EXDATE           | Current    | RFC 5545, Section 3.8.5.1  |      |                  |            |                            |      |
EXRULE           | Deprecated | [RFC2445], Section 4.8.5.2 |      |                  |            |                            |      |
RDATE            | Current    | RFC 5545, Section 3.8.5.2  |      |                  |            |                            |      |
RRULE            | Current    | RFC 5545, Section 3.8.5.3  |

回复 支持 反对

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
5#
 楼主| 发表于 2018-5-16 14:12:56 | 只看该作者
回复 支持 反对

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
6#
 楼主| 发表于 2018-5-17 09:43:39 | 只看该作者
回复 支持 反对

使用道具 举报

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
7#
 楼主| 发表于 2018-5-18 11:39:50 | 只看该作者
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-1 02:08 , Processed in 0.070407 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表