-
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
Support Time and Date solely next to DateTime (2.0.0-dev) #148
Comments
could we use use //--- instead ---//
new DateTime('2015-12-05');
//--- something like this ---//
date("Ymd", strtotime('2015-12-05')); or will this create other issues? |
@helveticadomes Well, yes this will solve the fact you solely have a date. But now you can't support date + time (which should also be possible in some cases) 😢 .
As you can see here. A check is used to validate if the object is of time DateTime. If true, it will return a valid DATE-AND-OR-TIME rfc6350 format. What you actually want is keep supporting this behavior (date + time behavior I mean), and on top of that support Time (without date). And support Date (without time). This can be done in my eyes, by inheriting the DateTime class (thus use DateTime as base class) for example. An create your own 'Date' class and 'Time' class. In that case we could re-use DateTimeOrStringValue class/DateTimeOrStringValue.php. class Date extends \DateTime {
//empty
}
class Time extends \DateTime {
//empty
} And extend if ($this->value instanceof \DateTime) {
// According to DATE-AND-OR-TIME rfc6350 standard
return $this->value->format('Ymd\THis');
elseif ($this->value instanceof Time) {
return $this->value->format('\THis');
}
elseif ($this->value instanceof Date) {
return $this->value->format('Ymd');
} else {
return $this->value;
} I hope I make sense? Another alternative would be to extend it DateTime fully, and vcard project should not use DateTime directly anymore (which I also really like in modularity kind of view). So we have DateAndTime, Date and Time classes: class DateAndTime extends \DateTime {
public function __toString() {
return $this->format('Ymd\THis');
}
}
class Date extends \DateTime {
public function __toString() {
return $this->format('Ymd');
}
}
class Time extends \DateTime {
public function __toString() {
return $this->format('\THis');
}
} In this last example DateTimeOrStringValue class properly is much easier in that case/should not contain any logic anymore. Since you just inherent the to_string already. Maybe only My guess would be the whole
In fact, if we implement those three classes, we can properly get rid of this whole DateTimeOrStringValue.php file totally? |
Currently with the 2.0.0-dev branch, the birthday, anniversary you need to specify a
new \DateTime
as constructor parameter.The problem with this, is you can't specify a date only (without time). Resulting in a vcard output (file) with a full date + time (
yyyymmddThhmmssZ
), which is not always wanted.Eg. for a birthday the date is enough, which should result in
yyyymmdd
only.This discussion was started in #146. But I like to solve this within another PR.
Solution Branch:
2.0.0-dev
The text was updated successfully, but these errors were encountered: