Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Culture sensitivity #266

Merged
merged 1 commit into from Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .editorconfig
Expand Up @@ -222,10 +222,10 @@ dotnet_diagnostic.CA1303.severity = none # Literal stri
# working around bug
dotnet_diagnostic.RS0041.severity = none # Public members should not use oblivious types

# TODO review these diagnostics as many/all are probably valid
dotnet_diagnostic.CA1304.severity = none # Method behaviour depends upon user's locale
dotnet_diagnostic.CA1305.severity = none # Method behaviour depends upon user's locale
dotnet_diagnostic.CA1307.severity = none # Method behaviour depends upon user's locale
Comment on lines -226 to -228
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the default "warning" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got warnings. The docs categorizes the rules as globalization warnings.

# TODO review these diagnostics as many/all are probably valid, keep current output behavior (english text with localized numbers)
dotnet_diagnostic.CA1304.severity = none # Method behaviour depends upon user's locale (specify CultureInfo f.e. ToLower())
dotnet_diagnostic.CA1305.severity = none # Method behaviour depends upon user's locale (specify IFormatProvider f.e. ToString())
dotnet_diagnostic.CA1307.severity = none # Method behaviour depends upon user's locale (specify StringComparison f.e. StartsWith(), Equals())

# TODO fix these
dotnet_diagnostic.CA1825.severity = none # Avoid unnecessary zero-length array allocations
Expand Down
6 changes: 5 additions & 1 deletion MetadataExtractor.Tests/DirectoryTest.cs
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using MetadataExtractor.Formats.Exif;
using Xunit;
Expand Down Expand Up @@ -103,9 +104,12 @@ public void SetAndGetIntArray()
[InlineData("2002-01-30", 2002, 1, 30, 0, 0, 0, 0, DateTimeKind.Unspecified)]
[InlineData("2002-01", 2002, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)]
[InlineData("2002", 2002, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)]
[InlineData("2002-01-30T23:59:59.099-08:00", 2002, 1, 31, 7, 59, 59, 99, DateTimeKind.Utc, "ar")]
#pragma warning restore format
public void SetStringAndGetDate(string str, int year, int month, int day, int hour, int minute, int second, int milli, DateTimeKind kind)
public void SetStringAndGetDate(string str, int year, int month, int day, int hour, int minute, int second, int milli, DateTimeKind kind, string? culture = null)
{
CultureInfo.CurrentCulture = string.IsNullOrWhiteSpace(culture) ? CultureInfo.CurrentCulture : CultureInfo.GetCultureInfo(culture);

_directory.Set(1, str);

var expected = new DateTime(year, month, day, hour, minute, second, milli, kind);
Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractor/DirectoryExtensions.cs
Expand Up @@ -662,7 +662,7 @@ public static bool TryGetDateTime(this Directory directory, int tagType /*, Time

if (s != null)
{
if (DateTime.TryParseExact(s, _datePatterns, null, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AdjustToUniversal, out dateTime))
if (DateTime.TryParseExact(s, _datePatterns, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AdjustToUniversal, out dateTime))
{
return true;
}
Expand Down