lantus 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +1,50 @@
1
1
  require 'time'
2
2
 
3
3
  module Lantus
4
- # Author:: Sam (mailto:sam@cruft.co)
5
- # License:: MIT
6
- # OnTrack uses really shitty date formats, including embedding a comma in
7
- # the CSV export file. Christ on a crutch
8
- class AwesomeDate < Hash
9
-
10
- # Parse the string 'd', looking for datetime information
4
+ class AwesomeDate
11
5
  def initialize d
12
- t = Time.parse d
13
-
14
- # We extract loads of stuff. Might be useful one day
15
- self["timestamp"] = t
16
- self["tzoffset"] = t.strftime "%z"
17
- self["timezone"] = t.zone
18
- self["unixtime"] = t.to_i
19
- self["day"] = t.strftime("%A").downcase
20
- self["cardinal_day"] = t.strftime("%-d").to_i
21
- self["ordinal_day"] = "%d%s" % [
22
- self["cardinal_day"],
23
- self.ordinal(self["cardinal_day"])
6
+ @time = Time.parse d
7
+ end
8
+
9
+ def time
10
+ "%s %s" % [
11
+ @time.strftime("%T"),
12
+ @time.zone
13
+ ]
14
+ end
15
+
16
+ def short_time
17
+ @time.strftime "%H:%M"
18
+ end
19
+
20
+ def date
21
+ @time.strftime "%F"
22
+ end
23
+
24
+ def day
25
+ @time.strftime("%A").downcase
26
+ end
27
+
28
+ def cardinal_day
29
+ @time.strftime("%-d").to_i
30
+ end
31
+
32
+ def ordinal_day
33
+ "%d%s" % [
34
+ self.cardinal_day,
35
+ self.ordinal(self.cardinal_day)
24
36
  ]
25
- self["month"] = t.strftime("%B").downcase
26
- self["date"] = t.strftime "%F"
27
- self["time"] = t.strftime "%T #{self['timezone']}"
28
- self["short_time"] = t.strftime "%H:%M"
29
- self["nice_date"] = "%s %s %s" % [
30
- self["day"],
31
- self["month"],
32
- self["ordinal_day"]
37
+ end
38
+
39
+ def month
40
+ @time.strftime("%B").downcase
41
+ end
42
+
43
+ def nice_date
44
+ "%s %s %s" % [
45
+ self.day,
46
+ self.month,
47
+ self.ordinal_day
33
48
  ]
34
49
  end
35
50
 
@@ -1,3 +1,3 @@
1
1
  module Lantus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,51 +1,57 @@
1
- require 'lantus'
2
-
3
- describe Lantus::AwesomeDate do
4
- otd = Lantus::AwesomeDate.new "Jun 22 2012 9:00:12 AM"
5
-
6
- it "should have the correct timestamp" do
7
- otd["timestamp"].to_s.should == "2012-06-22 09:00:12 +0100"
8
- end
9
-
10
- it "should have the correct time" do
11
- otd["time"].should == "09:00:12 BST"
12
- end
13
-
14
- it "should have the correct date" do
15
- otd["date"].should == "2012-06-22"
16
- end
17
-
18
- it "should have the correct day" do
19
- otd["day"].should == "friday"
20
- end
21
-
22
- it "should have the correct month" do
23
- otd["month"].should == "june"
24
- end
25
-
26
- it "should have the correct cardinal day" do
27
- otd["cardinal_day"].should == 22
28
- end
29
-
30
- it "should have the correct ordinal day" do
31
- otd["ordinal_day"].should == "22nd"
32
- end
33
-
34
- it "should have the correct nice_date" do
35
- otd["nice_date"].should == "friday june 22nd"
36
- end
37
-
38
- it "should have the correct short time" do
39
- otd["short_time"].should == "09:00"
40
- end
41
-
42
- otd_gmt = Lantus::AwesomeDate.new "Jan 22 2012 9:00:12 PM"
43
-
44
- it "should have the correct timestamp" do
45
- otd_gmt["timestamp"].to_s.should == "2012-01-22 21:00:12 +0000"
46
- end
47
-
48
- it "should have the correct time and TZ" do
49
- otd_gmt["time"].should == "21:00:12 GMT"
1
+ require 'spec_helper'
2
+
3
+ module Lantus
4
+ describe AwesomeDate, "initialized with 'Jun 22 2012 9:00:12 AM'" do
5
+ before :each do
6
+ @awesome_date = AwesomeDate.new "Jun 22 2012 9:00:12 AM"
7
+ end
8
+
9
+ describe "time" do
10
+ it "should be '09:00:12 BST'" do
11
+ @awesome_date.time.should == "09:00:12 BST"
12
+ end
13
+ end
14
+
15
+ describe "short time" do
16
+ it "should be '09:00'" do
17
+ @awesome_date.short_time.should == "09:00"
18
+ end
19
+ end
20
+
21
+ describe "date" do
22
+ it "should be '2012-06-22'" do
23
+ @awesome_date.date.should == "2012-06-22"
24
+ end
25
+ end
26
+
27
+ describe "day" do
28
+ it "should be 'friday'" do
29
+ @awesome_date.day.should == "friday"
30
+ end
31
+ end
32
+
33
+ describe "cardinal day" do
34
+ it "should be 22" do
35
+ @awesome_date.cardinal_day.should == 22
36
+ end
37
+ end
38
+
39
+ describe "ordinal day" do
40
+ it "should be '22nd'" do
41
+ @awesome_date.ordinal_day.should == "22nd"
42
+ end
43
+ end
44
+
45
+ describe "month" do
46
+ it "should be 'june'" do
47
+ @awesome_date.month.should == "june"
48
+ end
49
+ end
50
+
51
+ describe "nice date" do
52
+ it "should be 'friday june 22nd'" do
53
+ @awesome_date.nice_date.should == "friday june 22nd"
54
+ end
55
+ end
50
56
  end
51
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lantus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-20 00:00:00.000000000 Z
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec