Skip to content

Commit

Permalink
- Fixed date parsing error
Browse files Browse the repository at this point in the history
- Change main class and method names
  • Loading branch information
eramella committed Feb 27, 2018
1 parent c311392 commit 527ee51
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions QFXparser.TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion QFXparser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace QFXparser
{
public class Parser
internal class Parser
{
public static IEnumerable<Token> Parse(string fileText)
{
Expand Down
21 changes: 8 additions & 13 deletions QFXparser/QFXparser.cs
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
4 changes: 2 additions & 2 deletions QFXparser/QFXparser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageProjectUrl>https://github.com/eramella/QFXparser</PackageProjectUrl>
<RepositoryUrl>https://github.com/eramella/QFXparser</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
<PackageTags>qfx, financial, parser, quickbooks, dotnet, netstandard2</PackageTags>
<Version>1.1.0</Version>
<PackageTags>qfx, financial, parser, quickbooks, dotnet, netstandard2, qbo</PackageTags>
<Version>1.2.0</Version>
<PackageReleaseNotes>See Changelog:
https://github.com/eramella/QFXparser/blob/master/CHANGELOG.md</PackageReleaseNotes>
<NeutralLanguage>en-US</NeutralLanguage>
Expand Down
14 changes: 8 additions & 6 deletions QFXparser/RawTransaction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;

namespace QFXparser
{
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion QFXparser/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace QFXparser
{
public class Token
internal class Token
{
private StringBuilder _content;

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 527ee51

Please sign in to comment.