-
Notifications
You must be signed in to change notification settings - Fork 103
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
Provide custom formats for DateTimePeriod
#349
Comments
|
@jfontsaballs, please provide an example of what you can't currently express with the API we provide. What if it's already possible? |
I need to parse data received from a third party that does not conform to ISO standards. LocalTime.parse("9:16") Throws:
Currently I'm using the Java API: import java.time.LocalTime
import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.ChronoField
private val formatter = DateTimeFormatterBuilder()
.appendValue(ChronoField.HOUR_OF_DAY)
.appendLiteral(':')
.appendValue(ChronoField.MINUTE_OF_HOUR)
.toFormatter()
val JsonElement.localTime get() = LocalTime.parse(this.string, formatter).toKotlinLocalTime() I would like to write the following code but those APIs are internal. LocalTimeFormat.build {
hour(Padding.NONE)
char(':')
minute(Padding.NONE)
} |
@jfontsaballs, it's available from a different entry point: import kotlinx.datetime.*
import kotlinx.datetime.format.*
fun main() {
val format = LocalTime.Format {
hour(Padding.NONE)
char(':')
minute(Padding.NONE)
}
println("The time is ${format.parse("9:16")}")
} Runnable: https://pl.kotl.in/znkv3rbiZ Please also take a look at https://github.com/Kotlin/kotlinx-datetime?tab=readme-ov-file#working-with-other-string-formats |
Great, thank you! I'd like to request kotlinx.datetime.format.ISO_TIME (and other similar constants) be changed to use the public API, in order to improve discoverability of it when inspecting the code without having read the documentation. |
Currently,
DateTimePeriod
supportstoString
andparse
using the ISO 8601 format. With the recent introduction of the parsing and formatting machinery, we can add support for arbitrary formats.The text was updated successfully, but these errors were encountered: