kevuo / lastfm-sharp

Automatically exported from code.google.com/p/lastfm-sharp
GNU General Public License v3.0
0 stars 0 forks source link

Album.GetReleaseDate() exception #7

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Release date can be empty in xml string. DateTime.parse throws an 
exception.

Possible fix (check for empty value, return Nullable DateTime)

        /// <summary>
        /// Returns the album's release date.
        /// </summary>
        /// <returns>
        /// A <see cref="DateTime"/>
        /// </returns>
        public DateTime? GetReleaseDate()
        {
            XmlDocument doc = request("album.getInfo");
          string releaseDate = extract(doc, "releasedate");
      if (!string.IsNullOrEmpty(releaseDate))
            return DateTime.Parse(releaseDate);

          return null;
        }

Maybe even do a DateTime.TryParse

Original issue reported on code.google.com by mkrijten...@gmail.com on 28 Apr 2010 at 8:17