- ago
- at_beginning_of_day
- at_beginning_of_month
- at_beginning_of_week
- at_beginning_of_year
- at_midnight
- beginning_of_day
- beginning_of_month
- beginning_of_week
- beginning_of_year
- from_string
- in
- in_day_range?
- last_month
- last_year
- midnight
- monday
- months_ago
- months_since
- next_month
- next_week
- next_year
- seconds_since_midnight
- since
- start_of_day
- to_end_of_day
- to_start_of_day
- tomorrow
- years_ago
- years_since
- yesterday
NEVER | = | Time.mktime(2038) |
ZERO | = | Time.mktime(1972) |
[ show source ]
# File lib/facets/more/typecast.rb, line 219 def from_string(string, options={}) parse(string) rescue nil end
Returns a new Time representing the time a number of seconds ago. Do not use this method in combination with x.months, use months_ago instead!
[ show source ]
# File lib/facets/more/times.rb, line 115 def ago(seconds) # This is basically a wrapper around the Numeric extension. #seconds.until(self) self - seconds end
Alias for beginning_of_day
Alias for beginning_of_month
Alias for beginning_of_week
Alias for beginning_of_year
Alias for beginning_of_day
Returns a new Time representing the start of the day (0:00)
[ show source ]
# File lib/facets/more/times.rb, line 201 def beginning_of_day self - self.seconds_since_midnight end
Returns a new Time representing the start of the month (1st of the month, 0:00)
[ show source ]
# File lib/facets/more/times.rb, line 211 def beginning_of_month #self - ((self.mday-1).days + self.seconds_since_midnight) change(:mday => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0) end
Returns a new Time representing the "start" of this week (Monday, 0:00)
[ show source ]
# File lib/facets/more/times.rb, line 180 def beginning_of_week (self - self.wday.days).midnight + 1.day end
Returns a new Time representing the start of the year (1st of january, 0:00)
[ show source ]
# File lib/facets/more/times.rb, line 218 def beginning_of_year change(:month => 1,:mday => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0) end
Alias for since
Returns true only if day of time is included in the range (stime..etime). Only year days are checked.
[ show source ]
# File lib/facets/more/times.rb, line 247 def in_day_range?(stime=ZERO, etime=NEVER) if (etime <= stime) warn "invalid end time (#{etime} < #{stime})" if $DEBUG etime = NEVER end stime = stime.to_start_of_day etime = etime.to_end_of_day return (stime..etime).include?(time) end
Short-hand for months_ago(1)
[ show source ]
# File lib/facets/more/times.rb, line 170 def last_month months_ago(1) end
Short-hand for months_ago(1)
[ show source ]
# File lib/facets/more/times.rb, line 160 def last_year years_since(1) end
Alias for beginning_of_day
Alias for beginning_of_week
Returns a new Time representing the time a number of specified months ago.
[ show source ]
# File lib/facets/more/times.rb, line 133 def months_ago(months) if months >= self.month change(:year => self.year - 1, :month => 12).months_ago(months - self.month) else change(:year => self.year, :month => self.month - months) end end
[ show source ]
# File lib/facets/more/times.rb, line 141 def months_since(months) if months + self.month > 12 change(:year => self.year + 1, :month => 1).months_since(months - (self.month == 1 ? 12 : (self.month + 1))) else change(:year => self.year, :month => self.month + months) end end
Short-hand for months_since(1)
[ show source ]
# File lib/facets/more/times.rb, line 175 def next_month months_since(1) end
Returns a new Time representing the start of the given day in next week (default is Monday).
[ show source ]
# File lib/facets/more/times.rb, line 188 def next_week(day = :monday) days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6 } since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) end
Short-hand for months_since(1)
[ show source ]
# File lib/facets/more/times.rb, line 165 def next_year years_since(1) end
Seconds since midnight: Time.now.seconds_since_midnight
[ show source ]
# File lib/facets/more/times.rb, line 109 def seconds_since_midnight self.hour.hours + self.min.minutes + self.sec + (self.usec/1.0e+6) end
Returns a new Time representing the time a number of seconds since the instance time. Do not use this method in combination with x.months, use months_since instead!
[ show source ]
# File lib/facets/more/times.rb, line 124 def since(seconds) # This is basically a wrapper around the Numeric extension. #seconds.since(self) self + seconds end
Alias for beginning_of_day
Rrturns a new time at end of day
[ show source ]
# File lib/facets/more/times.rb, line 241 def to_end_of_day return Time.mktime(year, month, day, 23, 59, 59, 999) end
Returns a new time at start of day
[ show source ]
# File lib/facets/more/times.rb, line 236 def to_start_of_day return Time.mktime(year, month, day, 0, 0, 0, 0) end
Convenience method which returns a new Time representing the time 1 day since the instance time
[ show source ]
# File lib/facets/more/times.rb, line 231 def tomorrow self.since(1.day) end
Returns a new Time representing the time a number of specified years ago.
[ show source ]
# File lib/facets/more/times.rb, line 151 def years_ago(years) change(:year => self.year - years) end
[ show source ]
# File lib/facets/more/times.rb, line 155 def years_since(years) change(:year => self.year + years) end
Convenience method which returns a new Time representing the time 1 day ago
[ show source ]
# File lib/facets/more/times.rb, line 225 def yesterday self.ago(1.day) end