Skip to content

[FEATURE]: opportunity to pass custom datetime format for Java/Kotlin generation #2865

@l3r8yJ

Description

@l3r8yJ

It would be very suitable to add new flag for Java/Kotlin generation --datetime-format MY-CUSTOM-FORMAT

Context (Input, Language)

Input Format: flag for cli - --datetime-format
Output Language: Java, Kotlin

Description

Very often we need to provide custom datetime format; In case when automatically generated classes are published as standalone artifact (jar library for nexus). We can't change them at this moment.

Current Behaviour / Output

Not possible

Proposed Behaviour / Output

Inside generated classes would be custom format for datetime

    private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
            .appendOptional(DateTimeFormatter.ISO_DATE_TIME)
            .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
            .appendOptional(DateTimeFormatter.ISO_INSTANT)
            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))
            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))
            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
            .appendOptional(DateTimeFormatter.ofPattern("MY-CUSTOM-FORMAT")) // adds own format
            .toFormatter()
            .withZone(ZoneOffset.UTC);

Context

I wrapped quicktype cli into gradle plugin, that generates Java classes and publishes them as artifacts that can be added to project as a dependency. Now I can't provide custom date time format in config. I see bad workaround how i can do this, but it's seems inconvenient to me (need to parse generated classes and insert new line in every generated class, which is too ugly).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions