kronos 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -72,11 +72,11 @@ With Kronos, you can compare date objects as follows:
72
72
 
73
73
  ### A Note about Kronos Comparison Operators
74
74
 
75
- Kronos interprets "<" as "Does the date interval on the left occur completely before the date interval on the right?" In other words, if there is overlap, the result will be false.
75
+ Kronos interprets `<` as "Does the date interval on the left occur completely before the date interval on the right?" In other words, if there is overlap, the result will be false.
76
76
 
77
- Here's an example. If you ask "Does the year 1974 came before March 1974?" a careful response might be: "Actually, part of it comes before and part of it comes after. Your question does not really make sense because March 1974 is contained within the year 1974."
77
+ Here's an example. If you ask "Does the year 1974 come before March 1974?" a careful response might be: "Actually, part of it comes before and part of it comes after. Your question does not really make sense because March 1974 is contained within the year 1974."
78
78
 
79
- Because of this, Konos comparison operators (<, ==, >) behave a little bit differently for Kronos objects than for, say, integers. Given any two integers m and n, you can be sure that one of the operators holds. For example:
79
+ Because of this, Konos comparison operators (`<`, `==`, `>`) behave a little bit differently for Kronos objects than for, say, integers. Given any two integers m and n, you can be sure that one of the operators holds. For example:
80
80
 
81
81
  m = 1
82
82
  n = 2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kronos}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David James"]
@@ -26,7 +26,8 @@ Gem::Specification.new do |s|
26
26
  "kronos.gemspec",
27
27
  "lib/kronos.rb",
28
28
  "spec/compare_spec.rb",
29
- "spec/kronos_spec.rb",
29
+ "spec/from_hash_spec.rb",
30
+ "spec/parse_spec.rb",
30
31
  "spec/spec.opts",
31
32
  "spec/spec_helper.rb",
32
33
  "spec/valid_spec.rb"
@@ -38,7 +39,8 @@ Gem::Specification.new do |s|
38
39
  s.summary = %q{Simple and flexible date parsing.}
39
40
  s.test_files = [
40
41
  "spec/compare_spec.rb",
41
- "spec/kronos_spec.rb",
42
+ "spec/from_hash_spec.rb",
43
+ "spec/parse_spec.rb",
42
44
  "spec/spec_helper.rb",
43
45
  "spec/valid_spec.rb"
44
46
  ]
@@ -125,6 +125,14 @@ class Kronos
125
125
  h
126
126
  end
127
127
 
128
+ def self.from_hash(h)
129
+ o = self.new
130
+ o.year = h['year'] if h['year']
131
+ o.month = h['month'] if h['month']
132
+ o.day = h['day'] if h['day']
133
+ o if o.valid?
134
+ end
135
+
128
136
  def self.parse(string)
129
137
  self.new.parse(string)
130
138
  end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Kronos from_hash" do
4
+
5
+ it "2002" do
6
+ k = Kronos.from_hash({
7
+ 'year' => 2002,
8
+ })
9
+ k.year.should == 2002
10
+ k.month.should == nil
11
+ k.day.should == nil
12
+ end
13
+
14
+ it "November 2002" do
15
+ k = Kronos.from_hash({
16
+ 'year' => 2002,
17
+ 'month' => 11,
18
+ })
19
+ k.year.should == 2002
20
+ k.month.should == 11
21
+ k.day.should == nil
22
+ end
23
+
24
+ it "November 9, 2002" do
25
+ k = Kronos.from_hash({
26
+ 'year' => 2002,
27
+ 'month' => 11,
28
+ 'day' => 9,
29
+ })
30
+ k.year.should == 2002
31
+ k.month.should == 11
32
+ k.day.should == 9
33
+ end
34
+
35
+ it "Malformed: ? 9, 2002" do
36
+ k = Kronos.from_hash({
37
+ 'year' => 2002,
38
+ 'month' => nil,
39
+ 'day' => 9,
40
+ })
41
+ k.should == nil
42
+ end
43
+ end
File without changes
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - David James
@@ -50,7 +50,8 @@ files:
50
50
  - kronos.gemspec
51
51
  - lib/kronos.rb
52
52
  - spec/compare_spec.rb
53
- - spec/kronos_spec.rb
53
+ - spec/from_hash_spec.rb
54
+ - spec/parse_spec.rb
54
55
  - spec/spec.opts
55
56
  - spec/spec_helper.rb
56
57
  - spec/valid_spec.rb
@@ -86,6 +87,7 @@ specification_version: 3
86
87
  summary: Simple and flexible date parsing.
87
88
  test_files:
88
89
  - spec/compare_spec.rb
89
- - spec/kronos_spec.rb
90
+ - spec/from_hash_spec.rb
91
+ - spec/parse_spec.rb
90
92
  - spec/spec_helper.rb
91
93
  - spec/valid_spec.rb