scicloj / tablecloth.time

Tools for the processing and manipulation of time-series data in Clojure.
Other
18 stars 1 forks source link

Add time component extractors #53

Closed ezmiller closed 3 years ago

ezmiller commented 3 years ago

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 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

Open Questions