diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c45c2..ac7b0fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v. 1.2.0 +- Changed "QFXparser" class name to "FileParser" +- Changed "Build" method name to "BuildStatement" +- Fixed date conversion for different timezones + ### v. 1.1.0 - Changed "StatementBuilder" class name to "QFXparser" - Changed "Transaction" API diff --git a/QFXparser.TestApp/Program.cs b/QFXparser.TestApp/Program.cs index e8d6f64..c1105eb 100644 --- a/QFXparser.TestApp/Program.cs +++ b/QFXparser.TestApp/Program.cs @@ -9,10 +9,10 @@ static void Main (string[] args) { Console.Write("Type the path of the file you would like to upload: "); string qfxpath = Console.ReadLine();//Directory.GetParent("ofx.qbo").Parent.FullName + "\\Files\\ofx.qbo"; Stream stream = new FileStream(qfxpath, FileMode.Open); - QFXparser parser = new QFXparser(stream); + FileParser parser = new FileParser(stream); Console.WriteLine("Starting to parse..."); - Statement result = parser.Build(); + Statement result = parser.BuildStatement(); var str = JsonConvert.SerializeObject(result); Console.WriteLine(str); Console.ReadLine(); diff --git a/QFXparser/Parser.cs b/QFXparser/Parser.cs index ba27f48..fe4b218 100644 --- a/QFXparser/Parser.cs +++ b/QFXparser/Parser.cs @@ -6,7 +6,7 @@ namespace QFXparser { - public class Parser + internal class Parser { public static IEnumerable Parse(string fileText) { diff --git a/QFXparser/QFXparser.cs b/QFXparser/QFXparser.cs index 9526039..cc57441 100644 --- a/QFXparser/QFXparser.cs +++ b/QFXparser/QFXparser.cs @@ -1,37 +1,32 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using System.Linq; using System.Reflection; -using System.Text; namespace QFXparser { - public class QFXparser - { - - + public class FileParser + { private string _fileText; - public QFXparser(string fileNamePath) + public FileParser(string fileNamePath) { - using (StreamReader sr = new StreamReader(fileNamePath)) + using (StreamReader sr = new StreamReader(fileNamePath,true)) { _fileText = sr.ReadToEnd(); } } - public QFXparser(Stream fileStream) + public FileParser(Stream fileStream) { - using (StreamReader sr = new StreamReader(fileStream)) + using (StreamReader sr = new StreamReader(fileStream,true)) { _fileText = sr.ReadToEnd(); } } - public Statement Build() + public Statement BuildStatement() { RawStatement rawStatement = BuildRaw(); diff --git a/QFXparser/QFXparser.csproj b/QFXparser/QFXparser.csproj index a15ec95..9d400e1 100644 --- a/QFXparser/QFXparser.csproj +++ b/QFXparser/QFXparser.csproj @@ -12,8 +12,8 @@ https://github.com/eramella/QFXparser https://github.com/eramella/QFXparser Github - qfx, financial, parser, quickbooks, dotnet, netstandard2 - 1.1.0 + qfx, financial, parser, quickbooks, dotnet, netstandard2, qbo + 1.2.0 See Changelog: https://github.com/eramella/QFXparser/blob/master/CHANGELOG.md en-US diff --git a/QFXparser/RawTransaction.cs b/QFXparser/RawTransaction.cs index 46f581c..f5ee1df 100644 --- a/QFXparser/RawTransaction.cs +++ b/QFXparser/RawTransaction.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Text.RegularExpressions; namespace QFXparser { @@ -31,12 +32,13 @@ public DateTime DatePosted { get { - var dateStr = PostedOn.Substring(0, 18) + "Z"; - var tzstr = PostedOn.Substring(19).Split(':'); - var timeZoneName = tzstr[1].TrimEnd(']'); - var timeSpan = Convert.ToDouble(tzstr[0]); - var date = DateTimeOffset.ParseExact(dateStr, "yyyyMMddHHmmss.fffZ", CultureInfo.InvariantCulture); - var tzi = TimeZoneInfo.CreateCustomTimeZone(timeZoneName, TimeSpan.FromHours(timeSpan), timeZoneName, timeZoneName); + var dateStr = PostedOn.Substring(0, 12) + "Z"; + Regex regex = new Regex(@"(?<=\[)([^)]+)(?=\])"); + var tzstr = regex.Match(PostedOn).Groups[0].Value; + var tzstrSplit = tzstr.Split(':'); + var timeSpan = Convert.ToDouble(tzstrSplit[0]); + var date = DateTimeOffset.ParseExact(dateStr, "yyyyMMddHHmmZ", CultureInfo.InvariantCulture); + var tzi = TimeZoneInfo.CreateCustomTimeZone(tzstrSplit[1], TimeSpan.FromHours(timeSpan), tzstrSplit[1], tzstrSplit[1]); var newdate = TimeZoneInfo.ConvertTime(date, tzi); return newdate.DateTime; } diff --git a/QFXparser/Token.cs b/QFXparser/Token.cs index 5ea6d55..75ec08a 100644 --- a/QFXparser/Token.cs +++ b/QFXparser/Token.cs @@ -2,7 +2,7 @@ namespace QFXparser { - public class Token + internal class Token { private StringBuilder _content; diff --git a/README.md b/README.md index fc4da6d..bea8744 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,10 @@ Pass to the library a file path or a Strem and it will return a "Statement" obje Example: ```csharp -QFXparser parser = new QFXparser("C:\\filename.qbo"); -Statement result = parser.Build(); +using QFXparser; + +FileParser parser = new FileParser("C:\\filename.qbo"); +Statement result = parser.BuildStatement(); ``` The returned objects are: