Skip to content

Commit a10c666

Browse files
committed
Fixed date separator should respect the provided CultureInfo. Added new netstandard2.0 target to access date separator without workaround. Closes #15
1 parent ff914bc commit a10c666

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ test_script:
1212
dotnet test test\ExcelNumberFormat.Tests\ExcelNumberFormat.Tests.csproj --no-build --logger "trx;LogFileName=tests.trx" -c $Env:CONFIGURATION
1313
# upload results to AppVeyor
1414
$wc = New-Object 'System.Net.WebClient'
15-
$wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test\ExcelNumberFormat.Tests\TestResults\tests.trx))
15+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test\ExcelNumberFormat.Tests\TestResults\tests*.trx))
1616
artifacts:
1717
- path: '**\*.nupkg'

src/ExcelNumberFormat/ExcelNumberFormat.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net20;netstandard1.0</TargetFrameworks>
5-
<VersionPrefix>1.0.5</VersionPrefix>
4+
<TargetFrameworks>net20;netstandard1.0;netstandard2.0</TargetFrameworks>
5+
<VersionPrefix>1.0.6</VersionPrefix>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Description>.NET library to parse ECMA-376 number format strings and format values like Excel and other spreadsheet softwares.</Description>

src/ExcelNumberFormat/Formatter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ private static string FormatDate(DateTime date, List<string> tokens, CultureInfo
250250
var digits = token.Length - 1;
251251
result.Append("." + value.ToString("D" + digits));
252252
}
253+
else if (token == "/")
254+
{
255+
#if NETSTANDARD1_0
256+
result.Append(DateTime.MaxValue.ToString("/d", culture)[0]);
257+
#else
258+
result.Append(culture.DateTimeFormat.DateSeparator);
259+
#endif
260+
}
253261
else
254262
{
255263
FormatLiteral(token, result);

test/ExcelNumberFormat.Tests/Class1.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@ public void TestThousandSeparatorCulture()
437437
Assert.AreEqual("0.001.469,07", actual);
438438
}
439439

440+
[TestMethod]
441+
[TestCase("da-DK", "17-08-1978")]
442+
[TestCase("en-US", "17/08/1978")]
443+
[TestCase("bg-BG", "17.08.1978")]
444+
[TestCase("nb-NO", "17.08.1978")]
445+
public void TestDateSeparatorCulture(string cultureName, string expected)
446+
{
447+
var actual = Format(new DateTime(1978, 8, 17), "DD/MM/YYYY", new CultureInfo(cultureName));
448+
Assert.AreEqual(expected, actual);
449+
}
450+
440451
void TestValid(string format)
441452
{
442453
var to = new NumberFormat(format);

0 commit comments

Comments
 (0)