Skip to content
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

fix(roam-import): single digit roam dates are padded with a left zero. #1268

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/cljc/athens/patterns.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@
;; 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))


(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" %))))

64 changes: 64 additions & 0 deletions test/athens/patterns_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))