Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 21, 2020
1 parent ef46c72 commit edd496d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/SslCertificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions tests/SslCertificateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit edd496d

Please sign in to comment.