Peter-Schorn / SpotifyAPI

A Swift library for the Spotify web API. Supports all endpoints.
https://peter-schorn.github.io/SpotifyAPI/documentation/spotifywebapi
MIT License
251 stars 32 forks source link

Decoder error when release year is `0000` #37

Closed shaundon closed 2 years ago

shaundon commented 2 years ago

Bit of a strange one, but I noticed that a SpotifyDecodingError happens when an album has a release date of 0000, like this album: https://open.spotify.com/album/5QDyhsfWwW2783pyaDjV6J

This is clearly an error on Spotify's side, but I was wondering if there's a way to make SpotifyAPI more resilient to this happening in some way. The issue at the moment is that it means the entire page of results is lost, not just this one track

Peter-Schorn commented 2 years ago

The only workaround for this problem is to set the Album.releaseDate (and other properties decoded from date-strings) to nil when the date-string cannot be parsed from the JSON data. I think this is an acceptable solution here because if Spotify returns a date-string with an invalid format, there's nothing the client can do about it. Expect a new version with this change shortly.

Also, as an aside, the year 0 does not exist in the Gregorian calendar; it goes from 1 B.C. to 1 A.D. This is why "0000" is always invalid when parsing date-strings using the Unicode Technical Standard #35, although not for ISO 8601, in which 0 represents 1 B.C.

Peter-Schorn commented 2 years ago

I have pushed a new version with this change: 067861d89cd73be129259e4edb607d822ff63d45.

shaundon commented 2 years ago

Thanks so much! It's unfortunate that Spotify has this bug, but at least there's a workaround.