mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-31 20:24:21 -04:00
Specify DateTimeStyles when possible
This commit is contained in:
parent
9bb222b408
commit
653df7d8e5
@ -94,7 +94,7 @@ namespace Emby.Server.Implementations.Data
|
|||||||
dateText,
|
dateText,
|
||||||
_datetimeFormats,
|
_datetimeFormats,
|
||||||
DateTimeFormatInfo.InvariantInfo,
|
DateTimeFormatInfo.InvariantInfo,
|
||||||
DateTimeStyles.None).ToUniversalTime();
|
DateTimeStyles.AdjustToUniversal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryReadDateTime(this IReadOnlyList<ResultSetValue> reader, int index, out DateTime result)
|
public static bool TryReadDateTime(this IReadOnlyList<ResultSetValue> reader, int index, out DateTime result)
|
||||||
@ -108,9 +108,9 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
var dateText = item.ToString();
|
var dateText = item.ToString();
|
||||||
|
|
||||||
if (DateTime.TryParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out var dateTimeResult))
|
if (DateTime.TryParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AdjustToUniversal, out var dateTimeResult))
|
||||||
{
|
{
|
||||||
result = dateTimeResult.ToUniversalTime();
|
result = dateTimeResult;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1990,7 +1990,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||||||
|
|
||||||
writer.WriteElementString(
|
writer.WriteElementString(
|
||||||
"dateadded",
|
"dateadded",
|
||||||
DateTime.UtcNow.ToLocalTime().ToString(DateAddedFormat, CultureInfo.InvariantCulture));
|
DateTime.Now.ToString(DateAddedFormat, CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
if (item.ProductionYear.HasValue)
|
if (item.ProductionYear.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -21,10 +21,10 @@ namespace Jellyfin.Api.Controllers
|
|||||||
public ActionResult<UtcTimeResponse> GetUtcTime()
|
public ActionResult<UtcTimeResponse> GetUtcTime()
|
||||||
{
|
{
|
||||||
// Important to keep the following line at the beginning
|
// Important to keep the following line at the beginning
|
||||||
var requestReceptionTime = DateTime.UtcNow.ToUniversalTime();
|
var requestReceptionTime = DateTime.UtcNow;
|
||||||
|
|
||||||
// Important to keep the following line at the end
|
// Important to keep the following line at the end
|
||||||
var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime();
|
var responseTransmissionTime = DateTime.UtcNow;
|
||||||
|
|
||||||
// Implementing NTP on such a high level results in this useless
|
// Implementing NTP on such a high level results in this useless
|
||||||
// information being sent. On the other hand it enables future additions.
|
// information being sent. On the other hand it enables future additions.
|
||||||
|
@ -147,7 +147,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
? _userManager.GetUserById(userId.Value)
|
? _userManager.GetUserById(userId.Value)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
var minPremiereDate = DateTime.Now.Date.ToUniversalTime().AddDays(-1);
|
var minPremiereDate = DateTime.UtcNow.Date.AddDays(-1);
|
||||||
|
|
||||||
var parentIdGuid = parentId ?? Guid.Empty;
|
var parentIdGuid = parentId ?? Guid.Empty;
|
||||||
|
|
||||||
|
@ -145,9 +145,9 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(val))
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
{
|
{
|
||||||
if (DateTime.TryParse(val, out var added))
|
if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var added))
|
||||||
{
|
{
|
||||||
item.DateCreated = added.ToUniversalTime();
|
item.DateCreated = added;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -535,9 +535,9 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(firstAired))
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
||||||
{
|
{
|
||||||
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var airDate) && airDate.Year > 1850)
|
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal, out var airDate) && airDate.Year > 1850)
|
||||||
{
|
{
|
||||||
item.PremiereDate = airDate.ToUniversalTime();
|
item.PremiereDate = airDate;
|
||||||
item.ProductionYear = airDate.Year;
|
item.ProductionYear = airDate.Year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -552,9 +552,9 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(firstAired))
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
||||||
{
|
{
|
||||||
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var airDate) && airDate.Year > 1850)
|
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal, out var airDate) && airDate.Year > 1850)
|
||||||
{
|
{
|
||||||
item.EndDate = airDate.ToUniversalTime();
|
item.EndDate = airDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||||||
public static DateTime? GetDictionaryDateTime(IReadOnlyDictionary<string, string> tags, string key)
|
public static DateTime? GetDictionaryDateTime(IReadOnlyDictionary<string, string> tags, string key)
|
||||||
{
|
{
|
||||||
if (tags.TryGetValue(key, out var val)
|
if (tags.TryGetValue(key, out var val)
|
||||||
&& (DateTime.TryParse(val, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal, out var dateTime)
|
&& (DateTime.TryParse(val, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var dateTime)
|
||||||
|| DateTime.TryParseExact(val, "yyyy", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal, out dateTime)))
|
|| DateTime.TryParseExact(val, "yyyy", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out dateTime)))
|
||||||
{
|
{
|
||||||
return dateTime.ToUniversalTime();
|
return dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -1450,9 +1450,9 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||||||
|
|
||||||
// Credit to MCEBuddy: https://mcebuddy2x.codeplex.com/
|
// Credit to MCEBuddy: https://mcebuddy2x.codeplex.com/
|
||||||
// DateTime is reported along with timezone info (typically Z i.e. UTC hence assume None)
|
// DateTime is reported along with timezone info (typically Z i.e. UTC hence assume None)
|
||||||
if (tags.TryGetValue("WM/MediaOriginalBroadcastDateTime", out var premiereDateString) && DateTime.TryParse(year, null, DateTimeStyles.None, out var parsedDate))
|
if (tags.TryGetValue("WM/MediaOriginalBroadcastDateTime", out var premiereDateString) && DateTime.TryParse(year, null, DateTimeStyles.AdjustToUniversal, out var parsedDate))
|
||||||
{
|
{
|
||||||
video.PremiereDate = parsedDate.ToUniversalTime();
|
video.PremiereDate = parsedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
var description = tags.GetValueOrDefault("WM/SubTitleDescription");
|
var description = tags.GetValueOrDefault("WM/SubTitleDescription");
|
||||||
@ -1468,7 +1468,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||||||
// e.g. -> CBeebies Bedtime Hour. The Mystery: Animated adventures of two friends who live on an island in the middle of the big city. Some of Abney and Teal's favourite objects are missing. [S]
|
// e.g. -> CBeebies Bedtime Hour. The Mystery: Animated adventures of two friends who live on an island in the middle of the big city. Some of Abney and Teal's favourite objects are missing. [S]
|
||||||
if (string.IsNullOrWhiteSpace(subTitle)
|
if (string.IsNullOrWhiteSpace(subTitle)
|
||||||
&& !string.IsNullOrWhiteSpace(description)
|
&& !string.IsNullOrWhiteSpace(description)
|
||||||
&& description.AsSpan()[0..Math.Min(description.Length, MaxSubtitleDescriptionExtractionLength)].IndexOf(':') != -1) // Check within the Subtitle size limit, otherwise from description it can get too long creating an invalid filename
|
&& description.AsSpan()[..Math.Min(description.Length, MaxSubtitleDescriptionExtractionLength)].Contains(':')) // Check within the Subtitle size limit, otherwise from description it can get too long creating an invalid filename
|
||||||
{
|
{
|
||||||
string[] descriptionParts = description.Split(':');
|
string[] descriptionParts = description.Split(':');
|
||||||
if (descriptionParts.Length > 0)
|
if (descriptionParts.Length > 0)
|
||||||
|
@ -268,9 +268,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(val))
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
{
|
{
|
||||||
if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var added))
|
if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var added))
|
||||||
{
|
{
|
||||||
item.DateCreated = added.ToUniversalTime();
|
item.DateCreated = added;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -384,9 +384,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
var val = reader.ReadElementContentAsString();
|
var val = reader.ReadElementContentAsString();
|
||||||
if (!string.IsNullOrWhiteSpace(val) && userData != null)
|
if (!string.IsNullOrWhiteSpace(val) && userData != null)
|
||||||
{
|
{
|
||||||
if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var added))
|
if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var added))
|
||||||
{
|
{
|
||||||
userData.LastPlayedDate = added.ToUniversalTime();
|
userData.LastPlayedDate = added;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -685,9 +685,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(val))
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
{
|
{
|
||||||
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var date) && date.Year > 1850)
|
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var date) && date.Year > 1850)
|
||||||
{
|
{
|
||||||
item.PremiereDate = date.ToUniversalTime();
|
item.PremiereDate = date;
|
||||||
item.ProductionYear = date.Year;
|
item.ProductionYear = date.Year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -703,9 +703,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(val))
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
{
|
{
|
||||||
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var date) && date.Year > 1850)
|
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var date) && date.Year > 1850)
|
||||||
{
|
{
|
||||||
item.EndDate = date.ToUniversalTime();
|
item.EndDate = date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
|
|||||||
Assert.Equal("Album", res.Album);
|
Assert.Equal("Album", res.Album);
|
||||||
Assert.Equal(2021, res.ProductionYear);
|
Assert.Equal(2021, res.ProductionYear);
|
||||||
Assert.True(res.PremiereDate.HasValue);
|
Assert.True(res.PremiereDate.HasValue);
|
||||||
Assert.Equal(DateTime.Parse("2021-01-01T00:00Z", DateTimeFormatInfo.CurrentInfo).ToUniversalTime(), res.PremiereDate);
|
Assert.Equal(DateTime.Parse("2021-01-01T00:00Z", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AdjustToUniversal), res.PremiereDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -85,7 +85,7 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
|
|||||||
Assert.Equal("City to City", res.Album);
|
Assert.Equal("City to City", res.Album);
|
||||||
Assert.Equal(1978, res.ProductionYear);
|
Assert.Equal(1978, res.ProductionYear);
|
||||||
Assert.True(res.PremiereDate.HasValue);
|
Assert.True(res.PremiereDate.HasValue);
|
||||||
Assert.Equal(DateTime.Parse("1978-01-01T00:00Z", DateTimeFormatInfo.CurrentInfo).ToUniversalTime(), res.PremiereDate);
|
Assert.Equal(DateTime.Parse("1978-01-01T00:00Z", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AdjustToUniversal), res.PremiereDate);
|
||||||
Assert.Contains("Electronic", res.Genres);
|
Assert.Contains("Electronic", res.Genres);
|
||||||
Assert.Contains("Ambient", res.Genres);
|
Assert.Contains("Ambient", res.Genres);
|
||||||
Assert.Contains("Pop", res.Genres);
|
Assert.Contains("Pop", res.Genres);
|
||||||
@ -105,7 +105,7 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
|
|||||||
Assert.Equal("Eyes wide open", res.Album);
|
Assert.Equal("Eyes wide open", res.Album);
|
||||||
Assert.Equal(2020, res.ProductionYear);
|
Assert.Equal(2020, res.ProductionYear);
|
||||||
Assert.True(res.PremiereDate.HasValue);
|
Assert.True(res.PremiereDate.HasValue);
|
||||||
Assert.Equal(DateTime.Parse("2020-10-26T00:00Z", DateTimeFormatInfo.CurrentInfo).ToUniversalTime(), res.PremiereDate);
|
Assert.Equal(DateTime.Parse("2020-10-26T00:00Z", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AdjustToUniversal), res.PremiereDate);
|
||||||
Assert.Equal(22, res.People.Length);
|
Assert.Equal(22, res.People.Length);
|
||||||
Assert.Equal("Krysta Youngs", res.People[0].Name);
|
Assert.Equal("Krysta Youngs", res.People[0].Name);
|
||||||
Assert.Equal(PersonType.Composer, res.People[0].Type);
|
Assert.Equal(PersonType.Composer, res.People[0].Type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user