kotlinx-datetime
kotlinx-datetime copied to clipboard
Add a dayOfYear option
I need to parse / construct a Julian date, which requires the day of year value. It would fall in nicely with the dayOfMonth and dayOfWeek values. :-)
Or, is there a way I can construct my own WithDate extension that would allow me to add it on my end?
I need to parse / construct a Julian date
Which one is it? You can construct the value (though the API isn't nice) today:
LocalDate(year, 1, 1).plus(dayOfYear - 1, DateTimeUnit.DAY)
Parsing from strings, on the other hand, is only available via dirty hacks.
It is actually for parsing. I have a date time in the format of "yyDDDHHmm". I have been using the format helpers to do most of my parsing thus far. Perhaps the string based version might handle this?
Is this - dayOfYear - something we think could make it in a future version?
Okay, I did try to use the fallback of
byUnicodePattern("yyDDDHHmm")
but it then gives an assert with message:
java.lang.UnsupportedOperationException: kotlinx.datetime formatting does not support the day-of-year field. Please report your use case to https://github.com/Kotlin/kotlinx-datetime/issues
So I think it would be useful and a nice way to round out the parsers. :-)