Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateTime formatting #247

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Intacct.SDK.Tests/Intacct.SDK.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net8;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Intacct.SDK.Tests/Xml/RequestHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public async Task MockDefaultNo524RetryTest()

var ex = await Record.ExceptionAsync(() => requestHandler.ExecuteOnline(contentBlock));
Assert.IsType<HttpRequestException>(ex);
Assert.Equal("Response status code does not indicate success: 524 ().", ex.Message);
Assert.Equal("Response status code does not indicate success: 524.", ex.Message);
}

[Fact(Skip="test randomly failing")]
Expand Down
1 change: 1 addition & 0 deletions Intacct.SDK/Functions/AccountsPayable/ApPaymentCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* permissions and limitations under the License.
*/

using System.Globalization;
using Intacct.SDK.Xml;

namespace Intacct.SDK.Functions.AccountsPayable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.EqualTo
{
public class EqualToDate : AbstractDate
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " = '" + Value.ToString(Format) + "'";
clause = clause + Field + " = '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.EqualTo
{
public class EqualToDateTime : AbstractDateTime
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " = '" + Value.ToString(Format) + "'";
clause = clause + Field + " = '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.GreaterThan
{
public class GreaterThanDate : AbstractDate
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " > '" + Value.ToString(Format) + "'";
clause = clause + Field + " > '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.GreaterThan
{
public class GreaterThanDateTime : AbstractDateTime
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " > '" + Value.ToString(Format) + "'";
clause = clause + Field + " > '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.GreaterThanOrEqualTo
{
public class GreaterThanOrEqualToDate : AbstractDate
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " >= '" + Value.ToString(Format) + "'";
clause = clause + Field + " >= '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.GreaterThanOrEqualTo
{
public class GreaterThanOrEqualToDateTime : AbstractDateTime
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " >= '" + Value.ToString(Format) + "'";
clause = clause + Field + " >= '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.LessThan
{
public class LessThanDate : AbstractDate
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " < '" + Value.ToString(Format) + "'";
clause = clause + Field + " < '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.LessThan
{
public class LessThanDateTime : AbstractDateTime
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " < '" + Value.ToString(Format) + "'";
clause = clause + Field + " < '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.LessThanOrEqualTo
{
public class LessThanOrEqualToDate : AbstractDate
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " <= '" + Value.ToString(Format) + "'";
clause = clause + Field + " <= '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.Globalization;

namespace Intacct.SDK.Functions.Common.Query.Comparison.LessThanOrEqualTo
{
public class LessThanOrEqualToDateTime : AbstractDateTime
Expand All @@ -25,7 +27,7 @@ public override string ToString()
clause = "NOT ";
}

clause = clause + Field + " <= '" + Value.ToString(Format) + "'";
clause = clause + Field + " <= '" + Value.ToString(Format, CultureInfo.InvariantCulture) + "'";

return clause;
}
Expand Down
62 changes: 62 additions & 0 deletions Intacct.SDK/Functions/Projects/TimesheetUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2022 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using Intacct.SDK.Xml;

namespace Intacct.SDK.Functions.Projects
{
public class TimesheetUpdate : AbstractTimesheet
{

public TimesheetUpdate(string controlId = null) : base(controlId)
{
}

public override void WriteXml(ref IaXmlWriter xml)
{
xml.WriteStartElement("function");
xml.WriteAttribute("controlid", ControlId, true);

xml.WriteStartElement("update");
xml.WriteStartElement("TIMESHEET");

xml.WriteElement("RECORDNO", RecordNo, true);
xml.WriteElement("EMPLOYEEID", EmployeeId, true);
xml.WriteElement("BEGINDATE", BeginDate, IaXmlWriter.IntacctDateFormat);

xml.WriteElement("DESCRIPTION", Description);
xml.WriteElement("SUPDOCID", AttachmentsId);
xml.WriteElement("STATE", Action);

xml.WriteStartElement("TIMESHEETENTRIES");
if (Entries.Count > 0)
{
foreach (TimesheetEntryCreate entry in Entries)
{
entry.WriteXml(ref xml);
}
}
xml.WriteEndElement(); //TIMESHEETENTRIES

xml.WriteCustomFieldsImplicit(CustomFields);

xml.WriteEndElement(); //TIMESHEET
xml.WriteEndElement(); //update

xml.WriteEndElement(); //function
}

}
}
4 changes: 2 additions & 2 deletions Intacct.SDK/Logging/MessageFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E
result = response.Content.Headers.ContentLength.ToString();
break;
case "{req_body}":
result = request.Content.ToString();
result = request.Content.ReadAsStringAsync().Result;
break;
case "{res_body}":
result = response != null ? response.Content.ToString() : "NULL";
result = response != null ? response.Content.ReadAsStringAsync().Result : "NULL";
break;
case "{ts}":
case "{date_iso_8601}":
Expand Down
5 changes: 3 additions & 2 deletions Intacct.SDK/Xml/IaXmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
Expand Down Expand Up @@ -260,7 +261,7 @@ public void WriteElement(string localName, bool? value, bool writeNull = false)

public void WriteElement(string localName, DateTime value, string format = IntacctDateTimeFormat)
{
_writer.WriteElementString(localName, value == default(DateTime) ? "" : value.ToString(format));
_writer.WriteElementString(localName, value == default(DateTime) ? "" : value.ToString(format, CultureInfo.InvariantCulture));
}

public void WriteElement(string localName, DateTime? value, string format = IntacctDateTimeFormat, bool writeNull = false)
Expand All @@ -274,7 +275,7 @@ public void WriteElement(string localName, DateTime? value, string format = Inta
}
else
{
_writer.WriteElementString(localName, value == default(DateTime) ? "" : value.Value.ToString(format));
_writer.WriteElementString(localName, value == default(DateTime) ? "" : value.Value.ToString(format, CultureInfo.InvariantCulture));
}
}

Expand Down