Skip to content

Commit

Permalink
fix (technical): Improved some of the date time parsing handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Jun 15, 2022
1 parent f858c88 commit 20bbe92
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/Ombi.Core/Engine/TvSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,36 @@ public async Task<SearchTvShowViewModel> GetShowInformation(string tvdbid, Cance
SeasonNumber = e.season,
Episodes = new List<EpisodeRequests>()
};
var hasAirDate = e.airstamp.HasValue();
var airDate = DateTime.MinValue;
if (hasAirDate)
{
hasAirDate = DateTime.TryParse(e.airdate, out airDate);
}
newSeason.Episodes.Add(new EpisodeRequests
{
Url = e.url.ToHttpsUrl(),
Title = e.name,
AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue,
AirDate = airDate,
EpisodeNumber = e.number,

});
mapped.SeasonRequests.Add(newSeason);
}
else
{
var hasAirDate = e.airstamp.HasValue();
var airDate = DateTime.MinValue;
if (hasAirDate)
{
hasAirDate = DateTime.TryParse(e.airdate, out airDate);
}
// We already have the season, so just add the episode
season.Episodes.Add(new EpisodeRequests
{
Url = e.url.ToHttpsUrl(),
Title = e.name,
AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue,
AirDate = airDate,
EpisodeNumber = e.number,
});
}
Expand Down
16 changes: 14 additions & 2 deletions src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,24 +272,36 @@ private static void MapSeasons(List<SeasonRequests> seasonRequests, Season tvSea
Overview = tvSeason.overview,
Episodes = new List<EpisodeRequests>()
};
var hasAirDate = episode.air_date.HasValue();
var airDate = DateTime.MinValue;
if (hasAirDate)
{
DateTime.TryParse(episode.air_date, out airDate);
}
newSeason.Episodes.Add(new EpisodeRequests
{
//Url = episode...ToHttpsUrl(),
Title = episode.name,
AirDate = episode.air_date.HasValue() ? DateTime.Parse(episode.air_date) : DateTime.MinValue,
AirDate = airDate,
EpisodeNumber = episode.episode_number,

});
seasonRequests.Add(newSeason);
}
else
{
var hasAirDate = episode.air_date.HasValue();
var airDate = DateTime.MinValue;
if (hasAirDate)
{
DateTime.TryParse(episode.air_date, out airDate);
}
// We already have the season, so just add the episode
season.Episodes.Add(new EpisodeRequests
{
//Url = e.url.ToHttpsUrl(),
Title = episode.name,
AirDate = episode.air_date.HasValue() ? DateTime.Parse(episode.air_date) : DateTime.MinValue,
AirDate = airDate,
EpisodeNumber = episode.episode_number,
});
}
Expand Down
11 changes: 9 additions & 2 deletions src/Ombi.Core/Helpers/TvShowRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,16 @@ public TvShowRequestBuilder CreateNewRequest(TvRequestViewModel tv)
return this;
}

private DateTime FormatDate(string date)
private static DateTime FormatDate(string date)
{
return string.IsNullOrEmpty(date) ? DateTime.MinValue : DateTime.Parse(date);
if (date.HasValue())
{
if (DateTime.TryParse(date, out var d))
{
return d;
}
}
return DateTime.MinValue;
}
}
}
11 changes: 9 additions & 2 deletions src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,16 @@ public TvShowRequestBuilderV2 CreateNewRequest(TvRequestViewModelV2 tv, int root
return this;
}

private DateTime FormatDate(string date)
private static DateTime FormatDate(string date)
{
return string.IsNullOrEmpty(date) ? DateTime.MinValue : DateTime.Parse(date);
if (date.HasValue())
{
if (DateTime.TryParse(date, out var d))
{
return d;
}
}
return DateTime.MinValue;
}
}
}

0 comments on commit 20bbe92

Please sign in to comment.