Email me at [email protected]
ozzyczech / icalparser Goto Github PK
View Code? Open in Web Editor NEWSimple ical parser for PHP
Home Page: https://ozana.cz
License: BSD 3-Clause "New" or "Revised" License
Simple ical parser for PHP
Home Page: https://ozana.cz
License: BSD 3-Clause "New" or "Revised" License
Email me at [email protected]
This feed https://www.stanza.co/api/schedules/nhl-penguins/nhl-penguins.ics has VEVENT blocks with the VALARM immeadiately within it (see below). The parser throws an error in this case
Undefined index: VEVENT
in file /vendor/om/icalparser/src/IcalParser.php at line 180
I tried to figure out the best approach to get around this but the state-machine logic in there is kind of hard to follow. Any pointers?
BEGIN:VEVENT
BEGIN:VALARM
TRIGGER;VALUE=DURATION:-PT30M
ACTION:DISPLAY
DESCRIPTION:Penguins vs. Blue Jackets
END:VALARM
DTSTART:20170204T000000Z
DTEND:20170204T021500Z
UID:[email protected]
SUMMARY:Penguins vs. Blue Jackets
DESCRIPTION:Penguins vs. Blue Jackets\n\nBuy tickets here: https://stza.co/~lRQk\n\nSynced via Stanza - create your own live updating calendar (https://stanza.co?events)\n\nFor questions, check out Stanzaβs FAQs page: https://stanza.co/faqs
LOCATION:PPG Paints Arena, 1001 Fifth Ave, Pittsburgh, PA
STATUS:CONFIRMED
DTSTAMP:20170801T090752Z
CREATED:20170801T090752Z
LAST-MODIFIED:20170801T090752Z
TRANSP:OPAQUE
END:VEVENT
Unlimited recurring events only works for 3 years because it is limited in class IcalParser in function parseRecurrences
$end = clone($event['DTSTART']);
$end->add(new \DateInterval('P3Y')); // + 3 years
After 3 years the recurring event is not working anymore.
I am working on a solution for this issue, but I am not finished, yet.
Are there any more ideas which could help me?
Since PHP5.4 is near it end of life, and PHP5.6 published since one year, it could be a good thing to add a third build on PHP5.6 on travis CI
We have an iCal file generated from Google Calendar that we're parsing. It has multiple events that are recurring weekly on Mondays, Tuesdays, Wednesdays, and Thursdays. When the recurring event is parsed, the first week parses correctly. But for all subsequent weeks, Mondays are omitted.
I enabled debugging in the function that locates the next occurrence of an event and it looks like after the event on Wednesday, the EOP (end of period) value was being set to the following Monday but at midnight, so the event on Monday was out of the scope. When it continued in the loop, it began with Tuesday, so no Monday (other than the first Monday) was included in the list of recurrences.
The solution that we employed was this:
Changed line 367 in /opt/calendar/vendor/om/icalparser/src/Freq.php to read
return $this->findStartingPoint($offset, 1, false);
Original value was:
return $this->findStartingPoint($offset, 1);
I have no idea if that was the correct way to resolve it, or if this should be introduced as something permanent to the code base. But it's working for our specific situation.
BEGIN:VEVENT
UID:111
DTSTAMP:20181123T192651Z
CATEGORIES;LANGUAGE=de-DE:Party
CONTACT:
DESCRIPTION:xxx
DTSTART;TZID=Europe/Berlin:20160415T210000
DTEND;TZID=Europe/Berlin:20160416T040000
LOCATION:xxx
RDATE;TZID=Europe/Berlin:20161216T210000
RDATE;TZID=Europe/Berlin:20161223T210000
RDATE;TZID=Europe/Berlin:20161230T210000
SEQUENCE:0
SUMMARY:xxx
END:VEVENT
From this event, these dates are generated:
20160415
20161216
20161223
20161230
20170415
20180415
20190415
This is not correct. This problem seems to be the default setting in Freq.php:
protected $rules = ['freq' => 'yearly', 'interval' => 1];
There is no yearly rule in this event.
Hi,
When I use the foreach loop as described in the doc, I get that fatal Error
foreach ($cal->getEvents()->sorted() as $event) {
Uncaught Error: Call to a member function sorted() on array
If I remove the sorted part, the script is working but it seems there are confusions in the event Dates
foreach ($cal->getEvents() as $event) {
My php version is 7.4.27 and installed icalparser via composer this week.
What could I have missed?
Thank you for your Help!
Some files, like all the files provided by Mozilla:https://www.mozilla.org/en-US/projects/calendar/holidays/ have a prefix for the timezones, like this: TZID:/mozilla.org/20070129_1/Europe/Paris that will leads to an error when instanciating DateTimezone object
Hey.. since it is possible to grab parsed informations of a single event out of an ICS-File with multiple events:
Maybe it is possible or easy to implement exporting single event as ICS file?
thx
The timezones used by outlook.com 's ical files aren't supported so it seems.
DateTimeZone::__construct(): Unknown or bad timezone ((UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna)
File:/var/www/html/admin/modules/calendar/vendor/om/icalparser/src/IcalParser.php:252
File: icalparser/src/IcalParser.php
Line: 126
Function name: parseFile
The code is expected to throw exception on failing to open file. There is PHP warning instead with message: failed to open stream: No such file or directory.
OS: Ubuntu Server 14.04
PHP version: 5.5+
In my Google calender two different weekly events are scheduled.
One event is on a tuesday every two weeks. The other event also but one week shifted. (Same starttime and endtime.)
So, effectively the events alternate every week.
When i use icalparser both events are shown every thuesday.
(Google calender shows the events correctly (alternating on tuesday).
Any idea whats going wrong?
Example of one event:
Thuesday event.txt
You should probably update the example or remove it cause it is not working anymore with the current version.
Installed with composer:
Copied the example to testi.php and:
PHP Fatal error: Class 'om\IcalParser' not found in /www/default/rislointra/testi.php on line 20
What else shoud be done? I am not familiar with composer at all, but the require_once dependency seems to be loaded since no error message on it.
Issue with RRULE:FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Office Hours
X-WR-TIMEZONE:America/New_York
X-WR-CALDESC:
BEGIN:VTIMEZONE
TZID:America/Los_Angeles
X-LIC-LOCATION:America/Los_Angeles
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=America/Los_Angeles:20180506T100000
DTEND;TZID=America/Los_Angeles:20180506T103000
RRULE:FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR
DTSTAMP:20180722T165639Z
UID:[email protected]
CREATED:20180721T064200Z
DESCRIPTION:
LAST-MODIFIED:20180721T065236Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:Ok
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20180129
DTEND;VALUE=DATE:20180130
DTSTAMP:20180722T165639Z
UID:[email protected]
CREATED:20180130T220521Z
DESCRIPTION:
LAST-MODIFIED:20180130T220555Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:All Day
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
In the rule above I have Sunday, Monday, Tuesday, Wednesday, Thursday, Friday.
However the result I get from icalparser skips Mondays (the even started ON a Monday)
I figured out that this is a bug in freq.php
If you debug Freq.php (turn $debug = true in method findNext). You'll see this
O: Mon, 03 Dec 2018 00:00:00 -0800
START: Mon, 03 Dec 2018 10:00:00 -0800
EOP: Mon, 10 Dec 2018 00:00:00 -0800
DAY: Sun, 09 Dec 2018 10:00:00 -0800 A: 1
DAY: Mon, 10 Dec 2018 10:00:00 -0800 A: 0
DAY: Tue, 04 Dec 2018 10:00:00 -0800 A: 1
DAY: Wed, 05 Dec 2018 10:00:00 -0800 A: 1
DAY: Thu, 06 Dec 2018 10:00:00 -0800 A: 1
DAY: Fri, 07 Dec 2018 10:00:00 -0800 A: 1
OK
Notice "DAY: Mon, 10 Dec 2018" is A: 0. Thats because the EOP (End of period) is set to 12:00am. On Monday the Event goes until 10:00:00. So it's outside the range of the EOP. However it shouldn't be. The EOP should be the same time as START (not the same date).
I was able to fix this by making sure the EOP time is set to the time of START (I didn't change the date though)
Freq.php Line 279:
Replace:
$eop = $this->findEndOfPeriod($offset);
with
//EOP needs to have the same TIME as START ($t)
$tO = new \DateTime('@'.$t, new \DateTimeZone('UTC'));
$eop = $this->findEndOfPeriod($offset);
$eopO = new \DateTime('@'.$eop, new \DateTimeZone('UTC'));
$eopO->setTime($tO->format('H'),$tO->format('i'),$tO->format('s'));
$eop = $eopO->getTimestamp();
unset($eopO);
unset($tO);
I still need to run through your unit tests to confirm this won't break anything
hey.. when i add multiple categories via thunderbird to my nextcloud caldav calendar, it is like:
CATEGORIES:Anruf
CATEGORIES:Besondere Gelegenheit
CATEGORIES:Feiertag
CATEGORIES:Online
CATEGORIES:Suppliers
$cal->getSortedEvents()
just gets the last one.. only CATEGORIES:Suppliers
is there
How can you display the time in the correct time zone?
Hello,
I try to Parse a Google Calendar ICS file.
No problem with my own calendar as I barely use it, it's a small file.
But when I try with my Boss' calendar, I get a 500 server Error because of the large file (1.9MB).
I think I could increase php memory limit but I would like to find a more efficient way.
Is there a method to split the large file for example or another solution?
Issue: Invalid timezone error
Observations:
Two invalid timezone entries were encountered in our system:
Upon examining the IcalParser.php file, I noticed that the toTimezone function searches for a matching value within the windowsTimezones array. If it cannot find a match, it proceeds to use the $zone value directly. However, the subsequent operations involving new DateTimeZone($value) do not accept the value returned by this function. It seems that additional entries may need to be added to the windowsTimezones file.
Any help or guidance on resolving this issue would be greatly appreciated. Thank you in advance!
I think I found a bug: Yearly recurring events in January are not handled correctly, except for the first occurrence.
It's difficult to debug the code, but I think it's caused by the following line:
Line 256 in 255d3d2
if ($imm > $offset && $imm <= $eop && ($_t == null || $imm < $_t)) {
If this is changed into:
if ($imm >= $offset && $imm <= $eop && ($_t == null || $imm < $_t)) {
then it's working.
Shall I make a PR for this?
Drupal ran in to this same issue. Apparently, Exchange will sometimes return "Eastern Standard Time" or "Eastern Daylight Time". The fix is documented in https://www.drupal.org/node/1608132.
The function that is called is gettimezone but the function name is gettimezones
Hello
I just tried to run the ical parser with the given example under PHP 5.3.17. However this results in a blank page and lots of messages like this in the logs:
[Mon Jun 01 14:59:52 2015] [error] [client 149.217.48.231] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE in /srv/www/htdocs/news/include/IcalParser.php on line 92
Whats the problem here?
Best,
Thomas
I made an event in my Google calender with recurrency "Every last tuesday of the month". Starting at tuesday 28 november (for 6 times).
The output from the function parseFile is an array. The recurrences part is shown below.
[RECURRENCES] => Array(
[0] => DateTime Object ( [date] => 2023-11-28 20:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam)
[1] => DateTime Object ( [date] => 2023-12-26 20:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam)
[2] => DateTime Object ( [date] => 2024-01-23 20:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam)
[3] => DateTime Object ( [date] => 2024-02-20 20:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam)
[4] => DateTime Object ( [date] => 2024-03-19 20:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam)
[5] => DateTime Object ( [date] => 2024-04-16 20:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam))
As you can see the dates are tuesdays but not last tuesdays!
I'am not a php-pro. So I cannot pinpoint the code thats causing this error.
Thanks in advance for your attention.
Wim Raaij
When parsing recurring meetings it will detect a single meeting exception(occurrence) as a different recurring instance.
Here is an example sanitized ics file
https://gist.github.com/jasonheffner/eeb934d3edd29bc50ee40580e6890459
A single occurrence(exception) of a recurring meeting happens on 4/4/2017 at 3:30 - 4:30 EST which normally happens at 2:00 - 3:00 recurring. The code treats this as a separate recurring meeting and produces the following.
If an ICS has wrong date for some eveent (like : DTEND;VALUE=DATE:20141225 ), DateTime constructor will trigger an exception.
For the moment, this exception in un catched, and caused file parsing failure.
I will submit a pull request to fix that.
I propose to catch the exception, and set an empty value instead of the datetime object.
Which fallback value seems better ? null, false, an empty datetime object ?
Hello @OzzyCzech ,
thank you for this great parser.
I have tested it yesterday with different calendars and worked out some way of using.
Even I experimented of array based reading of the calendar.
Due there is no tutorial or wiki, I would kindly assist you here, furthermore Im proud to use code from someone who is from the same country like me ;)
I will try to make some wiki page entries and demo code, even explanation of your php code with getsorted and getsortedreverse (what I really looked for ;) )
Thank you
When parsing a VEVENT that has multiple ATTACH instances, the ATTACH key is overwritten by each subsequent instance. To retain backwards compatibility, I would recommend adding a new key called ATTACHMENTS and making it an array of 1 or more values. See my pull request.
Try running test, i got this:
PHP Fatal error: Uncaught Error: Typed property om\IcalParser::$timezone must not be accessed before initialization in /vendor/om/icalparser/src/IcalParser.php:284
PHP 7.4 on Debian 11
Hi Roman,
first, thanks for this useful Project !
just a short note: I found one thing missing: URL specification for events.
here is my modification:
`diff --git a/src/IcalParser.php b/src/IcalParser.php
index 9a91656..349e018 100644
--- a/src/IcalParser.php
+++ b/src/IcalParser.php
@@ -247,10 +247,11 @@ class IcalParser {
}
//implement 4.3.11 Text ESCAPED-CHAR
// added 'URL', 05.04.19 josswern
$text_properties = [
'CALSCALE', 'METHOD', 'PRODID', 'VERSION', 'CATEGORIES', 'CLASS', 'COMMENT', 'DESCRIPTION'
, 'LOCATION', 'RESOURCES', 'STATUS', 'SUMMARY', 'TRANSP', 'TZID', 'TZNAME', 'CONTACT', 'RELATED-TO', 'UID'
, 'ACTION', 'REQUEST-STATUS'
, 'ACTION', 'REQUEST-STATUS','URL',
];
if (in_array($key, $text_properties) || strpos($key, 'X-') === 0) {
if (is_array($value)) {
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.