From ca043d9ccd9045d7c12295248c86faf3a0956eaf Mon Sep 17 00:00:00 2001 From: julio Date: Wed, 2 Jun 2021 07:11:50 -0500 Subject: [PATCH 1/2] fix(roam-import): single digit roam dates are padded with a left zero. --- src/cljc/athens/patterns.cljc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cljc/athens/patterns.cljc b/src/cljc/athens/patterns.cljc index 9cb1b7d6e1..13f2bef641 100644 --- a/src/cljc/athens/patterns.cljc +++ b/src/cljc/athens/patterns.cljc @@ -32,12 +32,12 @@ ;; Any update to this should be done after testing it using the previous regex101 link (def roam-date #"((?<=\s1\d)th|(?<=(\s|[023456789])\d)((?<=1)st|(?<=2)nd|(?<=3)rd|(?<=[4567890])th)),(?=\s\d{4})") +(def pad-single-digit-date-pattern #"(?<=\s)\d(?=,)") (defn date [str] (re-find #"(?=\d{2}-\d{2}-\d{4}).*" str)) - (defn date-block-string [str] (re-find #"\b(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:st|nd|rd|th),\s\d{4}\b" str)) @@ -45,5 +45,8 @@ (defn replace-roam-date [string] - (clojure.string/replace string athens.patterns/roam-date ",")) + (-> string + (clojure.string/replace roam-date ",") + ;; Adds a 0 for single-digit roam dates. + (clojure.string/replace pad-single-digit-date-pattern #(str "0" %)))) From 1d42ac34035b70a3bd3826bd26b0342d9dd7b27f Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 7 Jul 2021 08:20:49 -0500 Subject: [PATCH 2/2] test(roam-import): include test for the transformation between roam-dates and athens-dates --- test/athens/patterns_test.clj | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/athens/patterns_test.clj b/test/athens/patterns_test.clj index 37f352c529..5781e5a121 100644 --- a/test/athens/patterns_test.clj +++ b/test/athens/patterns_test.clj @@ -42,3 +42,67 @@ (is (= "#[[link 1]] #hashtag" (first (re-find (patterns/linked ".*") "#[[link 1]] #hashtag"))))) +(deftest roam-to-athens-date + (let [roam-dates ["February 1st, 2021" + "February 2nd, 2021" + "February 3rd, 2021" + "February 4th, 2021" + "February 5th, 2021" + "February 6th, 2021" + "February 7th, 2021" + "February 8th, 2021" + "February 9th, 2021" + "November 10th, 2020" + "November 11th, 2020" + "November 12th, 2020" + "November 13th, 2020" + "November 14th, 2020" + "November 15th, 2020" + "November 16th, 2020" + "November 17th, 2020" + "November 18th, 2020" + "November 19th, 2020" + "November 20th, 2020" + "November 21st, 2021" + "November 22nd, 2021" + "November 23rd, 2021" + "November 24th, 2021" + "November 25th, 2021" + "November 26th, 2021" + "November 27th, 2021" + "November 28th, 2021" + "November 29th, 2021" + "November 30th, 2021" + "November 31st, 2021"] + expected-athens-dates ["February 01, 2021" + "February 02, 2021" + "February 03, 2021" + "February 04, 2021" + "February 05, 2021" + "February 06, 2021" + "February 07, 2021" + "February 08, 2021" + "February 09, 2021" + "November 10, 2020" + "November 11, 2020" + "November 12, 2020" + "November 13, 2020" + "November 14, 2020" + "November 15, 2020" + "November 16, 2020" + "November 17, 2020" + "November 18, 2020" + "November 19, 2020" + "November 20, 2020" + "November 21, 2021" + "November 22, 2021" + "November 23, 2021" + "November 24, 2021" + "November 25, 2021" + "November 26, 2021" + "November 27, 2021" + "November 28, 2021" + "November 29, 2021" + "November 30, 2021" + "November 31, 2021"]] + (is (= (map patterns/replace-roam-date roam-dates) expected-athens-dates))))