Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for writing to custom formats #7

Open
erikc5000 opened this issue Oct 28, 2019 · 1 comment
Open

Add support for writing to custom formats #7

erikc5000 opened this issue Oct 28, 2019 · 1 comment
Assignees
Labels
design Design issue/question enhancement New feature or request
Milestone

Comments

@erikc5000
Copy link
Owner

It should be possible to define a custom format similar to how a custom parser can be defined. Something like:

val customFormat = dateTimeFormat {
    monthNumber()
    +'/'
    dayOfMonth()
}

val date = Date(2019, 10, 28)
val string = date.toString(customFormat)

For the initial implementation, we can avoid adding support anything locale-specific. Locale will open up another can of worms.

Implementing this will probably require inserting an interface into the date-time primitives -- something akin to TemporalAccessor in java.time, but Period and Duration should also implement it since we include parser support for them. This interface should provide access to the available date-time fields on the object.

interface Temporal {
    fun get(field: DateTimeField): Long
}

Introducing a TemporalQuery-like interface for access to non-Long fields may also be necessary.

Ultimately, I'm envisioning the abstractions added here will also tie in with and enable parsing of arbitrary ISO-compliant strings.

val temporal = genericIsoParser.parseAny(text)

if (temporal is Year) {
    // ..
} else if (temporal is Date) {
    // ..
}

This will be useful for working with intervals that have mixed-precision end points, like "2018/2019-05-01".

Obviously, these are more advanced use cases though, so the focus should initially be on what's necessary to support custom formatting.

@erikc5000 erikc5000 added enhancement New feature or request design Design issue/question labels Oct 28, 2019
@erikc5000 erikc5000 self-assigned this May 20, 2020
@erikc5000 erikc5000 added this to the 0.3.0 milestone May 20, 2020
@erikc5000
Copy link
Owner Author

An effort is add formatting support is well underway. It's a pretty big change and will break the existing parser functionality to some extent.

@erikc5000 erikc5000 modified the milestones: 0.3.0, 0.4.0 Jul 30, 2020
@erikc5000 erikc5000 modified the milestones: 0.5.0, 0.70, 0.7.0 May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design issue/question enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant