diff --git a/CHANGELOG.md b/CHANGELOG.md index 08932ec..67316fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `ssl-certificate` will be documented in this file +## 1.19.0 - 2020-03-21 + +- add lifespan in days + ## 1.18.0 - 2020-03-18 - get details from a certificate from string (#123) diff --git a/README.md b/README.md index 62a38d4..ed21560 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,9 @@ $certificate = SslCertificate::createFromString($certificateData); $certificate->getIssuer(); // returns "Let's Encrypt Authority X3" $certificate->isValid(); // returns true if the certificate is currently valid -$certificate->expirationDate(); // returns an instance of Carbon +$certificate->validFromDate(); // returns a Carbon instance Carbon +$certificate->expirationDate(); // returns a Carbon instance Carbon +$certificate->lifespanInDays(); // return the amount of days between validFromDate and expirationDate $certificate->expirationDate()->diffInDays(); // returns an int $certificate->getSignatureAlgorithm(); // returns a string $certificate->getOrganization(); // returns the organization name when available diff --git a/src/SslCertificate.php b/src/SslCertificate.php index 9e89c56..5f34bcd 100644 --- a/src/SslCertificate.php +++ b/src/SslCertificate.php @@ -134,6 +134,11 @@ public function expirationDate(): Carbon return Carbon::createFromTimestampUTC($this->rawCertificateFields['validTo_time_t']); } + public function lifespanInDays(): int + { + return $this->validFromDate()->diffInDays($this->expirationDate()); + } + public function isExpired(): bool { return $this->expirationDate()->isPast(); diff --git a/tests/SslCertificateTest.php b/tests/SslCertificateTest.php index e167bdc..778cd18 100644 --- a/tests/SslCertificateTest.php +++ b/tests/SslCertificateTest.php @@ -79,6 +79,12 @@ public function it_can_determine_the_expiration_date() $this->assertSame('2016-08-17 16:50:00', $this->certificate->expirationDate()->format('Y-m-d H:i:s')); } + /** @test */ + public function it_can_determine_the_lifespan_in_days() + { + $this->assertEquals(90, $this->certificate->lifespanInDays()); + } + /** @test */ public function it_can_determine_if_the_certificate_is_valid() {