-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vCard 4.0: fix Name Property #146
base: 2.0.0-dev
Are you sure you want to change the base?
vCard 4.0: fix Name Property #146
Conversation
…atory check for fullname
@Danger89 maybe you can help me
|
Ah the name parser was also wrong. So the order was indeed wrong regarding lastname, firstname and additional. It's also a best practice to add some additional unit testers with introducing new code. While the N (Name) SHOULD be present. Is is OK to assume that when N is filled-in, FN can be derived from that? So still ending up in the vCard, without explicitly setting this? Since, this will be my use case. With the option to set the FN manually whenever the user likes to set FN differently. Eg. When However, when both FN & N is not filled-in, only then return an error that FN is mandatory. Or is that already implemented like such 😕 |
@helveticadomes I changed my unit tester on the dev branch, can you pull the new changes from 2.0.0-dev? So I can validate the FN outcome. |
for me that make most sense, or do you think i should not do that? it is implemented that: pull which changes where and how? |
That sounds good indeed!
You already did :). But how to trigger a rebuild on this PR 😕 (lack of knowledge of Github <> Travis integration I admit): |
…atory check for fullname
…es/vcard into feature-fixed-name-property
is it a good idea to also add a correct vcard file to assets? With correct I mean define the We can keep the current vcard asset as well (rename it?), since I think its a good test to validate if the jeroendesloovere/vcard parser is robust enough for parsing vcards files without FN (and only N) -> although its is an invalid Vcard file I think the parser should be robust. |
src/VCard.php
Outdated
if (count($found_name) == 0) { | ||
throw VCardException::forRequiredProperty(new FullName('NoName')); | ||
} else { | ||
$found_fullname[] = new FullName(implode(' ', array_filter(array($found_name[0]->getPrefix(), $found_name[0]->getLastName(), $found_name[0]->getAdditional(), $found_name[0]->getFirstName(), $found_name[0]->getSuffix())))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the result of the fullname of the unit tester ran https://travis-ci.org/jeroendesloovere/vcard/jobs/502040710.
+FN:Mr. van den Berg Antoine Melroy\r\n
This is not correct.
I prefer: Prefix - firstname - additional - lastname - suffix order.
Which should result into:
+FN:Mr. Melroy Antoine van den Berg\r\n
I hope you agree as well regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, fixed that & forcepush was to remove the commits created form a wrong rebase
da3372a
to
17d55da
Compare
lack of knowledge that describe exactly me :-D (git/github/travis) |
…es/vcard into feature-fixed-name-property
No worries. I can either do it myself. Or better, guide you through the process to help you. So next time you do have the ability and skills to do it yourself 🙌 . I like the second approach, and help you. EDIT: I think that unit testing is part of software development. So I think its a good think that can you write & execute them as well. EDIT 2: I requested via @jeroendesloovere a gitter.im community project for vcard, so we could easily chat. Which may help in communication and learn faster. |
…g in the BDAY parser (change production code to fix). The testcases is correct.. 1 error left to fix as well
… mind to validate DateTimeValue class as well!
I fixed the testcases, found yet another bug in the The 'u' format (see Date format in php docs) will return zero's with a date! So that is definitely not the behavior you want. Therefore I urge you to also look to the I also created a |
src/VCard.php
Outdated
if (count($found_name) == 0) { | ||
throw VCardException::forRequiredProperty(new FullName('NoName')); | ||
} else { | ||
$found_fullname[] = new FullName(implode(' ', array_filter(array($found_name[0]->getPrefix(), $found_name[0]->getFirstName(), $found_name[0]->getAdditional(), $found_name[0]->getLastName(), $found_name[0]->getSuffix())))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be made more readable, for example something like:
$found_fullname[] = new FullName(implode(' ', array_filter(array(
$found_name[0]->getPrefix(),
$found_name[0]->getFirstName(),
$found_name[0]->getAdditional(),
$found_name[0]->getLastName(),
$found_name[0]->getSuffix(),
))));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this for helveticadomes.
composer.json
Outdated
}, | ||
"scripts": { | ||
"test": "phpunit tests", | ||
"standard": "phpcs --standard=psr2 --extensions=php --warning-severity=0 --report=full 'src'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use spaces not tabs just like the rest of the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ow oopsy thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lessons learned: never use Gedit, Atom & vim all together 🤣
tests/VCardTest.php
Outdated
private $secondVCard; | ||
protected static $secondVCard; | ||
|
||
/** @var VCards: containing both first & second vcard together */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this not be of the type VCard?
https://github.com/jeroendesloovere/vcard/pull/146/files#diff-fc15453e7e481d3e92f86a7d1d2e7a99R101 here it's set with VCard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also i'm not sure, but i don't believe the : is needed/allowed in the phpdoc specs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya ok its type Vcard.. I wanted to point out this variable stores two vcards together.
I don't know what I was thinking.. I will revert it.
@jeroendesloovere I think it's ready to be merged. |
src/Property/Value/DateTimeValue.php
Outdated
@@ -16,6 +16,7 @@ public function __construct(\DateTime $value) | |||
|
|||
public function __toString(): string | |||
{ | |||
// TODO: possibly not in line with rfc6350 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, somebody could also look to this toString() method. However, this can be done later as well (has nothing to do with the Name property fix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thank you danger89 👍 Plus added an extra UT.
@helveticadomes Do you like to join the Gitter chat? https://gitter.im/vcard-php-library/community |
Ps. |
@@ -17,7 +17,8 @@ public function __construct($value) | |||
public function __toString(): string | |||
{ | |||
if ($this->value instanceof \DateTime) { | |||
return $this->value->format('u'); | |||
// According to DATE-AND-OR-TIME rfc6350 standard | |||
return $this->value->format('Ymd\THis'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also need the z
just like https://github.com/jeroendesloovere/vcard/pull/146/files#diff-0a46c638422a54cb3e31646555c0c263R20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Z could be added indeed.
@@ -17,7 +17,8 @@ public function __construct($value) | |||
public function __toString(): string | |||
{ | |||
if ($this->value instanceof \DateTime) { | |||
return $this->value->format('u'); | |||
// According to DATE-AND-OR-TIME rfc6350 standard | |||
return $this->value->format('Ymd\THis'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also want to raise a point for discussion, I see that in rfc6350 all the references to date and/or time basically say to use ISO 8601.
The thing is that php has a constant for ISO 8601 (DateTimeInterface::ATOM) which has the following syntax: Y-m-d\TH:i:sP (example: 2005-08-15T15:52:01+00:00), but this is different from the examples in rfc6350.
Personally i prefer the DateTimeInterface::ATOM style.
I'm interested in your opinions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@to-be-the-best The RFC6350 says it's BASED ON that ISO standard: and that ISO standard mainly says this is the standard ISO notation: YYYY-MM-DD. Bear in mind that the ISO standard is very brought, and is not specific enough. That is why the RFC6350 is extended this ISO standard, to be more clear.
I'm just looking at the specification of that document:
To allow unambiguous
interpretation, a stand-alone TIME value is always preceded by a "T".Examples for "date-and-or-time":
19961022T140000
So I think the Z
is debatable indeed.
And the ISO 8601 is even revised. And have two different versions ISO/DIS 8601-1
& ISO/DIS 8601-2
.
TLDR;To conclude: Ymd\THis
is OK according to the RFC6350 spec. The RFC standard is based on the ISO standard, but extends that, therefor I like to look to RFC standard only. Since RFC6350 is leading.
Finally, I think '\Z' can be added if you wish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ps. plus we need to do manual test procedures to validate if this notation is indeed working for the most used applications (eg. Outlook, Google Contacts, iCloud, ..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ps. ps. Actually another related discussion I like to have instead, is how to define a PHP class that can be used to only output Ymd
? Since the PHP DateTime()
can be used to store both date & time. So I can only assume now that there WILL be a time included (also 00:00:00 could even be valid) and dump the full date time RFC standard notation into my vcard.
However, it would be nice to have an option to only a date (without time) and time (without date), with the proper toString() implementation for those two cases (together with the full date time case-> already implemented).
Use cases are: Birthday or anniversary, where just a date, without time is sufficient enough in most cases.
if you use PS: i assume we need to add this expection also to VCardTest. |
Indeed the expection needs tests |
Currently its tested indirectly with several testcase like: Line 353 in 9985584
As you can see these tests are not resulting into an exception/error. But indeed you want to have a test that proves the exception is actually trigger also (bad weather test). |
Ready to merge now..? Please say yes ❤️ |
Create issue regarding DateTime to support also a single date or time object (with a proper toString() implementation for these two cases). Currently the DateTime can store both a date and time (even 00:00:00 is a valid time), therefor we always output the full date + time to the vcard file currently. However Google Contacts can't handle this actually, despite the RFC standard. Regarding the birthday:
Please, merge this PR, be more agile! 🍰 Separate issue is created: #148. Otherwise the merges/PRs are getting too big in my opinion. |
fix Name Property (wrong order: FN and N have different orders!)
mandatory check for fullname (fix #113 ) based on #128