Skip to content

Commit

Permalink
Support for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikTo committed Jul 8, 2015
1 parent b2a44c6 commit b05b356
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/BirthdayCalendarGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class BirthdayCalendarGenerator {
*/
protected $defaultYear = 1900;

/**
* Output format for the SUMMARY.
*
* @var string
*/
protected $format = '%1$s\'s Birthday';

/**
* Creates the generator.
*
Expand Down Expand Up @@ -121,6 +128,19 @@ function setTimeZone(DateTimeZone $timeZone) {

}

/**
* Sets the output format for the SUMMARY
*
* @param string $format
*
* @return void
*/
function setFormat($format) {

$this->format = $format;

}

/**
* Parses the input data and returns a VCALENDAR.
*
Expand Down Expand Up @@ -163,7 +183,7 @@ function getResult() {

// Create event.
$event = $calendar->add('VEVENT', [
'SUMMARY' => $object->FN->getValue() .'\'s Birthday',
'SUMMARY' => sprintf($this->format, $object->FN->getValue()),
'DTSTART' => new \DateTime($object->BDAY->getValue(), $this->timeZone),
'RRULE' => 'FREQ=YEARLY',
'TRANSP' => 'TRANSPARENT',
Expand All @@ -181,6 +201,4 @@ function getResult() {

}



}
39 changes: 39 additions & 0 deletions tests/VObject/BirthdayCalendarGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,43 @@ function testVcardStringWithNoBirthday() {

}

function testVcardStringWithValidBirthdayLocalized() {

$input = <<<VCF
BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest;;Mr.
FN:Forrest Gump
BDAY:19850407
UID:foo
END:VCARD
VCF;

$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:Forrest Gump's Geburtstag
DTSTART:19850407T000000Z
RRULE:FREQ=YEARLY
TRANSP:TRANSPARENT
X-SABRE-BDAY;X-SABRE-VCARD-UID=foo;X-SABRE-VCARD-FN=Forrest Gump:BDAY
END:VEVENT
END:VCALENDAR
ICS;

$this->generator->setObjects($input);
$this->generator->setFormat('%1$s\'s Geburtstag');
$output = $this->generator->getResult();

$this->assertVObjEquals(
$expected,
$output
);

// Reset to default format
$this->generator->setFormat('%1$s\'s Birthday');

}

}

0 comments on commit b05b356

Please sign in to comment.