Skip to content

Commit

Permalink
Merge pull request #84 from anion0278/dev
Browse files Browse the repository at this point in the history
Attempt to fix date parsing
  • Loading branch information
anion0278 authored Apr 23, 2024
2 parents 8dcad36 + df8db98 commit 4eb34a6
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public CultureInfo DateCultureInfo
{
if (_dataCultureInfo == null)
{
_dataCultureInfo = new CultureInfo(DateCultureInfoName);
_dataCultureInfo = new CultureInfo(DateCultureInfoName, false);
if (_timeSeparatorOverride != null)
{
_dataCultureInfo.DateTimeFormat.TimeSeparator = _timeSeparatorOverride;
}
if (NumericFormatSourceCultureName != null)
{
var numbericCultureInfo = new CultureInfo(NumericFormatSourceCultureName);
var numbericCultureInfo = new CultureInfo(NumericFormatSourceCultureName, false);
_dataCultureInfo.NumberFormat = numbericCultureInfo.NumberFormat;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private IReadOnlyList<string[]> GetFileLines(string fileName, string encodingCod

private DateTime ParseDate(string dateString, MarketPlaceTransactionsConfig config)
{
// TODO use CultureDependentValueParser
var match = Regex.Match(dateString, config.DateSubstring);
return DateTime.Parse(match.Groups[1].Value, config.DateCultureInfo);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0740000002001353907Czech Goods s.r.o. 01111900000013280900+00000016514842+000000461730770000000494070190011300424FIO
0750000002001353908000000000000000000000000000000000000026992951669712700000000000000000000000000408-0091951-6697127000124050224
07500000020013539080000000000000000000000000000000000001062710000000000000000000000000000000000000000000000000000000000124170224
0750000002001353908000000000000000000000000000000000000026992290539393600000000000000000000000000408-2472290-5393936000124230224
0750000002001353908000000000000000000000000000000000000062002070906676300000000000000000000000000405-7042070-9066763000124260224
0750000002001353915000000000000000000000000000000000000026992951669712700000000000000000000000000408-0091951-6697127000124050224
07500000020013539150000000000000000000000000000000000001062710000000000000000000000000000000000000000000000000000000000124170224
0750000002001353915000000000000000000000000000000000000026992290539393600000000000000000000000000408-2472290-5393936000124230224
0750000002001353915000000000000000000000000000000000000062002070906676300000000000000000000000000405-7042070-9066763000124260224

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions Mapp.BusinessLogic.Transactions.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public async Task ConvertTransactions_ParsesAndConvertsTransactions_AmazonFR()
await IntegrationTestBase("AmazonFR");
}

[Fact]
public async Task ConvertTransactions_ParsesAndConvertsTransactions_AmazonGB()
{
await IntegrationTestBase("AmazonGB");
}

[Fact]
public async Task ConvertTransactions_ParsesAndConvertsTransactions_AmazonIT()
{
Expand Down Expand Up @@ -115,20 +121,12 @@ public async Task ConvertTransactions_ParsesAndConvertsTransactions_AmazonSG()
await IntegrationTestBase("AmazonSG");
}

[Fact]
public async Task ConvertTransactions_ParsesAndConvertsTransactions_AmazonUK()
{
await IntegrationTestBase("AmazonUK");
}

[Fact]
public async Task ConvertTransactions_ParsesAndConvertsTransactions_AmazonUS()
{
await IntegrationTestBase("AmazonUS");
}



[Fact]
[Bug]
public async Task ConvertTransactions_ParsesAndConvertsTransactions_ZerosBug()
Expand Down
21 changes: 14 additions & 7 deletions Mapp.BusinessLogic.Transactions.Tests/TransactionsReaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Xunit;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using Xunit;

namespace Mapp.Business
{
Expand Down Expand Up @@ -70,13 +74,16 @@ public void Read_Given_Returns()
//}

//[Fact]
//public void ParseFrDate()
//public void ParseMxDate()
//{
// var reader = new TransactionsReader(new JsonManager());

// var result = reader.ParseDate("2 déc. 2019 08:04:58 UTC+00:00", @"(.*) UTC", new CultureInfo("fr-FR"));

// Assert.Equal(new DateTime(2019, 12, 2, 8, 4, 58), result);
// Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("");
// //var result = DateTime.Parse("2 déc. 2019 08:04:58", new CultureInfo(""));
// //var result2 = DateTime.Parse("12 févr. 2024 07:52:56", new CultureInfo("es-MX"));
// //var result = DateTime.Parse("8 feb 2024 23:25:40 GMT-8", new CultureInfo(""));
// var result2 = DateTime.Parse("8 feb 2024 23:25:40", new CultureInfo("es-MX"));

// Debugger.Break();
// //Assert.Equal(new DateTime(2019, 12, 2, 8, 4, 58), result);
//}

//[Fact]
Expand Down
35 changes: 35 additions & 0 deletions Mapp.DataAccess/ICultureDependentValueParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mapp.DataAccess
{
public interface IValueParser
{
decimal ParseDecimal(string value);
DateTime ParseDateTime(string value);
}

public class CultureDependentValueParser : IValueParser
{
public CultureInfo CultureInfo { get; }

public CultureDependentValueParser(CultureInfo cultureInfo)
{
CultureInfo = cultureInfo;
}

public DateTime ParseDateTime(string value)
{
return DateTime.Parse(value, CultureInfo);
}

public decimal ParseDecimal(string value)
{
return decimal.Parse(value, CultureInfo);
}
}
}
2 changes: 1 addition & 1 deletion Mapp.UI/Mapp.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
<Deterministic>false</Deterministic>
<PackageId>Mapp</PackageId>
<AssemblyName>Mapp.UI</AssemblyName>
<AssemblyName>Mapp</AssemblyName>
<NeutralLanguage>en</NeutralLanguage>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"LinesToSkipBeforeColumnNames": 7,
"MarketPlaceId": 8,
"MarketPlaceId": 15,
"DistinctionPhrases": [ "Tous les montants sont en EUR, sauf indication contraire" ],
"DateSubstring": "(.*) (UTC|GMT).*",
"TimeSeparatorOverride": null,
Expand Down
2 changes: 1 addition & 1 deletion Mapp.UI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

lex:LocalizeDictionary.DesignCulture="en"
lex:LocalizeDictionary.OutputMissingKeys="True"
lex:ResxLocalizationProvider.DefaultAssembly="Mapp.UI"
lex:ResxLocalizationProvider.DefaultAssembly="Mapp"
lex:ResxLocalizationProvider.DefaultDictionary="LocalizationStrings">

<b:Interaction.Behaviors>
Expand Down
2 changes: 0 additions & 2 deletions Mapp.UI/Views/TransactionsConverterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
xmlns:local="clr-namespace:Mapp.UI.Views"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
mc:Ignorable="d"
lex:ResxLocalizationProvider.DefaultAssembly="Mapp.UI"
lex:ResxLocalizationProvider.DefaultDictionary="LocalizationStrings"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
Expand Down

0 comments on commit 4eb34a6

Please sign in to comment.