Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/time_ext/time.rb
Instance Method Summary (collapse)
-
- (Object) beginning_of_hour
(also: #at_beginning_of_hour)
Returns a new Time representing the start of the hour (XX:00:00).
-
- (Object) beginning_of_minute
(also: #at_beginning_of_min, #beginning_of_min, #at_beginning_of_minute)
Returns a new Time representing the start of the minute (XX:XX:00).
-
- (Object) beginning_of_second
(also: #at_beginning_of_sec, #beginning_of_sec, #at_beginning_of_second)
Returns a new Time representing the start of the second, XX:XX:XX.000000 (.000000000 in ruby1.9).
-
- (Object) ceil(unit = :sec)
(also: #beginning_of_next, #at_beginning_of_next)
Returns a new Time representing the start of the next unit specified (second by default).
-
- (Object) common_year_days_in_month
Helper method for backwards compatibility with ActiveSupport.
-
- (Object) days_ago(days)
Returns a new Time representing the time a number of specified days ago.
-
- (Object) days_into_week
Helper method for backwards compatibility with ActiveSupport.
-
- (Object) days_since(days)
Returns a new Time representing the time a number of specified days in the future.
-
- (Object) end_of_hour
Returns a new Time representing the end of the hour, XX:59:59.999999 (.999999999 in ruby1.9).
-
- (Object) end_of_minute
(also: #end_of_min)
Returns a new Time representing the end of the hour, XX:XX:59.999999 (.999999999 in ruby1.9).
-
- (Object) end_of_second
(also: #end_of_sec)
Returns a new Time representing the end of the hour, XX:XX:XX.999999 (.999999999 in ruby1.9).
-
- (Object) floor(unit = :sec)
(also: #at_beginning_of, #beginning_of)
Returns a new Time representing the start of the unit specified (second by default).
-
- (Object) hours_ago(hours)
Returns a new Time representing the time a number of specified hours ago.
-
- (Object) hours_since(hours)
Returns a new Time representing the time a number of specified hours in the future.
-
- (Object) minutes_ago(minutes)
(also: #mins_ago)
Returns a new Time representing the time a number of specified minutes ago.
-
- (Object) minutes_since(minutes)
(also: #mins_since)
Returns a new Time representing the time a number of specified minutes in the future.
-
- (Object) next_day
Short-hand for days_since(1).
-
- (Object) next_hour
Short-hand for hours_since(1).
-
- (Object) next_minute
(also: #next_min)
Short-hand for minutes_since(1).
-
- (Object) next_quarter
Short-hand for quarters_since(1).beginning_of_quarter.
-
- (Object) next_second
(also: #next_sec)
Short-hand for seconds_since(1).
-
- (Object) prev_day
Short-hand for days_ago(1).
-
- (Object) prev_hour
Short-hand for hours_ago(1).
-
- (Object) prev_minute
(also: #prev_min)
Short-hand for minutes_ago(1).
-
- (Object) prev_quarter
Short-hand for quarters_ago(1).beginning_of_quarter.
-
- (Object) prev_second
(also: #prev_sec)
Short-hand for seconds_ago(1).
-
- (Object) prev_week(day = :monday)
Returns a new Time representing the start of the given day in the previous week (default is Monday).
-
- (Object) quarters_ago(quarters)
Returns a new Time representing the time a number of specified quarters (3 months) ago.
-
- (Object) quarters_since(quarters)
Returns a new Time representing the time a number of specified quarters (3 months) in the future.
-
- (Object) round(unit = :sec)
(also: #beginning_of_closest)
Returns a new Time representing the start of the current or next unit specified (second by default) depending which is closest.
-
- (Object) weeks_ago(weeks)
Returns a new Time representing the time a number of specified weeks ago.
-
- (Object) weeks_since(weeks)
Returns a new Time representing the time a number of specified weeks in the future.
Instance Method Details
- (Object) beginning_of_hour Also known as: at_beginning_of_hour
Returns a new Time representing the start of the hour (XX:00:00).
181 182 183 |
# File 'lib/time_ext/time.rb', line 181 def beginning_of_hour change(:min => 0, :sec => 0, :usec => 0) end |
- (Object) beginning_of_minute Also known as: at_beginning_of_min, beginning_of_min, at_beginning_of_minute
Returns a new Time representing the start of the minute (XX:XX:00).
167 168 169 |
# File 'lib/time_ext/time.rb', line 167 def beginning_of_minute change(:sec => 0, :usec => 0) end |
- (Object) beginning_of_second Also known as: at_beginning_of_sec, beginning_of_sec, at_beginning_of_second
Returns a new Time representing the start of the second, XX:XX:XX.000000 (.000000000 in ruby1.9).
153 154 155 |
# File 'lib/time_ext/time.rb', line 153 def beginning_of_second change(:usec => 0) end |
- (Object) ceil(unit = :sec) Also known as: beginning_of_next, at_beginning_of_next
Returns a new Time representing the start of the next unit specified (second by default).
21 22 23 |
# File 'lib/time_ext/time.rb', line 21 def ceil(unit = :sec) self.send("next_#{unit}").send("beginning_of_#{unit}") end |
- (Object) common_year_days_in_month
Helper method for backwards compatibility with ActiveSupport.
9 10 11 |
# File 'lib/time_ext/time.rb', line 9 def common_year_days_in_month defined?(COMMON_YEAR_DAYS_IN_MONTH) ? COMMON_YEAR_DAYS_IN_MONTH : [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] end |
- (Object) days_ago(days)
Returns a new Time representing the time a number of specified days ago.
123 124 125 |
# File 'lib/time_ext/time.rb', line 123 def days_ago(days) ago(days.days) end |
- (Object) days_into_week
Helper method for backwards compatibility with ActiveSupport.
4 5 6 |
# File 'lib/time_ext/time.rb', line 4 def days_into_week defined?(DAYS_INTO_WEEK) ? DAYS_INTO_WEEK : { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6 } end |
- (Object) days_since(days)
Returns a new Time representing the time a number of specified days in the future.
128 129 130 |
# File 'lib/time_ext/time.rb', line 128 def days_since(days) since(days.days) end |
- (Object) end_of_hour
Returns a new Time representing the end of the hour, XX:59:59.999999 (.999999999 in ruby1.9).
187 188 189 |
# File 'lib/time_ext/time.rb', line 187 def end_of_hour change(:min => 59, :sec => 59, :usec => 999999.999) end |
- (Object) end_of_minute Also known as: end_of_min
Returns a new Time representing the end of the hour, XX:XX:59.999999 (.999999999 in ruby1.9).
175 176 177 |
# File 'lib/time_ext/time.rb', line 175 def end_of_minute change(:sec => 59, :usec => 999999.999) end |
- (Object) end_of_second Also known as: end_of_sec
Returns a new Time representing the end of the hour, XX:XX:XX.999999 (.999999999 in ruby1.9).
161 162 163 |
# File 'lib/time_ext/time.rb', line 161 def end_of_second change(:usec => 999999.999) end |
- (Object) floor(unit = :sec) Also known as: at_beginning_of, beginning_of
Returns a new Time representing the start of the unit specified (second by default).
14 15 16 |
# File 'lib/time_ext/time.rb', line 14 def floor(unit = :sec) self.send("beginning_of_#{unit}") end |
- (Object) hours_ago(hours)
Returns a new Time representing the time a number of specified hours ago.
113 114 115 |
# File 'lib/time_ext/time.rb', line 113 def hours_ago(hours) ago(hours.hours) end |
- (Object) hours_since(hours)
Returns a new Time representing the time a number of specified hours in the future.
118 119 120 |
# File 'lib/time_ext/time.rb', line 118 def hours_since(hours) since(hours.hours) end |
- (Object) minutes_ago(minutes) Also known as: mins_ago
Returns a new Time representing the time a number of specified minutes ago.
101 102 103 |
# File 'lib/time_ext/time.rb', line 101 def minutes_ago(minutes) ago(minutes.minutes) end |
- (Object) minutes_since(minutes) Also known as: mins_since
Returns a new Time representing the time a number of specified minutes in the future.
107 108 109 |
# File 'lib/time_ext/time.rb', line 107 def minutes_since(minutes) since(minutes.minutes) end |
- (Object) next_day
Short-hand for days_since(1).
75 76 77 |
# File 'lib/time_ext/time.rb', line 75 def next_day days_since(1) end |
- (Object) next_hour
Short-hand for hours_since(1).
65 66 67 |
# File 'lib/time_ext/time.rb', line 65 def next_hour hours_since(1) end |
- (Object) next_minute Also known as: next_min
Short-hand for minutes_since(1).
54 55 56 |
# File 'lib/time_ext/time.rb', line 54 def next_minute minutes_since(1) end |
- (Object) next_quarter
Short-hand for quarters_since(1).beginning_of_quarter.
85 86 87 |
# File 'lib/time_ext/time.rb', line 85 def next_quarter quarters_since(1).beginning_of_quarter end |
- (Object) next_second Also known as: next_sec
Short-hand for seconds_since(1).
42 43 44 |
# File 'lib/time_ext/time.rb', line 42 def next_second since(1) end |
- (Object) prev_day
Short-hand for days_ago(1).
70 71 72 |
# File 'lib/time_ext/time.rb', line 70 def prev_day days_ago(1) end |
- (Object) prev_hour
Short-hand for hours_ago(1).
60 61 62 |
# File 'lib/time_ext/time.rb', line 60 def prev_hour hours_ago(1) end |
- (Object) prev_minute Also known as: prev_min
Short-hand for minutes_ago(1).
48 49 50 |
# File 'lib/time_ext/time.rb', line 48 def prev_minute minutes_ago(1) end |
- (Object) prev_quarter
Short-hand for quarters_ago(1).beginning_of_quarter.
90 91 92 |
# File 'lib/time_ext/time.rb', line 90 def prev_quarter quarters_ago(1).beginning_of_quarter end |
- (Object) prev_second Also known as: prev_sec
Short-hand for seconds_ago(1).
36 37 38 |
# File 'lib/time_ext/time.rb', line 36 def prev_second ago(1) end |
- (Object) prev_week(day = :monday)
Returns a new Time representing the start of the given day in the previous week (default is Monday).
80 81 82 |
# File 'lib/time_ext/time.rb', line 80 def prev_week(day = :monday) weeks_ago(1).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) end |
- (Object) quarters_ago(quarters)
Returns a new Time representing the time a number of specified quarters (3 months) ago.
143 144 145 |
# File 'lib/time_ext/time.rb', line 143 def quarters_ago(quarters) ago((quarters * 3).months) end |
- (Object) quarters_since(quarters)
Returns a new Time representing the time a number of specified quarters (3 months) in the future.
148 149 150 |
# File 'lib/time_ext/time.rb', line 148 def quarters_since(quarters) since((quarters * 3).months) end |
- (Object) round(unit = :sec) Also known as: beginning_of_closest
Returns a new Time representing the start of the current or next unit specified (second by default) depending which is closest
28 29 30 31 32 |
# File 'lib/time_ext/time.rb', line 28 def round(unit = :sec) next_unit = self.ceil(unit) this_unit = self.floor(unit) (self - this_unit) < (next_unit - self) ? this_unit : next_unit end |
- (Object) weeks_ago(weeks)
Returns a new Time representing the time a number of specified weeks ago.
133 134 135 |
# File 'lib/time_ext/time.rb', line 133 def weeks_ago(weeks) ago(weeks.weeks) end |
- (Object) weeks_since(weeks)
Returns a new Time representing the time a number of specified weeks in the future.
138 139 140 |
# File 'lib/time_ext/time.rb', line 138 def weeks_since(weeks) since(weeks.weeks) end |