kronos 0.1.5 → 0.1.6

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kronos}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
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"]
12
- s.date = %q{2010-03-09}
12
+ s.date = %q{2010-03-17}
13
13
  s.description = %q{Kronos provides flexible date parsing. Currently just a thin layer on top of ParseDate.}
14
14
  s.email = %q{djames@sunlightfoundation.com}
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "spec/parse_spec.rb",
31
31
  "spec/spec.opts",
32
32
  "spec/spec_helper.rb",
33
+ "spec/to_s_spec.rb",
33
34
  "spec/valid_spec.rb"
34
35
  ]
35
36
  s.homepage = %q{http://github.com/djsun/kronos}
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
42
43
  "spec/from_hash_spec.rb",
43
44
  "spec/parse_spec.rb",
44
45
  "spec/spec_helper.rb",
46
+ "spec/to_s_spec.rb",
45
47
  "spec/valid_spec.rb"
46
48
  ]
47
49
 
@@ -29,14 +29,25 @@ class Kronos
29
29
  self
30
30
  end
31
31
 
32
+ def to_s
33
+ s = ""
34
+ raise "Invalid" unless valid?
35
+ s << "%04i" % year if year
36
+ s << "/%02i" % month if month
37
+ s << "/%02i" % day if day
38
+ s
39
+ end
40
+
32
41
  def valid?
33
- if day
34
- return false unless month && year
35
- end
36
- if month
37
- return false unless year
42
+ if day && (!month || !year)
43
+ false
44
+ elsif month && !year
45
+ false
46
+ elsif !year
47
+ false
48
+ else
49
+ true
38
50
  end
39
- true
40
51
  end
41
52
 
42
53
  def <(other)
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  require 'kronos'
4
5
  require 'spec'
5
6
  require 'spec/autorun'
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "to_s" do
4
+
5
+ def new_kronos(year=nil, month=nil, day=nil)
6
+ k = Kronos.new
7
+ k.year = year if year
8
+ k.month = month if month
9
+ k.day = day if day
10
+ k
11
+ end
12
+
13
+ describe "2005" do
14
+ it "should be '2005'" do
15
+ k = new_kronos(2005)
16
+ k.to_s.should == '2005'
17
+ end
18
+ end
19
+
20
+ describe "Feb. 2005" do
21
+ it "should be '2005/02'" do
22
+ k = new_kronos(2005, 2)
23
+ k.to_s.should == '2005/02'
24
+ end
25
+ end
26
+
27
+ describe "Feb. 9, 2005" do
28
+ it "should be '2005/02/09'" do
29
+ k = new_kronos(2005, 2, 9)
30
+ k.to_s.should == '2005/02/09'
31
+ end
32
+ end
33
+ end
@@ -25,5 +25,9 @@ describe "Kronos Comparisons" do
25
25
  it "day and year is invalid" do
26
26
  new_kronos(2005, nil, 22).valid?.should == false
27
27
  end
28
+
29
+ it "nothing is invalid" do
30
+ new_kronos(nil, nil, nil).valid?.should == false
31
+ end
28
32
 
29
33
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - David James
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-09 00:00:00 -05:00
17
+ date: 2010-03-17 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -54,6 +54,7 @@ files:
54
54
  - spec/parse_spec.rb
55
55
  - spec/spec.opts
56
56
  - spec/spec_helper.rb
57
+ - spec/to_s_spec.rb
57
58
  - spec/valid_spec.rb
58
59
  has_rdoc: true
59
60
  homepage: http://github.com/djsun/kronos
@@ -90,4 +91,5 @@ test_files:
90
91
  - spec/from_hash_spec.rb
91
92
  - spec/parse_spec.rb
92
93
  - spec/spec_helper.rb
94
+ - spec/to_s_spec.rb
93
95
  - spec/valid_spec.rb