lib/lantus/awesome_date.rb in lantus-0.0.1 vs lib/lantus/awesome_date.rb in lantus-0.0.2
- old
+ new
@@ -1,36 +1,51 @@
require 'time'
module Lantus
-# Author:: Sam (mailto:sam@cruft.co)
-# License:: MIT
- # OnTrack uses really shitty date formats, including embedding a comma in
- # the CSV export file. Christ on a crutch
- class AwesomeDate < Hash
-
- # Parse the string 'd', looking for datetime information
+ class AwesomeDate
def initialize d
- t = Time.parse d
+ @time = Time.parse d
+ end
- # We extract loads of stuff. Might be useful one day
- self["timestamp"] = t
- self["tzoffset"] = t.strftime "%z"
- self["timezone"] = t.zone
- self["unixtime"] = t.to_i
- self["day"] = t.strftime("%A").downcase
- self["cardinal_day"] = t.strftime("%-d").to_i
- self["ordinal_day"] = "%d%s" % [
- self["cardinal_day"],
- self.ordinal(self["cardinal_day"])
+ def time
+ "%s %s" % [
+ @time.strftime("%T"),
+ @time.zone
]
- self["month"] = t.strftime("%B").downcase
- self["date"] = t.strftime "%F"
- self["time"] = t.strftime "%T #{self['timezone']}"
- self["short_time"] = t.strftime "%H:%M"
- self["nice_date"] = "%s %s %s" % [
- self["day"],
- self["month"],
- self["ordinal_day"]
+ 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