Skip to content

Commit

Permalink
Support all possible time formats (#95)
Browse files Browse the repository at this point in the history
* add more time format support

* enhance time parsing to support additional formats
  • Loading branch information
hkutluay authored Dec 26, 2023
1 parent b321f56 commit 269395f
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet-test-explorer.testProjectPath": "UblTr.Tests/"
}
19 changes: 4 additions & 15 deletions Ubl-Tr/Common/UnqualifiedDataTypes/TimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ namespace UblTr.Common
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2")]
public partial class TimeType
{

private List<string> applicableTimeFormats = new List<string> {
"HH:mm:ss",
"HH:mm",
"HH:mm:ss.fffff",
"HH:mm:ss.fffffff",
"HH:mm:ss.fffffffzzz"
};

private System.DateTime valueField;

/// <remarks/>
Expand All @@ -75,13 +66,11 @@ public String TimeString
bool parsed = false;
DateTime parsedValue;

foreach (var format in applicableTimeFormats)

if(DateTime.TryParse(value,CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedValue))
{
if(DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedValue))
{
this.valueField = parsedValue;
parsed = true;
}
this.valueField = parsedValue;
parsed = true;
}

if(!parsed)
Expand Down
6 changes: 3 additions & 3 deletions Ubl-Tr/UblTr.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<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.3.0</Version>
<Version>1.3.1</Version>
<PackageIcon>icon.png</PackageIcon>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<FileVersion>1.3.0.0</FileVersion>
<AssemblyVersion>1.3.1.0</AssemblyVersion>
<FileVersion>1.3.1.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<None Include="Images\icon.png">
Expand Down
14 changes: 14 additions & 0 deletions UblTr.Tests/InvoiceTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public void InvoiceType_BasicInvoice_Deserialize()
}

[TestMethod]
public void InvoiceType_BasicInvoiceLongTimeWithZone3f_Deserialize()
{
var invoice = DeserializeInvoiceXml( $"{_testFilesPath}/BasicInvoiceLongTimeWithZone3f.xml");
Assert.AreEqual("23:30:41", TimeZoneInfo.ConvertTimeToUtc(invoice.IssueTime.Value).ToString("HH:mm:ss"));
}

[TestMethod]
public void InvoiceType_BasicInvoiceLongTime7f_Deserialize()
{
var invoice = DeserializeInvoiceXml( $"{_testFilesPath}/BasicInvoiceLongTime7f.xml");
Assert.AreEqual("15:21:06", TimeZoneInfo.ConvertTimeToUtc(invoice.IssueTime.Value).ToString("HH:mm:ss"));
}

[TestMethod]
public void InvoiceType_BasicInvoiceLongTime_Deserialize()
{
var invoice = DeserializeInvoiceXml( $"{_testFilesPath}/BasicInvoiceLongTime.xml");
Expand Down
167 changes: 167 additions & 0 deletions UblTr.Tests/TestFiles/InvoiceType/BasicInvoiceLongTime7f.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="general.xslt"?>
<Invoice xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 ../xsdrt/maindoc/UBL-Invoice-2.1.xsd" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:n4="http://www.altova.com/samplexml/other-namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent>
<n4:auto-generated_for_wildcard/>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
<cbc:CustomizationID>TR1.2</cbc:CustomizationID>
<cbc:ProfileID>TEMELFATURA</cbc:ProfileID>
<cbc:ID>GIB20090000000001</cbc:ID>
<cbc:CopyIndicator>false</cbc:CopyIndicator>
<cbc:UUID>F47AC10B-58CC-4372-A567-0E02B2C3D479</cbc:UUID>
<cbc:IssueDate>2009-01-05</cbc:IssueDate>
<cbc:IssueTime>15:21:06.0000000Z</cbc:IssueTime>
<cbc:InvoiceTypeCode>SATIS</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>TRY</cbc:DocumentCurrencyCode>
<cbc:LineCountNumeric>1</cbc:LineCountNumeric>
<cac:InvoicePeriod>
<cbc:StartDate>2008-12-05</cbc:StartDate>
<cbc:EndDate>2009-01-05</cbc:EndDate>
</cac:InvoicePeriod>
<cac:Signature>
<cbc:ID schemeID="VKN_TCKN">1288331521</cbc:ID>
<cac:SignatoryParty>
<cac:PartyIdentification>
<cbc:ID schemeID="VKN">1288331521</cbc:ID>
</cac:PartyIdentification>
<cac:PostalAddress>
<cbc:StreetName>Papatya Caddesi Yasemin Sokak</cbc:StreetName>
<cbc:BuildingNumber>21</cbc:BuildingNumber>
<cbc:CitySubdivisionName>Beşiktaş</cbc:CitySubdivisionName>
<cbc:CityName>İstanbul</cbc:CityName>
<cbc:PostalZone>34100</cbc:PostalZone>
<cac:Country>
<cbc:Name>Türkiye</cbc:Name>
</cac:Country>
</cac:PostalAddress>
</cac:SignatoryParty>
<cac:DigitalSignatureAttachment>
<cac:ExternalReference>
<cbc:URI>#Signature</cbc:URI>
</cac:ExternalReference>
</cac:DigitalSignatureAttachment>
</cac:Signature>
<cac:AccountingSupplierParty>
<cac:Party>
<cbc:WebsiteURI>http://www.aaa.com.tr/</cbc:WebsiteURI>
<cac:PartyIdentification>
<cbc:ID schemeID="VKN">1288331521</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>AAA Anonim Şirketi</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:ID>1234567890</cbc:ID>
<cbc:StreetName>Papatya Caddesi Yasemin Sokak</cbc:StreetName>
<cbc:BuildingNumber>21</cbc:BuildingNumber>
<cbc:CitySubdivisionName>Beşiktaş</cbc:CitySubdivisionName>
<cbc:CityName>İstanbul</cbc:CityName>
<cbc:PostalZone>34100</cbc:PostalZone>
<cac:Country>
<cbc:Name>Türkiye</cbc:Name>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cac:TaxScheme>
<cbc:Name>Büyük Mükellefler</cbc:Name>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:Contact>
<cbc:Telephone>(212) 925 51515</cbc:Telephone>
<cbc:Telefax>(212) 925505015</cbc:Telefax>
<cbc:ElectronicMail>aa@aaa.com.tr</cbc:ElectronicMail>
</cac:Contact>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cbc:WebsiteURI/>
<cac:PartyIdentification>
<cbc:ID schemeID="TCKN">1234567890</cbc:ID>
</cac:PartyIdentification>
<cac:PartyIdentification>
<cbc:ID schemeID="TESISATNO">1234567</cbc:ID>
</cac:PartyIdentification>
<cac:PartyIdentification>
<cbc:ID schemeID="SAYACNO">12345678</cbc:ID>
</cac:PartyIdentification>
<cac:PostalAddress>
<cbc:ID>ATATÜRK MAH.</cbc:ID>
<cbc:Room>1</cbc:Room>
<cbc:StreetName>6. Sokak</cbc:StreetName>
<cbc:BuildingNumber>1</cbc:BuildingNumber>
<cbc:CitySubdivisionName>Beşiktaş</cbc:CitySubdivisionName>
<cbc:CityName>İstanbul</cbc:CityName>
<cbc:PostalZone>34100</cbc:PostalZone>
<cac:Country>
<cbc:Name>Türkiye</cbc:Name>
</cac:Country>
</cac:PostalAddress>
<cac:Contact>
<cbc:ElectronicMail>1234567890@mydn.com.tr</cbc:ElectronicMail>
</cac:Contact>
<cac:Person>
<cbc:FirstName>Ali</cbc:FirstName>
<cbc:FamilyName>YILMAZ</cbc:FamilyName>
</cac:Person>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:PaymentTerms>
<cbc:Note>BBB Bank Otomatik Ödeme</cbc:Note>
<cbc:PaymentDueDate>2009-01-20</cbc:PaymentDueDate>
</cac:PaymentTerms>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="TRY">15.15</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
<cac:TaxCategory>
<cac:TaxScheme>
<cbc:TaxTypeCode>0015</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:LineExtensionAmount currencyID="TRY">15.15</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID="TRY">15.15</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID="TRY">17.88</cbc:TaxInclusiveAmount>
<cbc:PayableAmount currencyID="TRY">17.88</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>1</cbc:ID>
<cbc:InvoicedQuantity unitCode="KWH">101</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="TRY">15.15</cbc:LineExtensionAmount>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:MultiplierFactorNumeric>0.0</cbc:MultiplierFactorNumeric>
<cbc:Amount currencyID="TRY">0</cbc:Amount>
<cbc:BaseAmount currencyID="TRY">15.15</cbc:BaseAmount>
</cac:AllowanceCharge>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="TRY">15.15</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
<cbc:Percent>18.0</cbc:Percent>
<cac:TaxCategory>
<cac:TaxScheme>
<cbc:Name>KDV</cbc:Name>
<cbc:TaxTypeCode>0015</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:Item>
<cbc:Name>Elektrik Tüketim Bedeli</cbc:Name>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="TRY">0.15</cbc:PriceAmount>
</cac:Price>
</cac:InvoiceLine>
</Invoice>
Loading

0 comments on commit 269395f

Please sign in to comment.