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.
- data/lib/lantus/awesome_date.rb +42 -27
- data/lib/lantus/version.rb +1 -1
- data/spec/awesome_date_spec.rb +55 -49
- metadata +2 -2
data/lib/lantus/awesome_date.rb
CHANGED
@@ -1,35 +1,50 @@
|
|
1
1
|
require 'time'
|
2
2
|
|
3
3
|
module Lantus
|
4
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
|
data/lib/lantus/version.rb
CHANGED
data/spec/awesome_date_spec.rb
CHANGED
@@ -1,51 +1,57 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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.
|
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-
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|