datet 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Datet" do
4
+ it "should have the same 'to_i' as normal time" do
5
+ time_i = Time.now.to_i
6
+ datet_i = Datet.new.to_i
7
+
8
+ raise "Expected to be the same but they werent: #{time_i} vs #{datet_i}" if time_i != datet_i
9
+ end
10
+
11
+ it "should be able to make ago-strings" do
12
+ time = Time.at(Time.now.to_i - 5)
13
+ datet = Datet.in(time)
14
+ res = datet.ago_str
15
+ raise "Expected '5 seconds ago' but got: '#{res}'." if res != "5 seconds ago"
16
+
17
+
18
+ time = Time.at(Time.now.to_i - 1800)
19
+ datet = Datet.in(time)
20
+ res = datet.ago_str
21
+ raise "Expected '30 minutes ago' but got: '#{res}'." if res != "30 minutes ago"
22
+
23
+
24
+ time = Time.at(Time.now.to_i - 60)
25
+ datet = Datet.in(time)
26
+ res = datet.ago_str
27
+ raise "Expected '1 minute ago' but got: '#{res}'." if res != "1 minute ago"
28
+
29
+
30
+ time = Time.at(Time.now.to_i - 48 * 3600)
31
+ datet = Datet.in(time)
32
+ res = datet.ago_str
33
+ raise "Expected '2 days ago' but got: '#{res}'." if res != "2 days ago"
34
+ end
35
+
36
+ #From "knjrbfw_spec.rb".
37
+ it "should be able to parse various date formats." do
38
+ date = Datet.in("2011-07-09 00:00:00 UTC")
39
+ date = Datet.in("1985-06-17 01:00:00")
40
+ date = Datet.in("1985-06-17")
41
+ date = Datet.in("17/06 1985")
42
+
43
+ raise "Couldnt register type 1 nullstamp." if !Datet.is_nullstamp?("0000-00-00")
44
+ raise "Couldnt register type 2 nullstamp." if !Datet.is_nullstamp?("0000-00-00 00:00:00")
45
+ raise "Registered nullstamp on valid date." if Datet.is_nullstamp?("1985-06-17")
46
+ raise "Registered nullstamp on valid date." if Datet.is_nullstamp?("1985-06-17 10:30:00")
47
+
48
+ date = Datet.in("2011-07-09 13:05:04 +0200")
49
+ ltime = date.localtime_str
50
+
51
+ #if RUBY_VERSION.slice(0, 3) == "1.9"
52
+ # if ltime != date.time.localtime
53
+ # raise "Calculated localtime (#{ltime}) was not the same as the real Time-localtime (#{date.time.localtime})."
54
+ # end
55
+ #end
56
+
57
+ if ltime != "2011-07-09 13:05:04 +0200"
58
+ raise "Datet didnt return expected result: '#{ltime}'."
59
+ end
60
+ end
61
+
62
+ it "should be able to compare dates" do
63
+ date1 = Datet.in("17/06 1985")
64
+ date2 = Datet.in("18/06 1985")
65
+ date3 = Datet.in("17/06 1985")
66
+
67
+ raise "Date1 was wrongly higher than date2." if date1 > date2
68
+
69
+ if date2 > date1
70
+ #do nothing.
71
+ else
72
+ raise "Date2 was wrongly not higher than date1."
73
+ end
74
+
75
+ raise "Date1 was wrongly not the same as date3." if date1 != date3
76
+ raise "Date1 was the same as date2?" if date1 == date2
77
+ end
78
+
79
+ it "various methods should just work" do
80
+ date = Datet.new(1985, 6, 17)
81
+ raise "Invalid days in month: #{date.days_in_month}" if date.days_in_month != 30
82
+ end
83
+
84
+ it "should be able to handle invalid timestamps" do
85
+ datet = Datet.new(2012, 3, 40)
86
+ raise "Expected dbstr to be '2012-04-09' but it wasnt: '#{datet.dbstr(:time => false)}'." if datet.dbstr(:time => false) != "2012-04-09"
87
+
88
+ datet = Datet.new(2012, 14)
89
+ raise "Expected dbstr to be '2013-02-01' but it wasnt: '#{datet.dbstr(:time => false)}'." if datet.dbstr(:time => false) != "2013-02-01"
90
+
91
+ datet = Datet.new(1985, 6, 17, 28)
92
+ raise "Expected dbstr to be '1985-06-18 04:00:00' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 04:00:00"
93
+
94
+ datet = Datet.new(1985, 6, 17, 28, 68)
95
+ raise "Expected dbstr to be '1985-06-18 05:08:00' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 05:08:00"
96
+
97
+ datet = Datet.new(1985, 6, 17, 28, 68, 68)
98
+ raise "Expected dbstr to be '1985-06-18 05:09:08' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 05:09:08"
99
+
100
+ datet = Datet.new(1985, 6, 17, 28, 68, 68, 68)
101
+ raise "Expected dbstr to be '1985-06-18 05:09:09' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 05:09:09"
102
+ end
103
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'datet'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datet
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Kasper Johansen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-07-12 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.8.0
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "3.12"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.8.4
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rcov
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description: A framework for handeling date- and time-related stuff in Ruby.
72
+ email: k@spernj.org
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ files:
81
+ - .document
82
+ - .rspec
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ - Rakefile
88
+ - VERSION
89
+ - lib/datet.rb
90
+ - spec/datet_spec.rb
91
+ - spec/spec_helper.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/kaspernj/datet
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 2695017267078872396
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.6.2
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: A framework for handeling date- and time-related stuff in Ruby.
123
+ test_files: []
124
+