Skip to content

Commit 067fa72

Browse files
authored
Merge pull request #4 from contentful/feat/datetime-json
Make DateTimeImmutable implement \JsonSerializable
2 parents 74e2186 + 9f1f94b commit 067fa72

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ after_success:
8080
# We generate API docs only for the build lead (to avoid wasting time on all builds),
8181
# and when on merges to master, which is the result of this condition and the setting
8282
# branches: only: master above.
83-
if [[ ($TRAVIS_PULL_REQUEST == false || $TRAVIS_TAG != false) && $BUILD_LEAD == 1 ]]
83+
if [[ ($TRAVIS_PULL_REQUEST == false || $TRAVIS_TAG != '') && $BUILD_LEAD == 1 ]]
8484
then
8585
sh ./scripts/prepare-docs.sh
8686
fi
@@ -91,7 +91,7 @@ deploy:
9191
github_token: $GITHUB_TOKEN
9292
local_dir: build/docs
9393
on:
94-
condition: ($TRAVIS_PULL_REQUEST == false || $TRAVIS_TAG != false) && $BUILD_LEAD == 1
94+
condition: ($TRAVIS_PULL_REQUEST == false || $TRAVIS_TAG != '') && $BUILD_LEAD == 1
9595

9696
notifications:
9797
slack:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# contentful-core.php
22

3-
[![Packagist](https://img.shields.io/packagist/v/contentful/contentful-core.svg?style=flat-square)](https://packagist.org/packages/contentful/contentful-core.php)
4-
[![Travis](https://img.shields.io/travis/contentful/contentful-core.php.svg?style=flat-square)](https://travis-ci.org/contentful/contentful-core.php)
5-
[![Packagist](https://img.shields.io/github/license/contentful/contentful-core.php.svg?style=flat-square)](https://packagist.org/packages/contentful/contentful-core.php)
6-
[![Code Climate](https://img.shields.io/codeclimate/github/contentful/contentful-core.php.svg?style=flat-square)](https://codeclimate.com/github/contentful/contentful-core.php)
7-
[![Codecov](https://img.shields.io/codecov/c/github/contentful/contentful-core.php.svg?style=flat-square)](https://codecov.io/gh/contentful/contentful-core.php)
3+
[![Packagist](https://img.shields.io/packagist/v/contentful/core.svg?style=for-the-badge)](https://packagist.org/packages/contentful/core)
4+
[![PHP from Packagist](https://img.shields.io/packagist/php-v/contentful/core.svg?style=for-the-badge)](https://packagist.org/packages/contentful/core)
5+
[![Travis](https://img.shields.io/travis/contentful/contentful-core.php.svg?style=for-the-badge)](https://travis-ci.org/contentful/contentful-core.php)
6+
[![Packagist](https://img.shields.io/github/license/contentful/contentful-core.php.svg?style=for-the-badge)](https://packagist.org/packages/contentful/contentful-core.php)
7+
[![Codecov](https://img.shields.io/codecov/c/github/contentful/contentful-core.php.svg?style=for-the-badge)](https://codecov.io/gh/contentful/contentful-core.php)
88

99
## What is Contentful?
1010

src/Api/DateTimeImmutable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* This class is used for easier conversion to a timestamp that works with Contentful.
1616
*/
17-
class DateTimeImmutable extends \DateTimeImmutable
17+
class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
1818
{
1919
/**
2020
* Formats the string for an easier interoperability with Contentful.
@@ -43,4 +43,14 @@ public function __toString()
4343
{
4444
return $this->formatForJson();
4545
}
46+
47+
/**
48+
* Returns a JSON representation of the current object.
49+
*
50+
* @return string
51+
*/
52+
public function jsonSerialize()
53+
{
54+
return $this->formatForJson();
55+
}
4656
}

tests/Unit/Api/DateTimeImmutableTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public function testStringRepresentation()
2525

2626
$this->assertSame('1988-09-19T00:00:00Z', $date->formatForJson());
2727
$this->assertSame('1988-09-19T00:00:00Z', (string) $date);
28+
$this->assertSame('"1988-09-19T00:00:00Z"', \json_encode($date));
2829
}
2930
}

0 commit comments

Comments
 (0)