Syntax to create a multiple day events?

163 views
Skip to first unread message

jan mueller

unread,
Mar 5, 2014, 12:10:23 PM3/5/14
to sabredav...@googlegroups.com
Hello Evert, 

I'm stuck at creating events that span multiple days.
When using 

    'DTSTART' => new \DateTime('2014-06-27'),
    'DTEND' => new \DateTime('2014-06-29'),

it occupies the whole days in calendar view (eg. iCal on osx). 
I want it to be a "whole day" event. 

Which syntax do I need to use? 

best, 
Jan

Evert Pot

unread,
Mar 5, 2014, 4:36:28 PM3/5/14
to sabredav...@googlegroups.com
Hi Jan,

A standard DTSTART looks like this:

DTSTART:20140629T123000Z

An all day event looks like this:

DTSTART;VALUE=DATE:20140629

All you need to do is set this VALUE parameter to make this work. So if you already have a VEVENT object with a DTSTART property,
you can change it as such:

$vevent->DTSTART['VALUE'] = 'DATE';

I think it's better to set this all in one go though. So I wouldn't pass DTSTART when you're creating the vevent object, but set it later
as such:

$vevent->add(
  'DTSTART',
  new DateTime('2014-06-29'),
  ['VALUE' => 'DATE' ]
);

This way there's less processing, because you're not transforming a DATE-TIME into a DATE, but rather create it correctly right from the get-go.

Evert

jan mueller

unread,
Mar 5, 2014, 5:25:48 PM3/5/14
to sabredav...@googlegroups.com
Good evening, Evert, 

I changed my code. It looks like this now (had to change to the old array-syntax) : 
$vcalendar->add('VEVENT', array(
    'SUMMARY' => 'Beachsoccer 2014',
    'LOCATION' => 'SKG Arena ,Bickenbach', 
));

$vcalendar->add(
  'DTSTART',
  new DateTime('2014-06-27'), 
  array(
  'VALUE' => 'DATE'
  )
);
$vcalendar->add(
  'DTEND',
  new DateTime('2014-06-29'), 
  array(
  'VALUE' => 'DATE'
  )
);



The resulting ics looks like this: 

BEGIN:VCALENDAR

VERSION:2.0

PRODID:-//Sabre//Sabre VObject 3.1.3//EN

CALSCALE:GREGORIAN

DTSTART;TZID=Europe/Berlin;VALUE=DATE:20140627T000000

DTEND;TZID=Europe/Berlin;VALUE=DATE:20140629T000000

BEGIN:VEVENT

SUMMARY:Beachsoccer 2014

LOCATION:SKG Arena \,Bickenbach

END:VEVENT

END:VCALENDAR


When trying to open it (iCal on OSX), the event is not added :-( 
I removed The T000000 by hand already and it did not change anything. 
Can't figure it out.. 

best regards, 
Jan 

Ingo Ratsdorf

unread,
Mar 5, 2014, 6:09:37 PM3/5/14
to sabredav...@googlegroups.com
Maybe because you say it's a date but you are submitting a DateTime?
And a date does not have a TIMEzone.

so either it is
DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140627T000000
or
DTSTART;VALUE=DATE-TIME:20140627T000000Z
or
DTSTART;VALUE=DATE:20140627
or
DTSTART:20140627

Cheers,
Ingo
--
You received this message because you are subscribed to the Google Groups "SabreDAV Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sabredav-discu...@googlegroups.com.
To post to this group, send email to sabredav...@googlegroups.com.
Visit this group at http://groups.google.com/group/sabredav-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Evert Pot

unread,
Mar 7, 2014, 3:34:49 PM3/7/14
to sabredav...@googlegroups.com

On Wednesday, March 5, 2014 6:09:37 PM UTC-5, IngoRatsdorf wrote:
Maybe because you say it's a date but you are submitting a DateTime?
And a date does not have a TIMEzone.

Actually.. it's a bug.

There's no 'Date' class in PHP, so using DateTime here is correct. It's the VALUE that in the end
that formats the value as either an iCalendar DATE-TIME or DATE.

I'm going to fix this bug, and this will be part of the next release.

In the meantime, I have two workaround:

1. Specify the date as a string, instead of a PHP DateTime object:

$vevent->add(
  'DTSTART',
  '20140627', 
  array(
  'VALUE' => 'DATE'
  )
);

2. First set the VALUE property, and then set the date (but this kinda sucks)

$dtstart = $vevent->add(
  'DTSTART',
  null,
  array(
  'VALUE' => 'DATE'
  )
);

$dtstart->setValue(new DateTime('2014-06-27'));

3. Bonus:

$vevent->add(
  'DTSTART',
  (new DateTime('2014-06-27'))->format('Ymd'), 
  array(
  'VALUE' => 'DATE'
  )
);

Note though, that in your example, you set the DTSTART and DTEND on the VCALENDAR object, which is wrong regardless. DTSTART and DTEND are children of the VEVENT object.

Evert

Evert Pot

unread,
Mar 7, 2014, 3:43:02 PM3/7/14
to sabredav...@googlegroups.com


On Friday, March 7, 2014 3:34:49 PM UTC-5, Evert Pot wrote:

On Wednesday, March 5, 2014 6:09:37 PM UTC-5, IngoRatsdorf wrote:
Maybe because you say it's a date but you are submitting a DateTime?
And a date does not have a TIMEzone.

Actually.. it's a bug.


.. which is now fixed on the master branch of sabre/vobject.

jan mueller

unread,
Mar 8, 2014, 6:56:22 AM3/8/14
to sabredav...@googlegroups.com
I got it to work. Using this code, as you proposed: 

$vcalendar = new VObject\Component\VCalendar();

$vevent = $vcalendar->add('VEVENT', array(
    'SUMMARY' => 'Beachsoccer 2014',
    'LOCATION' => 'SKG Arena ,Bickenbach', 
));

$vevent->add(
  'DTSTART',
  '20140627', 
  array(
  'VALUE' => 'DATE'
  )
);

$vevent->add(
  'DTEND',
  '20140630', 
  array(
  'VALUE' => 'DATE'
  )
);


The "Bonus" code did not work; threw a parser error. 

Thank you again & have a good day! 
Jan  
Reply all
Reply to author
Forward
0 new messages