Sha256: feadd655e82c7c84452489e8ad5fe197b270430775e9ba13c9468ff429d7e315

Contents?: true

Size: 963 Bytes

Versions: 1

Compression:

Stored size: 963 Bytes

Contents

class ::Date
  def to_tc_date
    TimeCrisis::Date.civil(year, month, day)
  end

  def to_tc_datetime
    TimeCrisis::DateTime.civil(year, month, day, 0, 0, 0, 0)
  end
  
  def to_tc_time(form = :local)
    ::TimeCrisis::Time.send(form, year, month, day)
  end
end

class ::Time
  def to_tc_date
    TimeCrisis::Date.civil(year, month, day)
  end

  def to_tc_datetime
    TimeCrisis::DateTime.civil(year, month, day, hour, min, sec, 0, utc_offset)
  end
  
  def to_tc_time
    TimeCrisis::Time.at(self.to_f)
  end
end

class ::DateTime
  def to_tc_date
    TimeCrisis::Date.civil(year, month, day)
  end

  def to_tc_datetime
    TimeCrisis::DateTime.civil(year, month, day, hour, min, sec, 0, (offset * 86400).to_i)
  end
  
  def to_tc_time
    TimeCrisis::Time.at(self.to_f)
  end
end

class ::String
  def to_tc_date(opts={})
    TimeCrisis::Date.parse(self, opts)
  end

  def to_tc_datetime(opts={})
    TimeCrisis::DateTime.parse(self, opts)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_crisis-0.3.5 lib/time_crisis/conversions.rb