Giter VIP home page Giter VIP logo

ics-parser's Introduction

This ics-parser is under MIT license. You may use it for your own sites for free, but I would like to get a notice when you use it ([email protected]). If you use it for another software project, please let the information / links to this project in the files.

It is hosted at https://github.com/MartinThoma/ics-parser/ and PEAR coding standard is used.

This project will not be continued. johngrogg/ics-parser is based on this project, but still supported and a few features were added.

Requirements

  • PHP

Installation

  • Copy all files to a folder where PHP can be executed
  • Include class.iCalReader.php to your project

Credits

  • Martin Thoma (programming, bug-fixing, project management)
  • Frank Gregor (programming, feedback, testing)

Basic Usage

The ics-Parser should only provide a very basic object to work with:

require 'class.iCalReader.php';

$ical = new ical('MyCal.ics');
print_r($ical->events());

What does $ical->events() return?

Array
(
    [0] => Array
        (
            [DTSTART] => 20110105T090000Z
            [DTEND] => 20110107T173000Z
            [DTSTAMP] => 20110121T195741Z
            [UID] => [email protected]
            [CREATED] => 20110121T195616Z
            [DESCRIPTION] => This is a short description\nwith a new line. Some "special" 'signs' may be <interesting>\, too.
            [LAST-MODIFIED] => 20110121T195729Z
            [LOCATION] => Kansas
            [SEQUENCE] => 2
            [STATUS] => CONFIRMED
            [SUMMARY] => My Holidays
            [TRANSP] => TRANSPARENT
        )

    [1] => Array
        (
            [DTSTART] => 20110112
            [DTEND] => 20110116
            [DTSTAMP] => 20110121T195741Z
            [UID] => [email protected]
            [CREATED] => 20110119T142901Z
            [DESCRIPTION] => 
            [LAST-MODIFIED] => 20110119T152216Z
            [LOCATION] => 
            [SEQUENCE] => 2
            [STATUS] => CONFIRMED
            [SUMMARY] => test 11
            [TRANSP] => TRANSPARENT
        )
)

How do I get a Unix timestamp out of a ical date?

If the date is before 1970, it returns false.

<?
require 'class.iCalReader.php';

$ical = new ical('MyCal.ics');
$array= $ical->events();

// The ical date
$date = $array[0]['DTSTART'];
echo $date;

// The Unix timestamp
echo $ical->iCalDateToUnixTimestamp($date);

?>

How many events / todos are in the iCal?

<?
require 'class.iCalReader.php';

$ical = new ical('MyCal.ics');

// The number of events
echo $ical->event_count;

// The number of events
echo $ical->todo_count;

?>

ics-parser's People

Contributors

martinthoma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ics-parser's Issues

SUMMARY tag with LANGUAGE setting ignored completely

What steps will reproduce the problem?
1. ICS Line: SUMMARY;LANGUAGE=en-us:Office Workgroup Focus Group


What is the expected output? What do you see instead?
Should return an array of:
('SUMMARY' => 'Office Workgroup Focus Group')

Instead returns an array of:
('SUMMARY' => '')

What version of the product are you using? On what operating system?
r13
Released: Sep 18, 2011

Please provide any additional information below.
Fixed by adding a case for the SUMMARY under function __construct($filename)

This issue might also affect timezone settings:
eg.
DTEND;TZID="Eastern Standard Time":20130502T180000
DTSTART;TZID="Eastern Standard Time":20130502T130000
etc.

But admittedly I haven't tested that yet.

Original issue reported on code.google.com by [email protected] on 2 May 2013 at 2:13

How to select from current date

Hey there,

How can i select the events from current date, and then only the events for the current month?

thanx in advance,

Angelicus

Patch for /trunk/class.iCalReader.php

I propose adding the numerical exclusion to the regex pattern on 171 because it 
matches times given in the description causing invalid parsing of the 
information.  I'm not 100% sure, but I don't believe keys in the iCalendar 
format are allowed to have numerical characters in them, so there shouldn't be 
an issue with this patch.
Thanks!

Original issue reported on code.google.com by [email protected] on 1 Feb 2012 at 5:46

Attachments:

Multiline Fields getting stripped spaces

What steps will reproduce the problem?
1.  The following event block:
BEGIN:VEVENT
DTSTART;VALUE=DATE:20111104
DTEND;VALUE=DATE:20111105
SUMMARY:Photo Day
DESCRIPTION:8:45-12:00\nPlease make sure that students have their photo 
 forms and payments on the day of photo day that they can hand to the 
 photographer
LOCATION:individual photos will be taken in the Library and class photos 
 will be taken in The Art Room
UID:FA2ADBF1-1815-4F8F-9040-DD983DE10B4E
DTSTAMP:20120829T070843Z
TRANSP:TRANSPARENT
LAST-MODIFIED:20120828T142712Z
X-BUSYMAC-LASTMODBY:Administrator
END:VEVENT

What is the expected output? What do you see instead?
Expected output of description should be:
"8:45-12:00\nPlease make sure that students have their photo forms and payments 
on the day of photo day that they can hand to the photographer"

What I end up with:
"8:45-12:00\nPlease make sure that students have their photoforms and payments 
on the day of photo day that they can hand to thephotographer"

note no space between photo and forms and the and photographer

What version of the product are you using? On what operating system?
latest as of today, sorry.

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 30 Aug 2012 at 2:12

Continuation lines with ':' parsed as new key-value field

What steps will reproduce the problem?
1. Parse an ICS file with the following multi-line value:
...
DESCRIPTION:BendTech Meetup\nWednesday\, April 17 at 6:00 PM\n\nThis meet
 ing is a followup to the INW meeting last Tuesday where we talked about
 MakerSpaces. We had a great turnout (30+ people) and lots of energy a...
 \n\nDetails: http://www.meetup.com/bendtech/events/114014962/
...

Notice that the last line is parsed as a separate key-value line, rather than 
as a continuation of the DESCRIPTION line.

This can be fixed by adding the following to the head of the foreach block in 
__construct():

                if (substr($line, 0, 1) == ' ') {
                  // continuation line
                  $line = substr($line, 1);
                  $this->addCalendarComponentWithKeyAndValue($type, false, $line);
                  continue;
                }

Original issue reported on code.google.com by broofa on 15 Apr 2013 at 12:42

Events that have an RRULE don't recur

What steps will reproduce the problem?
1. Create a recurring event in your calendar 
2. View the list of events by date

What is the expected output? What do you see instead?
It should have the event repeated (with shifted start and end dates) according 
to the RRULE entry for the event.

Please provide any additional information below.
I've created a modified version of the parser that handles recurring events. It 
is available at the following github repo:
https://github.com/johngrogg/ics-parser

Feel free to snag it, tweak it, and bring it back into this main repo.

Original issue reported on code.google.com by [email protected] on 10 Jul 2013 at 11:21

Patch for /trunk/class.iCalReader.php

The code as it was did not parse UTC timestamps correctly if there was a 
different default timezone.  This worked especially poorly if there were a mix 
of UTC and non-UTC dates in the ics file.  I made some edits to keep the Z 
indicator and rely on it to format thigs differently depending.

Original issue reported on code.google.com by [email protected] on 21 Feb 2013 at 5:57

Attachments:

Recurring events are disregarded

All the recurring instances of an event are not taken in consideration when parsing the ics file, only the first instance. Would it be possible to make an update for it?

Time wrong on google calendars

What steps will reproduce the problem?
1. Use 

$ical   = new 
ICal('https://www.google.com/calendar/ical/vk8jabjtlgkm43nrpa5f2j7d4s%40group.ca
lendar.google.com/private-23a9c345d3cf3b5a749e362dda839de8/basic.ics');
$events = $ical->events();
foreach($events as $event) {
   date('G:i',$ical->iCalDateToUnixTimestamp($event['DTSTART']))
}

on a Google calendar and it will show the difference of 2h at the moment 
(1h normal and 1h due to day light savings time).

What is the expected output? What do you see instead?

It will show the difference of 2h at the moment 
(1h normal and 1h due to day light savings time).

What version of the product are you using? On what operating system?

Revision 13. Mac OS X.


Please provide any additional information below.

There is an easy fix: replace 

$timestamp = mktime(

by 

$timestamp = gmmktime(

and it will get it right.

Original issue reported on code.google.com by [email protected] on 4 Oct 2013 at 5:14

Doesn't recognize ICS EXDATE property (excluded date, date/time exceptions)

Property Name
EXDATE
Purpose
This property defines the list of date/time exceptions for a recurring calendar component.
Value Type
The default value type for this property is DATE-TIME. The value type can be set to DATE.
Property Parameters
Non-standard, value data type and time zone identifier property parameters can be specified on this property.
Conformance
This property can be specified in an iCalendar object that includes a recurring calendar component.

Source: http://www.kanzaki.com/docs/ical/exdate.html

Fix multiline-description

Hello, me and my boss found the solution for that problem.
You write the wrongregular expression to  keyValueFromString and that maked the 
problem.
You need to replace this:

preg_match("/([^:]+)[:]([\w\W]*)/", $text, $matches);

To that:

preg_match("/^([A-Z\-]+)\:(.*)$/", $text, $matches);

Original issue reported on code.google.com by [email protected] on 23 Jul 2013 at 2:38

Request: URL change

Hello,

When you have a moment, would it be possible to update the link johngrogg/ics-parser in your README to u01jmg3/ics-parser as the repo has changed owners?

Thank you

Replacing description with description value from VALARM section

When is use VALARM section, description is replaced with description from 
there. 

For example, for this event

BEGIN:VEVENT
DTSTAMP:20120704T141257Z
UID:040000008200E00074C5B7101A82E00800000000314FF44
DESCRIPTION:Test Description
PRIORITY:5
SUMMARY:Test
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-LABEL:0
CLASS:PUBLIC
SEQUENCE:0
X-ALARM-TRIGGER:-PT15M
X-NEXT-ALARM:20120707T054500Z
DTSTART;TZID="Amsterdam, Belgrade, Berlin":20120707T080000
DTEND;TZID="Amsterdam, Belgrade, Berlin":20120707T130000
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Alarm Description
TRIGGER;RELATED=START:-PT15M
END:VALARM
END:VEVENT

return description "Alarm Description" and not "Test Description"

Sorry for my English...

Original issue reported on code.google.com by [email protected] on 4 Jul 2012 at 2:55

eventsFromRange should allow arbitrary range

To allow an arbitrary range to be selected using the eventsFromRange method I 
altered the code to the following, bool start and end are still accepted and 
should give same result as before (i.e. shouldn't break existing 
implementations)


/**
 * Returns false when the current calendar has no events in range, else the
 * events.
 * 
 * Note that this function makes use of a UNIX timestamp. This might be a 
 * problem on January the 29th, 2038.
 * See http://en.wikipedia.org/wiki/Unix_time#Representing_the_number
 *
 * @param {boolean} or {time} $rangeStart Either true or false or unix timestamp
 * @param {boolean} or {time} $rangeEnd   Either true or false or unix timestamp
 *
 * @return {mixed}
 */
public function eventsFromRange($rangeStart = false, $rangeEnd = false) 
{
    $events = $this->sortEventsWithOrder($this->events(), SORT_ASC);

    if (!$events) {
        return false;
    }

    $extendedEvents = array();

    if ($rangeStart === true) {
        $rangeStart = time();
    } else if ($rangeStart === false) {
        $rangeStart = 0;
    }

    if ($rangeEnd === true or ($rangeEnd <= $rangeStart && $rangeStart <= time())) {
        $rangeEnd = time();
    } else if ($rangeEnd === false or $rangeEnd <= $rangeStart) {
        $rangeEnd = strtotime('2038-01-18');
    }

    // loop through all events by adding two new elements
    foreach ($events as $anEvent) {
        $dtStart = $this->iCalDateToUnixTimestamp($anEvent['DTSTART']);
        $dtEnd = $this->iCalDateToUnixTimestamp($anEvent['DTEND']);
        if ($dtEnd >= $rangeStart && $dtStart <= $rangeEnd) $extendedEvents[] = $anEvent;
    }

    return $extendedEvents;
}



Original issue reported on code.google.com by [email protected] on 29 Jan 2012 at 9:09

Calendar Name and Summary

What steps will reproduce the problem?
1. Parse Calendar Name, Description etc.
2. Parse Timezone information
3.

What is the expected output? What do you see instead?

Calendar Name, Description, Timezone information. 

What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 7 Jul 2014 at 6:23

You should use gmmktime for Google Calendar ICS files

• What steps will reproduce the problem?
1. Parse a Google Calendar ICS file. Google uses only GMT to avoid conflicts 
with daylight saving times  
2. Use the function iCalDateToUnixTimestamp and it will return a bad timestamp 
if your location is not UTC / GMT. 

• What is the expected output? What do you see instead?
For example : an event starting 2015-01-20 17:00:00 GMT will be timestamped 
2015-01-20 16:00:00 GMT if you are located in Paris and your server configured 
like that. 

• What version of the product are you using? On what operating system?
Current - OSX 10.9.5 - MAMP Latest

• Please provide any additional information below.
My solution : use gmmktime instead of mktime in the iCalDateToUnixTimestamp 
function.

I hope I am clear... :)
And this helps some people.

Thxxxxxx for your useful class.

Regards

Julien


Original issue reported on code.google.com by [email protected] on 20 Jan 2015 at 3:10

eventsFromRange: fail to search event by range

What steps will reproduce the problem?
1. call function eventsFromRange with input like '2013-10-01', '2013-12-31'
2. returned events are from now to 2038/01/18
3.

What is the expected output? What do you see instead?
events are from '2013-10-01' to '2013-12-31'

What version of the product are you using? On what operating system?
r13, is CentOS 5.6, php5.3.3

Please provide any additional information below.
event range should not function like its name

Original issue reported on code.google.com by [email protected] on 16 Jul 2013 at 9:01

Easier way to get the Unix timestamp

PHP has a function to get the Unix timestamp: strtotime()
It works pretty well on your example too:

<?
require 'class.iCalReader.php';

$ical = new ical('MyCal.ics');
$array= $ical->events();

// The ical date
$date = $array[0]['DTSTART'];
echo $date;

// The Unix timestamp
$unixDate = strtotime($date);
echo $unixDate;
?>

This is also useful because then you can get a readable date:
echo date('m/d/Y h:i:s a', $unixDate);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.