Skip to content

Commit 03f02a3

Browse files
authored
Merge pull request #268 from silva96/duration-since
In durations, make sure method usage reads as plain english
2 parents aaac037 + b2793c0 commit 03f02a3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.adoc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,51 @@ Time.zone.now # => Fri, 12 Mar 2014 22:04:47 EET +02:00
15331533
Time.current # Same thing but shorter.
15341534
----
15351535

1536+
== Duration
1537+
1538+
If used without a parameter, prefer `from_now` and `ago` instead of `since`, `after`, `until` or `before`.
1539+
1540+
[source,ruby]
1541+
----
1542+
# bad - It's not clear 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
1547+
1548+
# good
1549+
5.hours.from_now
1550+
5.hours.ago
1551+
----
1552+
1553+
If used with a parameter, prefer `since`, `after`, `until` or `before` instead of `from_now` and `ago`.
1554+
1555+
[source,ruby]
1556+
----
1557+
# bad - It's confusing and misleading to read
1558+
2.days.from_now(yesterday)
1559+
2.days.ago(yesterday)
1560+
1561+
# good
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 negative numbers for the duration subject. Always prefer using a qualifier that allows using positive literal numbers.
1569+
1570+
[source,ruby]
1571+
----
1572+
# bad - It's confusing and misleading to read
1573+
-5.hours.from_now
1574+
-5.hours.ago
1575+
1576+
# good
1577+
5.hours.ago
1578+
5.hours.from_now
1579+
----
1580+
15361581
== Bundler
15371582

15381583
=== Dev/Test Gems [[dev-test-gems]]

0 commit comments

Comments
 (0)