From d2eba284eced16843929b46a3b7919eccab44e08 Mon Sep 17 00:00:00 2001 From: freek Date: Fri, 25 Aug 2017 13:42:34 +0200 Subject: [PATCH] commit --- CHANGELOG.md | 4 ++++ src/SslCertificate.php | 9 +++++++++ tests/SslCertificateTest.php | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10e2b94..7484a5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `ssl-certificate` will be documented in this file +## 1.7.0 - 2017-08-28 + +- add `getDaysUntilExpirationDate` + ## 1.6.0 - 2017-08-23 - add `getDomains` diff --git a/src/SslCertificate.php b/src/SslCertificate.php index 3e172b9..7ae15a2 100644 --- a/src/SslCertificate.php +++ b/src/SslCertificate.php @@ -92,6 +92,15 @@ public function isValidUntil(Carbon $carbon, string $url = null): bool return $this->isValid($url); } + public function daysUntilExpirationDate(): int + { + $endDate = $this->expirationDate(); + + $interval = Carbon::now()->diff($endDate); + + return (int)$interval->format("%r%a"); + } + public function getDomains(): array { return array_filter(array_merge([$this->getDomain()], $this->getAdditionalDomains())); diff --git a/tests/SslCertificateTest.php b/tests/SslCertificateTest.php index 60c8e27..adaa24f 100644 --- a/tests/SslCertificateTest.php +++ b/tests/SslCertificateTest.php @@ -210,4 +210,10 @@ public function it_can_get_all_domains() 3 => '*.otherdomain.com', ], $this->certificate->getDomains()); } + + /** @test */ + public function it_can_get_the_days_until_the_expiration_date() + { + $this->assertEquals(77, $this->certificate->daysUntilExpirationDate()); + } }