Sha256: c4cfda9467f5cbe1cb280cb18f1b1150b4d0c1485a6f75e2b01886f15e471a0d

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

require 'time'

module Lantus
  class AwesomeDate
    def initialize d
      @time = Time.parse d
    end

    def time
      "%s %s" % [
        @time.strftime("%T"),
        @time.zone
      ]
    end

    def short_time
      @time.strftime "%H:%M"
    end

    def date
      @time.strftime "%F"
    end

    def day
      @time.strftime("%A").downcase
    end

    def cardinal_day
      @time.strftime("%-d").to_i
    end

    def ordinal_day
      "%d%s" % [
        self.cardinal_day,
        self.ordinal(self.cardinal_day)
      ]
    end

    def month
      @time.strftime("%B").downcase
    end

    def nice_date
      "%s %s %s" % [
        self.day,
        self.month,
        self.ordinal_day
      ]
    end

    def ordinal cardinal
      last_digit = cardinal % 10
      case last_digit
        when 1
          "st"
        when 2
          "nd"
        when 3
          "rd"
        else
          "th"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lantus-0.0.2 lib/lantus/awesome_date.rb