Sha256: 3692d49586baf4a6f23429989ed1242d8cad4f81ce3163fb8858a819055a847c

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

class NSDate
  def year
    return components(NSYearCalendarUnit).year
  end

  def month
    return components(NSMonthCalendarUnit).month
  end

  def day
    return components(NSDayCalendarUnit).day
  end

  def ymd
    return [self.year, self.month, self.day]
  end

  def weekday
    return components(NSWeekdayCalendarUnit).weekday
  end

  def hour
    return components(NSHourCalendarUnit).hour
  end

  def minute
    return components(NSMinuteCalendarUnit).minute
  end

  def second
    return components(NSSecondCalendarUnit).second
  end

  def timezone
    return components(NSTimeZoneCalendarUnit).timeZone
  end
  alias timeZone timezone

  def utc_offset
    return self.timezone.secondsFromGMT
  end

  def hms
    return [self.hour, self.minute, self.second]
  end

  def datetime
    return [self.year, self.month, self.day, self.hour, self.minute, self.second]
  end

  def +(time_interval)
    return self.dateByAddingTimeInterval(time_interval)
  end

  private
  def components(components)
    unless (@@calendar ||= nil)
      @@calendar = NSCalendar.alloc.initWithCalendarIdentifier(NSGregorianCalendar)
    end
    return @@calendar.components(components, fromDate:self)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sugarcube-0.8.7 lib/sugarcube/nsdate.rb
sugarcube-0.8.6 lib/sugarcube/nsdate.rb