Skip to content

Commit

Permalink
Fix #19. QuickBooks does not handle UTC time properly, so we should h…
Browse files Browse the repository at this point in the history
…ave a way to handle timezone for the developer
  • Loading branch information
jsgoupil committed Feb 1, 2019
1 parent 2921228 commit 158b4d5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/QbXml/Objects/Types/DATETIMETYPE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override string ToString()
// QuickBooks doesn't support Z format.
if (k == "Z")
{
k = string.Empty;
k = "+00:00";
}

return value.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture) + k;
Expand Down
4 changes: 2 additions & 2 deletions src/QbXml/QbXml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<Description>Create requests and parse responses from QuickBooks QbXml.</Description>
<Author>Jean-Sébastien Goupil</Author>
<Authors>Jean-Sébastien Goupil</Authors>
<Copyright>Copyright © Jean-Sébastien Goupil 2018</Copyright>
<Version>0.1.0</Version>
<Copyright>Copyright © Jean-Sébastien Goupil 2015-2019</Copyright>
<Version>0.1.1</Version>
<AssemblyName>QbSync.QbXml</AssemblyName>
<RootNamespace>QbSync.QbXml</RootNamespace>
<PackageId>QbSync.QbXml</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion test/QbXml.Tests/QbXml.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
<Title>QbXml.Tests</Title>
<Author>Jean-Sébastien Goupil</Author>
<Copyright>Copyright © Jean-Sébastien Goupil 2018</Copyright>
<Copyright>Copyright © Jean-Sébastien Goupil 2015-2019</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
Expand Down
25 changes: 22 additions & 3 deletions test/QbXml.Tests/Types/DateTimeTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using QbSync.QbXml.Objects;
using QbSync.QbXml.Tests.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QbSync.QbXml.Tests.Types
{
Expand Down Expand Up @@ -44,5 +41,27 @@ public void DateTimeInvalidSentByQuickBooks()

Assert.AreEqual(DateTime.MinValue, dt.ToDateTime());
}

[Test]
public void DateTimeLocalToString()
{
var utcDateTime = new DateTime(2015, 4, 3, 10, 6, 17, DateTimeKind.Utc);
var timeZoneInfo = QuickBooksTestHelper.GetPacificStandardTimeZoneInfo();
var localDateTime = TimeZoneInfo.ConvertTime(utcDateTime, timeZoneInfo);
localDateTime = DateTime.SpecifyKind(localDateTime, DateTimeKind.Local);

var dt = new DATETIMETYPE(localDateTime);

Assert.AreEqual("2015-04-03T03:06:17-07:00", dt.ToString());
}

[Test]
public void DateTimeUtcToString()
{
var utcDateTime = new DateTime(2015, 4, 3, 10, 6, 17, DateTimeKind.Utc);
var dt = new DATETIMETYPE(utcDateTime);

Assert.AreEqual("2015-04-03T10:06:17+00:00", dt.ToString());
}
}
}

0 comments on commit 158b4d5

Please sign in to comment.