Skip to content

Commit 4f503e8

Browse files
transclaude
andcommitted
Review Time and Symbol methods
- Rename Time#trunc to Time#floor_to (parallels round_to; avoids confusion with Ruby's Time#floor). Deprecate trunc. - Symbol: 14 methods reviewed, all clean, no changes needed Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e16906e commit 4f503e8

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ Changes:
101101
* Deprecate `Enumerable#mash` (use `Enumerable#graph` instead).
102102
* Deprecate `Enumerable#uniq_by` (use `Enumerable#uniq(&block)`, Ruby 1.9.2+).
103103
* Redefine `String#lchomp` / `#lchomp!` as aliases for `delete_prefix` / `delete_prefix!`.
104+
* Rename `Time#trunc` to `Time#floor_to` (parallels `Time#round_to`; avoids confusion
105+
with Ruby's `Time#floor` which takes sub-second digit precision). `trunc` deprecated.
104106
* Fix dead requires for removed `kernel/singleton_class` in Proc and Kernel.
105107
* Remove misplaced `applique/file_helpers` from core (test infrastructure).
106108
* Drop unused `test_files` directive from gemspec. (PR#301)

lib/core/facets/time/trunc.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
class Time
22

3-
# Truncate time at give range (in seconds).
3+
# Truncate time to a given interval in seconds.
4+
# Unlike Ruby's Time#floor which takes sub-second digit precision,
5+
# this takes an interval in seconds.
46
#
57
# t = Time.now
6-
# t = t.trunc(60*60)
8+
# t = t.floor_to(60*60)
79
# t.min #=> 0
810
# t.sec #=> 0
911
#
10-
def trunc(amount)
11-
self - (self.to_i % amount)
12+
def floor_to(seconds)
13+
self - (self.to_i % seconds)
1214
end
1315

14-
end
16+
# @deprecated Use Time#floor_to instead.
17+
def trunc(seconds)
18+
warn "Time#trunc is deprecated. Use Time#floor_to instead.", uplevel: 1
19+
floor_to(seconds)
20+
end
1521

22+
end

0 commit comments

Comments
 (0)