When working with date times people may frequently want to extract pieces of a datetime.
Proposed Solution
These functions basically just take the strategy of converting anytime to a java.time.LocalDateTime. That java.time class has functions that allow you to extract most/all components, such as year, month, etc.
Some of the components are always returned as ints by the functions on java.time.LocalDateTime. Others are returned as other classes. For example .getDayOfWeek returns a java.time.DayOfWeek. For the latter, we will return strings by default, but provide the option to either return :as-number? or :as-class?. For the former, we will return ints.
I tried to write a helper fn that can be used with partial to avoid repetition. So extract-datetime-component-simple can take an anonymous function with the extract call (e.g. #(.getYear %)) and returns an int. And extract-datetime-component-complex yields a function that takes the more complex set of options described above.
Work remaining
Might be good to figure out a way to prevent type reflection for extract-datetime-component-complex.
Goal / Problem
When working with date times people may frequently want to extract pieces of a datetime.
Proposed Solution
These functions basically just take the strategy of converting anytime to a
java.time.LocalDateTime
. That java.time class has functions that allow you to extract most/all components, such as year, month, etc.Some of the components are always returned as ints by the functions on
java.time.LocalDateTime
. Others are returned as other classes. For example.getDayOfWeek
returns ajava.time.DayOfWeek
. For the latter, we will return strings by default, but provide the option to either return:as-number?
or:as-class?
. For the former, we will return ints.I tried to write a helper fn that can be used with
partial
to avoid repetition. Soextract-datetime-component-simple
can take an anonymous function with the extract call (e.g.#(.getYear %)
) and returns an int. Andextract-datetime-component-complex
yields a function that takes the more complex set of options described above.Work remaining
extract-datetime-component-complex
.Open Questions