konik-io / konik

A library to create, read and validate ZUGFeRD compliant invoices. Available for Java and .NET
https://konik.io
Other
48 stars 19 forks source link

Define default date pattern #64

Closed djmj closed 5 years ago

djmj commented 6 years ago

A konic beginner will try to set a Date intuitive and fail little confused like:

Date issued = myInvoice.issued;
header.setIssued(issued);

but must create a spefific Zf instance:

header.setIssued(new ZfDateDay(issued));

There are certain date formats of zugferd this Zf structure supports. Allowing java Date could be archived by overloading the function which does the conversion internally.

Vad1mo commented 6 years ago

ZfDate is subclass of Date already.

ZfDate is mandatory as ZF Dates have a format. There are already Classes for the typical usecases e.g. ZfDateDay

there is even a ZfDateFactory that produces ZfDate for each CODE

Can you provide an example:

djmj commented 6 years ago

The idea was to allow Date as arguments instead of ZfDate in all methods. I as a programmer dont care what format zugferd uses internal. Something flexible like:

public class Header
{
    public void setIssued(Date issued)
    {
        this.issued = ZfDate.convertTo(issued);
    }

    public static ZfDate convertTo(Date date)
    {
        if (date instanceof ZfDate)
            return (ZfDate)date;
        else
            return new ZfDateDay(date);
    }
}

In this case the default will be converted to ZfDateDay.

Further the application could provide a "default date converter" interface which could be used, in case a different default format shall be used. If this is necessary.

public Invoice(ZfDateConverter dateConverter)
Vad1mo commented 6 years ago

I see the point. However there is no default date format. It depend a lot on the use case and the user. You have to also take into account that the lib does also parsing xmls and converting them back into the data model.

However I take that into account for the 2.0 release as this suggestion is an API break.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.