Methods
Constants
NEVER = Time.mktime(2038)
ZERO = Time.mktime(1972)
Public Class methods
from_string(string, options={})
# File lib/facets/more/typecast.rb, line 219
    def from_string(string, options={})
      parse(string)
    rescue
      nil
    end
Public Instance methods
ago(seconds)

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!

# 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
at_beginning_of_day()

Alias for beginning_of_day

at_beginning_of_month()

Alias for beginning_of_month

at_beginning_of_week()

Alias for beginning_of_week

at_beginning_of_year()

Alias for beginning_of_year

at_midnight()

Alias for beginning_of_day

beginning_of_day()

Returns a new Time representing the start of the day (0:00)

This method is also aliased as midnight at_midnight at_beginning_of_day start_of_day
# File lib/facets/more/times.rb, line 201
  def beginning_of_day
    self - self.seconds_since_midnight
  end
beginning_of_month()

Returns a new Time representing the start of the month (1st of the month, 0:00)

This method is also aliased as at_beginning_of_month
# 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
beginning_of_week()

Returns a new Time representing the "start" of this week (Monday, 0:00)

This method is also aliased as monday at_beginning_of_week
# File lib/facets/more/times.rb, line 180
  def beginning_of_week
    (self - self.wday.days).midnight + 1.day
  end
beginning_of_year()

Returns a new Time representing the start of the year (1st of january, 0:00)

This method is also aliased as at_beginning_of_year
# 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
in(seconds)

Alias for since

in_day_range?(stime=ZERO, etime=NEVER)

Returns true only if day of time is included in the range (stime..etime). Only year days are checked.

# 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
last_month()

Short-hand for months_ago(1)

# File lib/facets/more/times.rb, line 170
  def last_month
    months_ago(1)
  end
last_year()

Short-hand for months_ago(1)

# File lib/facets/more/times.rb, line 160
  def last_year
    years_since(1)
  end
midnight()

Alias for beginning_of_day

monday()

Alias for beginning_of_week

months_ago(months)

Returns a new Time representing the time a number of specified months ago.

# 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
months_since(months)
# 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
next_month()

Short-hand for months_since(1)

# File lib/facets/more/times.rb, line 175
  def next_month
    months_since(1)
  end
next_week(day = :monday)

Returns a new Time representing the start of the given day in next week (default is Monday).

# 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
next_year()

Short-hand for months_since(1)

# File lib/facets/more/times.rb, line 165
  def next_year
    years_since(1)
  end
seconds_since_midnight()

Seconds since midnight: Time.now.seconds_since_midnight

# 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
since(seconds)

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!

This method is also aliased as in
# 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
start_of_day()

Alias for beginning_of_day

to_end_of_day()

Rrturns a new time at end of day

# File lib/facets/more/times.rb, line 241
  def to_end_of_day
    return Time.mktime(year, month, day, 23, 59, 59, 999)
  end
to_start_of_day()

Returns a new time at start of day

# File lib/facets/more/times.rb, line 236
  def to_start_of_day
    return Time.mktime(year, month, day, 0, 0, 0, 0)
  end
tomorrow()

Convenience method which returns a new Time representing the time 1 day since the instance time

# File lib/facets/more/times.rb, line 231
  def tomorrow
    self.since(1.day)
  end
years_ago(years)

Returns a new Time representing the time a number of specified years ago.

# File lib/facets/more/times.rb, line 151
  def years_ago(years)
    change(:year => self.year - years)
  end
years_since(years)
# File lib/facets/more/times.rb, line 155
  def years_since(years)
    change(:year => self.year + years)
  end
yesterday()

Convenience method which returns a new Time representing the time 1 day ago

# File lib/facets/more/times.rb, line 225
  def yesterday
    self.ago(1.day)
  end