Skip to content

Commit f0db671

Browse files
authored
fix: vcard bday export format with unknown year (#6087)
1 parent 780b128 commit f0db671

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/Services/VCard/ExportVCard.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,16 @@ private function exportWorkInformation(Contact $contact, VCard $vcard)
196196
/**
197197
* @param Contact $contact
198198
* @param VCard $vcard
199+
*
200+
* @see https://datatracker.ietf.org/doc/html/rfc6350#section-6.2.5
199201
*/
200202
private function exportBirthday(Contact $contact, VCard $vcard)
201203
{
202204
$vcard->remove('BDAY');
203205

204206
if (! is_null($contact->birthdate)) {
205207
if ($contact->birthdate->is_year_unknown) {
206-
$date = $contact->birthdate->date->format('--m-d');
208+
$date = $contact->birthdate->date->format('--md');
207209
} else {
208210
$date = $contact->birthdate->date->format('Ymd');
209211
}

tests/Unit/Services/VCard/ExportVCardTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,24 @@ public function vcard_add_birthday()
311311
$this->assertStringContainsString('BDAY:20001005', $vCard->serialize());
312312
}
313313

314+
/** @test */
315+
public function vcard_add_birthday_with_unknown_year()
316+
{
317+
$account = factory(Account::class)->create();
318+
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
319+
$contact->setSpecialDate('birthdate', 0, 10, 5);
320+
$vCard = new VCard();
321+
322+
$exportVCard = app(ExportVCard::class);
323+
$this->invokePrivateMethod($exportVCard, 'exportBirthday', [$contact, $vCard]);
324+
325+
$this->assertCount(
326+
self::defaultPropsCount + 1,
327+
$vCard->children()
328+
);
329+
$this->assertStringContainsString('BDAY:--1005', $vCard->serialize());
330+
}
331+
314332
/** @test */
315333
public function vcard_add_contact_fields_empty()
316334
{

0 commit comments

Comments
 (0)