Skip to content

Commit 2b017e0

Browse files
committed
Deps and docs update
1 parent dc9bea9 commit 2b017e0

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,13 @@ Examples below:
195195
## Feedback/Discussions
196196
Github issues are a good way to discuss library related topics. I am also reachable via [CodeRafting](https://www.coderafting.com/).
197197

198+
## Some high-level TODOs (not in the order of priority)
199+
- `Clj` compatibility
200+
- Accept `1918-11-11T11:10:50` date-time format.
201+
- Option for users to provide customer date-time validators, for faster validation than the default one.
202+
- Include `future` date-time and intervals.
203+
- Some more friendly options, such as `tomorrow` and `yesterday`.
204+
- Option to spell out the numbers. Ex: `2 days ago` and `two days ago`.
205+
198206
## License
199207
Distributed under the MIT License. Copyright (c) 2020 [Amarjeet Yadav](https://www.coderafting.com/).

Diff for: deps.edn

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:deps {com.andrewmcveigh/cljs-time {:mvn/version "0.5.2"}}}

Diff for: project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
:url "https://github.com/coderafting/humane-time"
55
:license {:name "The MIT License"
66
:url "https://opensource.org/licenses/MIT"}
7+
:repositories [["clojars" {:sign-releases false}]]
78
:dependencies
89
[[org.clojure/clojure "1.10.1" :scope "provided"]
910
[org.clojure/clojurescript "1.10.597" :scope "provided"]
1011
[com.andrewmcveigh/cljs-time "0.5.2"]]
11-
1212
:plugins
1313
[[lein-cljsbuild "1.1.8"]
1414
[lein-figwheel "0.5.19"]

Diff for: src/humane_time/core.cljs

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns ^{:doc "Contains functions to be exposed to library users."
2-
:todo {1 "Possibility of making it available for both clj and cljs."}}
2+
:todo {1 "Possibility of making it available for both `clj` and `cljs`."}}
33
humane-time.core
44
(:require [humane-time.ops :as ops]))
55

66
(defn readable-date
7-
"Accepts date-string only in the form of 'DD-MM-YYYY' and 'YYYY-MM-DD' formats. DD and MM could just be D or M.
7+
"Accepts date-string only in the form of `DD-MM-YYYY` and `YYYY-MM-DD` formats. `DD` and `MM` could just be `D` or `M`.
88
Returns a string similar to:
9-
April 27, 2020 or Apr 27, 2020 or Monday, April 27, 2020 or Mon, April 27, 2020 or Mon, Apr 27, 2020.
9+
`April 27, 2020` or `Apr 27, 2020` or `Monday, April 27, 2020` or `Mon, April 27, 2020` or `Mon, Apr 27, 2020`.
1010
The optional options map dictates the return format. It includes the following keys:
11-
:day-name? - defaults to true.
12-
:short-names? - defaults to false."
11+
- `:day-name?` - defaults to `true`.
12+
- `:short-names?` - defaults to `false`."
1313
[date-string & opts-map]
1414
(let [dt (ops/datetime-descriptor date-string)]
1515
(str (if (or (nil? (:day-name? (first opts-map))) (:day-name? (first opts-map)))
@@ -60,14 +60,14 @@
6060
:else "less than an hour")))
6161

6262
(defn
63-
^{:doc "Accepts start and end values (strings) only in the form of 'DD-MM-YYYY' and 'YYYY-MM-DD' formats. DD and MM could just be D or M.
63+
^{:doc "Accepts `start` and `end` values (strings) only in the form of `DD-MM-YYYY` and `YYYY-MM-DD` formats. `DD` and `MM` could just be `D` or `M`.
6464
Returns a readable duration, but only in the highest unit, with lower bound of the value.
65-
Example: if the duration is between 1 and 2 years (ex: 1 year 10 months), then it will return '1 year'.
66-
Similarly, if the duration is between 10 to 11 months, then it will return '10 months'.
67-
Takes an optional approximation-string, defaults to 'about'."
68-
:todo {1 "Use error-margin to compute approx timeline duration, rather than simply taking the lower bounds.
69-
Maybe, an alternate return value can be offered with better approximation, with an 'about' string attached in each return value."
70-
2 "Return a string that can describe the duration as: 5 years, 10 months, 2 weeks, 4 days, and 2 hours."}}
65+
Example: if the duration is between 1 and 2 years (ex: 1 year 10 months), then it will return `1 year`.
66+
Similarly, if the duration is between 10 to 11 months, then it will return `10 months`.
67+
Takes an optional `approximation-string`, defaults to `about`."
68+
:todo {1 "Use `error-margin` to compute approx timeline duration, rather than simply taking the lower bounds.
69+
Maybe, an alternate return value can be offered with better approximation, with an `about` string attached in each return value."
70+
2 "Return a string that can describe the duration as: `5 years, 10 months, 2 weeks, 4 days, and 2 hours.`"}}
7171
readable-duration
7272
[{:keys [start end approximation-string]}]
7373
(cond
@@ -83,11 +83,11 @@
8383
:else (throw (ExceptionInfo. (str "Invalid inputs - :start " start ", :end " end)))))
8484

8585
(defn readable-moment
86-
"Accepts date-string only in the form of 'DD-MM-YYYY' and 'YYYY-MM-DD' formats. DD and MM could just be D or M.
86+
"Accepts `date-string` only in the form of `DD-MM-YYYY` and `YYYY-MM-DD` formats. `DD` and `MM` could just be `D` or `M`.
8787
Describes a moment in histry. Useful for one-time events.
8888
Takes an optional moment descriptor map with the following keys:
89-
:prefix - defaults to 'Happened'.
90-
:suffix - defaults to 'ago'.
89+
- `:prefix` - defaults to `Happened`.
90+
- `:suffix` - defaults to `ago`.
9191
One or both the keys may be provided in the map."
9292
[date-string & moement-desc-map]
9393
(str (or (:prefix (first moement-desc-map)) "Happened")
@@ -127,14 +127,14 @@
127127
(period-helper-end end period-desc-map)))
128128

129129
(defn readable-period
130-
"Accepts start and end values (strings) only in the form of 'DD-MM-YYYY' and 'YYYY-MM-DD' formats. DD and MM could just be D or M.
130+
"Accepts `start` and `end` values (strings) only in the form of `DD-MM-YYYY` and `YYYY-MM-DD` formats. `DD` and `MM` could just be `D` or `M`.
131131
Takes an optional period description map with the following keys:
132-
:start-desc - defaults to 'Started'.
133-
:end-desc - defaults to 'Ended'.
134-
:period-desc - defaults to 'Went on for'.
135-
:approximation-string - defaults to 'about'.
136-
:past-indicator - defaults to 'ago'.
137-
:separator - defaults to ' | '. Note that there are spaces before and after the separator."
132+
- `:start-desc` - defaults to 'Started'.
133+
- `:end-desc` - defaults to 'Ended'.
134+
- `:period-desc` - defaults to 'Went on for'.
135+
- `:approximation-string` - defaults to 'about'.
136+
- `:past-indicator` - defaults to 'ago'.
137+
- `:separator` - defaults to ' | '. Note that there are spaces before and after the separator."
138138
[{:keys [start end period-desc]}]
139139
(cond
140140
(and start (nil? end)) (period-helper-start start period-desc)

Diff for: src/humane_time/ops.cljs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns ^{:doc "Contains data and functions to be used by the functions in the core namespace."
2-
:todo {1 "Possibility of accepting '1918-11-11T11:10:50' date-time format."
2+
:todo {1 "Possibility of accepting `1918-11-11T11:10:50` date-time format."
33
2 "Option for users to provide customer validators."}}
44
humane-time.ops
55
(:require [cljs.reader :as r]
@@ -23,7 +23,7 @@
2323

2424
(defn datetime-descriptor
2525
"Takes a date string and returns a map after some destructuring.
26-
Accepts date-string only in the form of 'DD-MM-YYYY' and 'YYYY-MM-DD' formats. DD and MM could just be D or M."
26+
Accepts date-string only in the form of `DD-MM-YYYY` and `YYYY-MM-DD` formats. `DD` and `MM` could just be `D` or `M`."
2727
[date-string]
2828
(let [ds (clojure.string/split date-string #"-")
2929
y (if (= (count (last ds)) 4) (last ds) (first ds))
@@ -46,9 +46,9 @@
4646
(defn duration-descriptor
4747
"Returns a map that describes the duration between a start and end-time in different units.
4848
For each unit, the value semantics is of lower bound. To elaborate:
49-
If the difference (in years) is 2 years and 10 months, then the value of :years will be 2, not 3. But, the value of :months will be 34.
50-
Similarly, if the difference in months is 5 months and 3 weeks, the the value of :months will be 5, not 6. But, the value of :weeks will be 23.
51-
If no end-time is provided, the the current time will be considered as the end-time."
49+
If the difference (in years) is 2 years and 10 months, then the value of `:years` will be 2, not 3. But, the value of `:months` will be 34.
50+
Similarly, if the difference in months is 5 months and 3 weeks, the the value of `:months` will be 5, not 6. But, the value of `:weeks` will be 23.
51+
If no `end-time` is provided, the the current time will be considered as the `end-time`."
5252
[date-string & end-time]
5353
(let [intrvl (t/interval (:datetime-obj (datetime-descriptor date-string))
5454
(if end-time (:datetime-obj (datetime-descriptor (first end-time))) (t/time-now)))]
@@ -59,6 +59,6 @@
5959
:hours (t/in-hours intrvl)}))
6060

6161
(defn singular->plural
62-
"Simply adds an 's' at the end of the singular-text arg if val is greater than 1."
62+
"Simply adds an `s` at the end of the singular-text arg if `val` is greater than 1."
6363
[singular-text val]
6464
(if (<= val 1) singular-text (str singular-text "s")))

0 commit comments

Comments
 (0)