From 150152a65686459d1b4750c707db853d29ab46ef Mon Sep 17 00:00:00 2001 From: R Siddharthan Date: Sun, 23 May 2021 14:52:56 -0400 Subject: [PATCH 1/6] adds new datetime convertor methods + exports rolloing-window --- src/tablecloth/time/api.clj | 8 +++++++- src/tablecloth/time/api/converters.clj | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/tablecloth/time/api.clj b/src/tablecloth/time/api.clj index 442b7ca..19b994d 100644 --- a/src/tablecloth/time/api.clj +++ b/src/tablecloth/time/api.clj @@ -19,4 +19,10 @@ ->months-end ->quarters-end ->years-end - ->every) + ->every + ->year + ->year-month) + +(exporter/export-symbols tablecloth.time.api.rolling-window + rolling-window) + diff --git a/src/tablecloth/time/api/converters.clj b/src/tablecloth/time/api/converters.clj index fe186d9..c2fca90 100644 --- a/src/tablecloth/time/api/converters.clj +++ b/src/tablecloth/time/api/converters.clj @@ -1,10 +1,13 @@ (ns tablecloth.time.api.converters - (:import [java.time Year] - [org.threeten.extra YearWeek YearQuarter]) (:require [tech.v3.datatype.datetime :as dtdt] [tech.v3.datatype :as dt] [tech.v3.datatype.casting :refer [add-object-datatype!]] - [tick.alpha.api :as tick])) + [tick.alpha.api :as tick]) + + (:import [java.time Year] + [org.threeten.extra YearWeek YearQuarter] + [java.util Locale] + [java.time.format TextStyle])) (set! *warn-on-reflection* true) @@ -158,3 +161,16 @@ [datetime] (let [^java.time.LocalDate localDate (-> datetime ->local-date)] (.with localDate (java.time.temporal.TemporalAdjusters/lastDayOfYear)))) + +(defn ->year + [localdate] + (.getYear ^java.time.LocalDate localdate)) + +(defn ->year-month + [localdate] + (let [yyyy (.getYear ^java.time.LocalDate localdate) + mmm (-> (.getMonth ^java.time.LocalDate localdate) + (.getDisplayName ^java.time.format.TextStyle TextStyle/SHORT + (^java.util.Locale Locale/getDefault)))] + [yyyy mmm])) + From a0169151ed8a6211e01a56827a402c16f6136ddc Mon Sep 17 00:00:00 2001 From: "R. Siddharthan" Date: Sat, 17 Jul 2021 22:38:33 -0400 Subject: [PATCH 2/6] adds year-quarter to local-date conversion --- src/tablecloth/time/api.clj | 3 ++- src/tablecloth/time/api/converters.clj | 6 ++++++ test/tablecloth/time/api/converters_test.clj | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/tablecloth/time/api.clj b/src/tablecloth/time/api.clj index b737db5..535905c 100644 --- a/src/tablecloth/time/api.clj +++ b/src/tablecloth/time/api.clj @@ -24,4 +24,5 @@ ->quarters-end ->years-end ->every - string->time) + string->time + year-quarter->local-date) diff --git a/src/tablecloth/time/api/converters.clj b/src/tablecloth/time/api/converters.clj index f6b6008..33711c0 100644 --- a/src/tablecloth/time/api/converters.clj +++ b/src/tablecloth/time/api/converters.clj @@ -1,5 +1,6 @@ (ns tablecloth.time.api.converters (:import [java.time Year] + [java.time.format DateTimeFormatter] [org.threeten.extra YearWeek YearQuarter]) (:require [tech.v3.datatype.datetime :as dtdt] [tech.v3.datatype :as dt] @@ -20,6 +21,11 @@ (defn year->local-date [^Year year] (-> year (.atMonthDay (java.time.MonthDay/parse "--01-01")))) +(defn year-quarter->local-date [year-quarter format-pattern] + (-> year-quarter + (YearQuarter/parse (DateTimeFormatter/ofPattern format-pattern)) + .atEndOfQuarter)) + (defn year->milliseconds-since-epoch [^Year year] (-> year year->local-date dtdt/local-date->milliseconds-since-epoch)) diff --git a/test/tablecloth/time/api/converters_test.clj b/test/tablecloth/time/api/converters_test.clj index 55ec4ea..5887e8f 100644 --- a/test/tablecloth/time/api/converters_test.clj +++ b/test/tablecloth/time/api/converters_test.clj @@ -3,7 +3,7 @@ [tablecloth.time.api :refer [down-to-nearest ->seconds convert-to ->minutes ->hours ->days ->weeks-end ->months-end ->quarters-end ->years-end - string->time]])) + string->time year-quarter->local-date]])) (deftest test-down-to-nearest (testing "returns partial fn if datetime not provided" @@ -53,6 +53,10 @@ (is (= #time/date "1970-12-31" (->years-end #time/date "1970-01-01")))) +(deftest test->year-quarter + (is (= #time/date "2016-03-31" + (year-quarter->local-date "2016 Q1" "yyyy 'Q'q")))) + (deftest test-convert-to (is (= #time/date "1970-01-01" (convert-to #time/instant "1970-01-01T00:00:00Z" :local-date))) From b59160fe3ceda654a4d748f0101cae553b58e762 Mon Sep 17 00:00:00 2001 From: "R. Siddharthan" Date: Sat, 17 Jul 2021 22:38:33 -0400 Subject: [PATCH 3/6] adds year-quarter to local-date conversion --- src/tablecloth/time/api.clj | 3 ++- src/tablecloth/time/api/converters.clj | 6 ++++++ test/tablecloth/time/api/converters_test.clj | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/tablecloth/time/api.clj b/src/tablecloth/time/api.clj index b737db5..535905c 100644 --- a/src/tablecloth/time/api.clj +++ b/src/tablecloth/time/api.clj @@ -24,4 +24,5 @@ ->quarters-end ->years-end ->every - string->time) + string->time + year-quarter->local-date) diff --git a/src/tablecloth/time/api/converters.clj b/src/tablecloth/time/api/converters.clj index f6b6008..33711c0 100644 --- a/src/tablecloth/time/api/converters.clj +++ b/src/tablecloth/time/api/converters.clj @@ -1,5 +1,6 @@ (ns tablecloth.time.api.converters (:import [java.time Year] + [java.time.format DateTimeFormatter] [org.threeten.extra YearWeek YearQuarter]) (:require [tech.v3.datatype.datetime :as dtdt] [tech.v3.datatype :as dt] @@ -20,6 +21,11 @@ (defn year->local-date [^Year year] (-> year (.atMonthDay (java.time.MonthDay/parse "--01-01")))) +(defn year-quarter->local-date [year-quarter format-pattern] + (-> year-quarter + (YearQuarter/parse (DateTimeFormatter/ofPattern format-pattern)) + .atEndOfQuarter)) + (defn year->milliseconds-since-epoch [^Year year] (-> year year->local-date dtdt/local-date->milliseconds-since-epoch)) diff --git a/test/tablecloth/time/api/converters_test.clj b/test/tablecloth/time/api/converters_test.clj index 55ec4ea..5887e8f 100644 --- a/test/tablecloth/time/api/converters_test.clj +++ b/test/tablecloth/time/api/converters_test.clj @@ -3,7 +3,7 @@ [tablecloth.time.api :refer [down-to-nearest ->seconds convert-to ->minutes ->hours ->days ->weeks-end ->months-end ->quarters-end ->years-end - string->time]])) + string->time year-quarter->local-date]])) (deftest test-down-to-nearest (testing "returns partial fn if datetime not provided" @@ -53,6 +53,10 @@ (is (= #time/date "1970-12-31" (->years-end #time/date "1970-01-01")))) +(deftest test->year-quarter + (is (= #time/date "2016-03-31" + (year-quarter->local-date "2016 Q1" "yyyy 'Q'q")))) + (deftest test-convert-to (is (= #time/date "1970-01-01" (convert-to #time/instant "1970-01-01T00:00:00Z" :local-date))) From fa9fc35c6bd1854d19123944bf568dcdb298cc9a Mon Sep 17 00:00:00 2001 From: R Siddharthan Date: Sun, 23 May 2021 14:52:56 -0400 Subject: [PATCH 4/6] adds new datetime convertor methods + exports rolloing-window --- src/tablecloth/time/api.clj | 4 ++++ src/tablecloth/time/api/converters.clj | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tablecloth/time/api.clj b/src/tablecloth/time/api.clj index 535905c..532805b 100644 --- a/src/tablecloth/time/api.clj +++ b/src/tablecloth/time/api.clj @@ -26,3 +26,7 @@ ->every string->time year-quarter->local-date) + +(exporter/export-symbols tablecloth.time.api.rolling-window + rolling-window) + diff --git a/src/tablecloth/time/api/converters.clj b/src/tablecloth/time/api/converters.clj index 33711c0..de6ebaa 100644 --- a/src/tablecloth/time/api/converters.clj +++ b/src/tablecloth/time/api/converters.clj @@ -180,4 +180,3 @@ [datetime] (let [^java.time.LocalDate localDate (-> datetime ->local-date)] (.with localDate (java.time.temporal.TemporalAdjusters/lastDayOfYear)))) - From e21edaa0fc5de7cb76a6c4d95a75344a9eb32894 Mon Sep 17 00:00:00 2001 From: R Siddharthan Date: Fri, 23 Jul 2021 14:12:46 -0400 Subject: [PATCH 5/6] roll back year-quarter test function --- test/tablecloth/time/api/converters_test.clj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/tablecloth/time/api/converters_test.clj b/test/tablecloth/time/api/converters_test.clj index 5887e8f..55ec4ea 100644 --- a/test/tablecloth/time/api/converters_test.clj +++ b/test/tablecloth/time/api/converters_test.clj @@ -3,7 +3,7 @@ [tablecloth.time.api :refer [down-to-nearest ->seconds convert-to ->minutes ->hours ->days ->weeks-end ->months-end ->quarters-end ->years-end - string->time year-quarter->local-date]])) + string->time]])) (deftest test-down-to-nearest (testing "returns partial fn if datetime not provided" @@ -53,10 +53,6 @@ (is (= #time/date "1970-12-31" (->years-end #time/date "1970-01-01")))) -(deftest test->year-quarter - (is (= #time/date "2016-03-31" - (year-quarter->local-date "2016 Q1" "yyyy 'Q'q")))) - (deftest test-convert-to (is (= #time/date "1970-01-01" (convert-to #time/instant "1970-01-01T00:00:00Z" :local-date))) From ebe08302d91c1cdaed08847a76481e1c6c336c2b Mon Sep 17 00:00:00 2001 From: R Siddharthan Date: Fri, 23 Jul 2021 14:17:42 -0400 Subject: [PATCH 6/6] cleanup to sync with main --- src/tablecloth/time/api/converters.clj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/tablecloth/time/api/converters.clj b/src/tablecloth/time/api/converters.clj index 33711c0..f6b6008 100644 --- a/src/tablecloth/time/api/converters.clj +++ b/src/tablecloth/time/api/converters.clj @@ -1,6 +1,5 @@ (ns tablecloth.time.api.converters (:import [java.time Year] - [java.time.format DateTimeFormatter] [org.threeten.extra YearWeek YearQuarter]) (:require [tech.v3.datatype.datetime :as dtdt] [tech.v3.datatype :as dt] @@ -21,11 +20,6 @@ (defn year->local-date [^Year year] (-> year (.atMonthDay (java.time.MonthDay/parse "--01-01")))) -(defn year-quarter->local-date [year-quarter format-pattern] - (-> year-quarter - (YearQuarter/parse (DateTimeFormatter/ofPattern format-pattern)) - .atEndOfQuarter)) - (defn year->milliseconds-since-epoch [^Year year] (-> year year->local-date dtdt/local-date->milliseconds-since-epoch))