Skip to content

Commit 64b467c

Browse files
authored
separate examples and rephrase statements
1 parent ee59832 commit 64b467c

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

README.adoc

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,43 +1535,47 @@ Time.current # Same thing but shorter.
15351535

15361536
== Duration
15371537

1538-
Don't use `.since`, `.after` without a parameter, prefer `.from_now`.
1538+
If used without a parameter, prefer `from_now` and `ago` instead of `since`, `after`, `until` or `before`.
15391539

1540-
Dont't use `.until`, `.before`, without a parameter, prefer `ago`.
1541-
1542-
Dont't use `.ago' or `.from_now` with a parameter, prefer their respective aliases `.until` or `.before` for `ago` and `.since` or `.after` for `from_now`
1540+
[source,ruby]
1541+
----
1542+
# bad - It's not clear at first sight that the qualifier refers to the current time (which is the default parameter)
1543+
5.hours.since
1544+
5.hours.after
1545+
5.hours.before
1546+
5.hours.until
15431547
1544-
Don't use hard coded negative numbers for the duration subject
1548+
# good
1549+
5.hours.from_now
1550+
5.hours.ago
1551+
----
15451552

1546-
As a general rule, make sure that reading the code as it was plain english makes total sense.
1553+
If used with a parameter, prefer `since`, `after`, `until` or `before` instead of `from_now` and `ago`.
15471554

15481555
[source,ruby]
15491556
----
1550-
# bad
1551-
5.hours.since # => It's not clear at first sight that `since` refers to "since now"
1552-
5.hours.after # => It's not clear at first sight that `after` refers to "after now"
1553-
5.hours.before # => It's not clear at first sight that `before` refers to "before now"
1554-
5.hours.until # => It's not clear at first sight that `until` refers to "until now"
1555-
1556-
tomorrow = 2.days.from_now(yesterday) # yesterday would be 1.day.ago, reading this is confusing
1557-
today = 1.day.ago(tomorrow)
1557+
# bad - It's confusing and misleading to read
1558+
2.days.from_now(yesterday)
1559+
2.days.ago(yesterday)
15581560
1559-
1560-
-5.hours.from_now # reading this is confusing
1561-
-5.hours.ago # reading this is confusing
1562-
-5.hours.after(today)
15631561
# good
1564-
5.hours.from_now # when refering a future time from now, use from_now
1565-
5.hours.ago # when refering a past time from now, use ago
1562+
2.days.since(yesterday)
1563+
2.days.after(yesterday)
1564+
2.days.before(yesterday)
1565+
2.days.until(yesterday)
1566+
----
1567+
1568+
Avoid using literal negative numbers for the duration subject. Always prefer using a qualifier that allows using positive literal numbers.
15661569

1567-
tomorrow = 2.days.since(yesterday) # use since only when you have a referential Time in the past
1568-
tomorrow = 2.days.after(yesterday) # use after only when you have a referential Time in the past
1569-
today = 1.day.before(tomorrow) # use before only when you have a referential Time in the future
1570-
today = 1.day.until(tomorrow) # use until only when you have a referential Time in the future
1570+
[source,ruby]
1571+
----
1572+
# bad - It's confusing and misleading to read
1573+
-5.hours.from_now
1574+
-5.hours.ago
15711575
1572-
5.hours.ago # use the inverse method instead of the inverse number, -5.hours.from_now becomes 5.hours.ago
1573-
5.hours.ago # use the inverse method instead of the inverse number, -5.hours.ago becomes 5.hours.ago
1574-
5.hours.before(today)
1576+
# good
1577+
5.hours.ago
1578+
5.hours.from_now
15751579
----
15761580

15771581
== Bundler

0 commit comments

Comments
 (0)