支持时区的 PHP 中的 ICalendar 解析器

ICalendar parser in PHP that supports timezones(支持时区的 PHP 中的 ICalendar 解析器)
本文介绍了支持时区的 PHP 中的 ICalendar 解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个可以解析 ICalendar (ICS) 文件并正确处理时区的 PHP 类.

I am looking for a PHP class that can parse an ICalendar (ICS) file and correctly handle timezones.

我自己已经创建了一个 ICS 解析器,但它只能处理 PHP 已知的时区(如欧洲/巴黎").

I already created an ICS parser myself but it can only handle timezones known to PHP (like 'Europe/Paris').

很遗憾,Evolution(Ubuntu 的默认日历软件)生成的 ICS 文件不使用默认时区 ID.它使用特定的时区 ID 导出事件,同时导出时区的完整定义:夏令时日期、重复规则以及所有难以理解的有关时区的内容.

Unfortunately, ICS file generated by Evolution (default calendar software of Ubuntu) does not use default timezone IDs. It exports events with its a specific timezone ID exporting also the full definition of the timezone: daylight saving dates, recurrence rule and all the hard stuff to understand about timezones.

这对我来说太多了.因为它只是我女朋友的一个小工具,所以我没有时间进一步研究 ICalendar 规范并自己创建一个成熟的 ICalendar 解析器.

This is too much for me. Since it was only a small utility for my girlfriend, I won't have time to investigate further the ICalendar specification and create a full blown ICalendar parser myself.

那么,在 PHP 中是否有任何已知的 ICalendar 文件格式实现可以解析时区定义?

So is there any known implementation in PHP of ICalendar file format that can parse timezones definitions?

推荐答案

很可能有很多解析 .ics 文件的库,但我将向您展示一个对我非常有效的示例.

Most likely there are a lot of libraries that parse .ics files, but I'll show you one example that works for me quite well.

我使用过这个库:http://www.phpclasses.org/浏览/文件/16660.html

它为您处理不同类型的 ICal 组件提供了很大的灵活性:VEVENT、VTODO、VJOURNAL、VFREEBUSY、VALARM 和 VTIMEZONE(您要询问的那个).

It gives you a lot of flexibility in handling different types of ICal components: VEVENT, VTODO, VJOURNAL, VFREEBUSY, VALARM, and VTIMEZONE (the one you were asking about).

示例:

<pre><?php

//
// Open library
//
require_once( "iCalcreator.class.php" ) ;

//
// Demo ICal file contents
//
$string = <<<EOS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VTIMEZONE
TZID:US-Eastern
LAST-MODIFIED:19870101T000000Z
BEGIN:STANDARD
DTSTART:19971026T020000
RDATE:19971026T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:19971026T020000
RDATE:19970406T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
EOS
;

//
// There is no direct string parsing functionality,
// so first create a temporary file
//
$filename = tempnam( ".", "" ) ;
$f = fopen($filename,"w") ;
fwrite( $f, $string );
fclose($f);

//
// ... parse it into an object
//
$var = new vcalendar();
$var->parse($filename);
var_dump( $var );
$event = $var->components[0] ;
var_dump( $event->createDtstamp() );


//
// ... and finally remove all temporary data.
//
unlink($filename);

这篇关于支持时区的 PHP 中的 ICalendar 解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)