Closed kenfolza closed 4 years ago
Do you have some example code?
TimeType uses DateTimeOffset, so any timezone offsets should be kept. If you don't specify any, your local timezone offset is used (like how DateTime works in .NET)
If you explicitly do not want to specify timezone, use DateTimeOffset or a DateTime with DateTimeKind.Utc
Hi,
The problem occurs in XML output. I assign the IssueTime as "10:30:00". But in XML output file, it becomes <IssueTime>10:30:00+03:00</IssueTime>
. I want to see just <IssueTime>10:30:00</IssueTime>
. Is this possible?
I don't think that is possible. But it also doesn't make any sense to do so.
The receiver MUST know the timezone, else it wouldn't know the exact issue time.
For example: you are generating the invoice in GMT+3, but the receiver is in GMT+6, if this is not in the XML, the receiver does not know the exact issue time.
I understand, but in our country government published a local rule set for UBL. In the documentation they want IssueTime as <IssueTime>10:30:00</IssueTime>
without time zone .
I don't think that is possible with how .NET XmlSerializer works with DateTime(Offset). It will always include the timezone information.
You could try "10:30:00.0Z", but this is not exactly same.
Under the covers, XmlConvert.ToString(DateTimeOffset) is used for the string representation in XML. I believe there is no way in .NET to override it's format.
Ok, thanks for the information.
@kenfolza actually, this might work:
invoice.IssueTime.ValueString = "10:30:00";
(ValueString is hidden from intellisense, since you normally don't need it, but it is there)
not sure though, since DateTimeOffset is still used.
@remcoros Unfortunately it didn't work.
The problem occurs in XML output. I assign the IssueTime as "10:30:00". But in XML output file, it becomes
The problem occurs in XML output. I assign the IssueTime as "10:30:00". But in XML output file, it becomes 10:30:00+03:00. I want to see just 10:30:00. Is this possible?
If you work with zatca, probably it will be helpfully to you. Before siging your generated invoice xml just use code below
internal class Utf8StringWriter : StringWriter
{
// Use UTF8 encoding but write no BOM to the wire
public override Encoding Encoding
{
get { return new UTF8Encoding(false); } // in real code I'll cache this encoding.
}
}
and in method
string xmlText = string.Empty;
using (var writer =new Utf8StringWriter() )
{
invoice.Save(writer);
xmlText = writer.ToString();
Regex dTCheck = new Regex(@"<cbc:IssueTime>(\d{2}:\d{2}:\d{2})([\+|-]\d{2}:\d{2})</cbc:IssueTime>");
if (dTCheck.IsMatch(xmlText))
xmlText = dTCheck.Replace(xmlText, "<cbc:IssueTime>$1</cbc:IssueTime>");
}
if (string.IsNullOrEmpty(xmlText))
throw new Exception("Xml not created.");
@remcoros if it is possible to pass the issue time format here XmlConvert.ToDateTimeOffset(value);?
Hi, I assign IssueTime as "10:30:00" . After i serialize InvoiceType object and generate xml document, IssueTime becomes 10:30:00+03:00 Is there a way to remove +03:00 time zone?
Thanks,