Skip to content

Add a dayOfYear option #414

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

Closed
tylerwilson opened this issue Jul 22, 2024 · 3 comments · Fixed by #417
Closed

Add a dayOfYear option #414

tylerwilson opened this issue Jul 22, 2024 · 3 comments · Fixed by #417
Labels
formatters Related to parsing and formatting
Milestone

Comments

@tylerwilson
Copy link

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?

@dkhalanskyjb
Copy link
Collaborator

dkhalanskyjb commented Jul 23, 2024

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.

@dkhalanskyjb dkhalanskyjb added the waiting for clarification Additional information is needed from the user label Jul 23, 2024
@tylerwilson
Copy link
Author

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?

@dkhalanskyjb dkhalanskyjb added formatters Related to parsing and formatting and removed waiting for clarification Additional information is needed from the user labels Jul 23, 2024
@dkhalanskyjb dkhalanskyjb added this to the 0.7.0 milestone Jul 23, 2024
@tylerwilson
Copy link
Author

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. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatters Related to parsing and formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants