Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  consider the albums to be released at midnight
  record label is not always provided
  day of release may not always be set
  • Loading branch information
Baptouuuu committed Apr 13, 2020
2 parents 0010e49 + db17693 commit f9e2a7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/SDK/Catalog/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Innmind\Immutable\{
Set,
Sequence,
Str,
};

final class Catalog implements CatalogInterface
Expand Down Expand Up @@ -76,6 +77,18 @@ public function album(Album\Id $id): Album
$textColor2 = $attributes['artwork']['textColor2'] ?? null;
$textColor3 = $attributes['artwork']['textColor3'] ?? null;
$textColor4 = $attributes['artwork']['textColor4'] ?? null;
$releaseDate = $attributes['releaseDate'];

if (Str::of($releaseDate)->matches('~^\d{4}$~')) {
// like in the case of this EP https://music.apple.com/fr/album/rip-it-up-ep/213587444
// only the year is provided, and Apple Music interprets this as
// january 1st
$releaseDate .= '-01-01';
}

if (Str::of($releaseDate)->matches('~^\d{4}-\d{2}-\d{2}$~')) {
$releaseDate .= ' 00:00:00';
}

return new Album(
$id,
Expand All @@ -102,8 +115,8 @@ public function album(Album\Id $id): Album
$resource['data'][0]['relationships']['tracks']['data'],
)),
$attributes['isMasteredForItunes'],
$this->clock->at($attributes['releaseDate']),
new Album\RecordLabel($attributes['recordLabel']),
$this->clock->at($releaseDate),
new Album\RecordLabel($attributes['recordLabel'] ?? ''),
new Album\Copyright($attributes['copyright'] ?? ''),
new Album\EditorialNotes(
$attributes['editorialNotes']['standard'] ?? '',
Expand Down
4 changes: 3 additions & 1 deletion tests/SDK/Catalog/CatalogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Innmind\TimeContinuum\{
Clock,
PointInTime,
Earth,
Format,
};
use Innmind\HttpTransport\Transport;
use Innmind\Http\{
Expand Down Expand Up @@ -792,7 +794,7 @@ public function testAlbum()
$clock
->expects($this->once())
->method('at')
->with('1984-06-04')
->with('1984-06-04 00:00:00')
->willReturn($release = $this->createMock(PointInTime::class));

$album = $catalog->album($id);
Expand Down

0 comments on commit f9e2a7d

Please sign in to comment.