Skip to content

Commit

Permalink
Merge pull request #57 from hkutluay/date-time-fix
Browse files Browse the repository at this point in the history
Issue time format fix
- fixes #56
  • Loading branch information
hkutluay committed May 13, 2022
2 parents a7fdf52 + 9f52b02 commit 083e85b
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-multi-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Unit Tests
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Add Nuget source
run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config

- name: Build with dotnet
run: dotnet build --configuration Release
- name: Test with dotnet
Expand Down
13 changes: 12 additions & 1 deletion Ubl-Tr/Common/UnqualifiedDataTypes/TimeType.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using System;
using System.Globalization;
using System.Xml.Serialization;

namespace UblTr.Common
{
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ValidationTimeType))]
Expand Down Expand Up @@ -41,7 +45,7 @@ public partial class TimeType
private System.DateTime valueField;

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute(DataType = "time")]
[System.Xml.Serialization.XmlIgnore]
public System.DateTime Value
{
get
Expand All @@ -53,5 +57,12 @@ public System.DateTime Value
this.valueField = value;
}
}

[System.Xml.Serialization.XmlTextAttribute(DataType = "string")]
public String TimeString
{
get { return this.valueField.ToString("HH:mm:ss"); }
set { this.valueField = DateTime.ParseExact(value, "HH:mm:ss", CultureInfo.InvariantCulture); }
}
}
}
23 changes: 21 additions & 2 deletions Ubl-Tr/Serialization/UblTrNamespaces.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Serialization;

namespace UblTr.Serialization
{
Expand All @@ -18,4 +19,22 @@ public UblTrNamespaces()
Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
}
}
}

public class UblTrNamespacesManager : XmlNamespaceManager
{
public UblTrNamespacesManager(XmlNameTable TableName): base(TableName)
{
AddNamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
AddNamespace("ccts", "urn:un:unece:uncefact:documentation:2");
AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
AddNamespace("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
AddNamespace("ubltr", "urn:oasis:names:specification:ubl:schema:xsd:TurkishCustomizationExtensionComponents");
AddNamespace("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
AddNamespace("udt", "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
AddNamespace("xades", "http://uri.etsi.org/01903/v1.3.2#");
AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
}

}
}
8 changes: 4 additions & 4 deletions Ubl-Tr/UblTr.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.1;netstandard2.0;net45;net46;netcoreapp1.0;netcoreapp1.1;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard1.3;netstandard2.1;netstandard2.0;net45;net46;netcoreapp1.0;netcoreapp1.1;net5.0;net6.0</TargetFrameworks>
<RootNamespace>UblTr</RootNamespace>
<Authors>Hakan Kutluay</Authors>
<Description>Ubl-Tr v1.2.1 (UBL 2.1) .Net Classes</Description>
<RepositoryUrl>https://github.com/hkutluay/UblTr</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
<PackageTags>ubltr ubl-tr e-invoice ubl ubl-tr-1.2.1 e-fatura fatura efatura e-despatch eirsaliye irsaliye applicationresponse uygulamayaniti creditnote receiptadvice </PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.1.5</Version>
<Version>1.1.6</Version>
<PackageIcon>icon.png</PackageIcon>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<FileVersion>1.1.5.0</FileVersion>
<AssemblyVersion>1.1.6.0</AssemblyVersion>
<FileVersion>1.1.6.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<None Include="Images\icon.png">
Expand Down
50 changes: 47 additions & 3 deletions UblTr.Tests/InvoiceTypeTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml;
Expand Down Expand Up @@ -58,6 +59,7 @@ public void InvoiceType_CommercialInvoice_Deserialize()
public void InvoiceType_BasicInvoice_Serialize()
{
var document = new XmlDocument();
var date = DateTime.Now;

var invoice = new InvoiceType
{
Expand All @@ -71,7 +73,9 @@ public void InvoiceType_BasicInvoice_Serialize()
new Common.UBLExtensionType() {
ExtensionContent = document.CreateElement("auto-generated_for_wildcard","n4")
}
}
},
IssueTime = new Common.IssueTimeType() { Value = date },
IssueDate = new Common.IssueDateType() { Value = date }
};


Expand All @@ -80,8 +84,6 @@ public void InvoiceType_BasicInvoice_Serialize()
xmlSerializer.Serialize(stream, invoice, new UblTrNamespaces());
stream.Seek(0,SeekOrigin.Begin);

// File.WriteAllBytes("/Users/hakankutluay/Downloads/TestInvoice.xml", stream.ToArray());

var deserializedInvoice = (InvoiceType)xmlSerializer.Deserialize(stream);

Assert.AreEqual(invoice.ID.Value, deserializedInvoice.ID.Value);
Expand All @@ -92,5 +94,47 @@ public void InvoiceType_BasicInvoice_Serialize()
}


[TestMethod]
public void InvoiceType_BasicInvoice_TimeSerialize()
{
var document = new XmlDocument();

// var date = DateTime.ParseExact("2022/01/01 22:30:44", "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
var date = DateTime.Now;
var invoice = new InvoiceType
{
UUID = new Common.UUIDType() { Value = Guid.NewGuid().ToString() },
UBLVersionID = new Common.UBLVersionIDType() { Value = "2.1" },
CustomizationID = new Common.CustomizationIDType() { Value = "TR1.2" },
ProfileID = new Common.ProfileIDType() { Value = "TEMELFATURA" },
ID = new Common.IDType() { Value = "INV20200000000001" },
CopyIndicator = new Common.CopyIndicatorType() { Value = false },
UBLExtensions = new Common.UBLExtensionType[] {
new Common.UBLExtensionType() {
ExtensionContent = document.CreateElement("auto-generated_for_wildcard","n4")
}
},
IssueTime = new Common.IssueTimeType() { Value = date },
IssueDate = new Common.IssueDateType() { Value = date }
};


XmlSerializer xmlSerializer = new XmlSerializer(typeof(InvoiceType));
var stream = new MemoryStream();
xmlSerializer.Serialize(stream, invoice, new UblTrNamespaces());
stream.Seek(0, SeekOrigin.Begin);

var xPath = @"//*[local-name() = 'Invoice']/cbc:IssueTime";

var doc = new XmlDocument();
var namespaces = new UblTrNamespacesManager(doc.NameTable);
doc.Load(stream);
var sn = doc.SelectSingleNode(xPath, namespaces);

Assert.AreEqual(sn.InnerText, date.ToString("HH:mm:ss"));

}


}
}
2 changes: 1 addition & 1 deletion UblTr.Tests/UblTr.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down

0 comments on commit 083e85b

Please sign in to comment.