third_base 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/LICENSE +19 -0
  2. data/README +261 -0
  3. data/benchmark/date.rb +18 -0
  4. data/benchmark/datetime.rb +18 -0
  5. data/bin/third_base +4 -0
  6. data/lib/third_base/compat/date/format.rb +3 -0
  7. data/lib/third_base/compat/date.rb +3 -0
  8. data/lib/third_base/compat.rb +405 -0
  9. data/lib/third_base/date.rb +674 -0
  10. data/lib/third_base/datetime.rb +385 -0
  11. data/lib/third_base.rb +2 -0
  12. data/spec/compat/compat_class_methods_spec.rb +208 -0
  13. data/spec/compat/compat_instance_methods_spec.rb +54 -0
  14. data/spec/compat/date_spec.rb +56 -0
  15. data/spec/compat/datetime_spec.rb +77 -0
  16. data/spec/compat_spec_helper.rb +2 -0
  17. data/spec/date/accessor_spec.rb +134 -0
  18. data/spec/date/add_month_spec.rb +28 -0
  19. data/spec/date/add_spec.rb +24 -0
  20. data/spec/date/boat_spec.rb +31 -0
  21. data/spec/date/civil_spec.rb +47 -0
  22. data/spec/date/commercial_spec.rb +34 -0
  23. data/spec/date/constants_spec.rb +18 -0
  24. data/spec/date/downto_spec.rb +17 -0
  25. data/spec/date/eql_spec.rb +9 -0
  26. data/spec/date/hash_spec.rb +13 -0
  27. data/spec/date/julian_spec.rb +13 -0
  28. data/spec/date/leap_spec.rb +19 -0
  29. data/spec/date/minus_month_spec.rb +26 -0
  30. data/spec/date/minus_spec.rb +47 -0
  31. data/spec/date/ordinal_spec.rb +13 -0
  32. data/spec/date/parse_spec.rb +227 -0
  33. data/spec/date/step_spec.rb +55 -0
  34. data/spec/date/strftime_spec.rb +132 -0
  35. data/spec/date/strptime_spec.rb +118 -0
  36. data/spec/date/succ_spec.rb +16 -0
  37. data/spec/date/today_spec.rb +11 -0
  38. data/spec/date/upto_spec.rb +17 -0
  39. data/spec/date_spec_helper.rb +3 -0
  40. data/spec/datetime/accessor_spec.rb +53 -0
  41. data/spec/datetime/add_spec.rb +36 -0
  42. data/spec/datetime/boat_spec.rb +43 -0
  43. data/spec/datetime/constructor_spec.rb +58 -0
  44. data/spec/datetime/eql_spec.rb +11 -0
  45. data/spec/datetime/minus_spec.rb +65 -0
  46. data/spec/datetime/now_spec.rb +14 -0
  47. data/spec/datetime/parse_spec.rb +338 -0
  48. data/spec/datetime/strftime_spec.rb +102 -0
  49. data/spec/datetime/strptime_spec.rb +84 -0
  50. data/spec/datetime_spec_helper.rb +3 -0
  51. data/spec/spec_helper.rb +54 -0
  52. metadata +107 -0
@@ -0,0 +1,84 @@
1
+ require(File.join(File.dirname(__FILE__), '..', 'datetime_spec_helper'))
2
+
3
+ describe "DateTime.strptime" do
4
+ before do
5
+ @t = Time.now
6
+ end
7
+
8
+ it "should be able to parse the date time" do
9
+ DateTime.strptime("2000-04-06T10:11:12").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
10
+ end
11
+
12
+ it "should be able to parse the hour in a 24 hour clock with leading zero" do
13
+ DateTime.strptime("10", '%H').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
14
+ DateTime.strptime("09", '%H').should == DateTime.civil(@t.year, @t.mon, @t.day, 9, 0, 0)
15
+ DateTime.strptime("2000 16", '%Y %H').should == DateTime.civil(2000, 1, 1, 16, 0, 0)
16
+ end
17
+
18
+ it "should be able to parse the hour in a 12 hour clock with leading zero with meridian indicator" do
19
+ DateTime.strptime("10 AM", '%I %p').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
20
+ DateTime.strptime("03 04 04 PM", '%m %d %I %p').should == DateTime.civil(@t.year, 3, 4, 16, 0, 0)
21
+ end
22
+
23
+ it "should be able to parse the hour in a 24 hour clock with leading space" do
24
+ DateTime.strptime("10", '%k').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
25
+ DateTime.strptime(" 9", '%k').should == DateTime.civil(@t.year, @t.mon, @t.day, 9, 0, 0)
26
+ DateTime.strptime("10 16", '%d %k').should == DateTime.civil(@t.year, @t.mon, 10, 16, 0, 0)
27
+ end
28
+
29
+ it "should be able to parse the hour in a 12 hour clock with leading space with meridian indicator" do
30
+ DateTime.strptime("10 am", '%l %P').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
31
+ DateTime.strptime(" 4 pm", '%l %P').should == DateTime.civil(@t.year, @t.mon, @t.day, 16, 0, 0)
32
+ end
33
+
34
+ it "should be able to parse the minute with leading zero" do
35
+ DateTime.strptime("10", '%M').should == DateTime.civil(@t.year, @t.mon, @t.day, @t.hour, 10, 0)
36
+ DateTime.strptime("09", '%M').should == DateTime.civil(@t.year, @t.mon, @t.day, @t.hour, 9, 0)
37
+ end
38
+
39
+ it "should be able to parse the second with leading zero" do
40
+ DateTime.strptime("10", '%S').should == DateTime.civil(@t.year, @t.mon, @t.day, @t.hour, @t.min, 10)
41
+ DateTime.strptime("10 09", '%H %S').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 9)
42
+ end
43
+
44
+ it "should be able to parse the number of seconds since the unix epoch" do
45
+ DateTime.strptime("1226527410", '%s').should == DateTime.civil(2008, 11, 12, 22, 3, 30, 0)
46
+ DateTime.strptime("1226527411", '%s').should == DateTime.civil(2008, 11, 12, 22, 3, 31, 0)
47
+ end
48
+
49
+ it "should be able to parse the time zone offset as a string of hours and minutes" do
50
+ DateTime.strptime("2000 +0000", '%Y %z').offset.should == 0
51
+ DateTime.strptime("2000 Z", '%Y %z').offset.should == 0
52
+ DateTime.strptime("2000 -1200", '%Y %z').offset.should == -43200
53
+ DateTime.strptime("2000 +1200", '%Y %z').offset.should == 43200
54
+ DateTime.strptime("2000 -01:00", '%Y %z').offset.should == -3600
55
+ DateTime.strptime("2000 +01:00", '%Y %z').offset.should == 3600
56
+ end
57
+
58
+ ############################
59
+ # Specs that combine stuff #
60
+ ############################
61
+
62
+ it "should be able to parse the common date" do
63
+ DateTime.strptime("Thu Apr 6 10:11:12 2000", "%c").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
64
+ end
65
+
66
+ it "should be able to parse the hour and minute" do
67
+ DateTime.strptime("10:11", "%R").should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 11, 0)
68
+ end
69
+
70
+ it "should be able to parse the hour, minute, second, and am/pm flag" do
71
+ DateTime.strptime("10:11:12 AM", "%r").should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 11, 12)
72
+ DateTime.strptime("01:11:12 PM", "%r").should == DateTime.civil(@t.year, @t.mon, @t.day, 13, 11, 12)
73
+ end
74
+
75
+ it "should be able to parse the hour, minute, and second" do
76
+ DateTime.strptime("10:11:12", "%T").should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 11, 12)
77
+ DateTime.strptime("01:11:12", "%X").should == DateTime.civil(@t.year, @t.mon, @t.day, 1, 11, 12)
78
+ end
79
+
80
+ it "should be able to parse the common date and timezone" do
81
+ DateTime.strptime("Thu Apr 6 10:11:12 +0000 2000", "%+").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
82
+ DateTime.strptime("Thu Apr 6 10:11:12 +1200 2000", "%+").should == DateTime.civil(2000, 4, 6, 10, 11, 12, 0, 43200)
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ require 'third_base/datetime'
2
+ include ThirdBase
3
+ require(File.join(File.dirname(__FILE__), 'spec_helper'))
@@ -0,0 +1,54 @@
1
+ unless ENV['MSPEC_RUNNER']
2
+ begin
3
+ require "pp"
4
+ require 'mspec/version'
5
+ require 'mspec/helpers'
6
+ require 'mspec/guards'
7
+ require 'mspec/runner/shared'
8
+ require 'mspec/matchers/be_ancestor_of'
9
+ require 'mspec/matchers/output'
10
+ require 'mspec/matchers/output_to_fd'
11
+ require 'mspec/matchers/complain'
12
+ require 'mspec/matchers/equal_element'
13
+ require 'mspec/matchers/equal_utf16'
14
+ require 'mspec/matchers/match_yaml'
15
+
16
+ # Code to setup HOME directory correctly on Windows
17
+ # This duplicates Ruby 1.9 semantics for defining HOME
18
+ platform_is :windows do
19
+ if ENV['HOME']
20
+ ENV['HOME'] = ENV['HOME'].tr '\\', '/'
21
+ elsif ENV['HOMEDIR'] && ENV['HOMEDRIVE']
22
+ ENV['HOME'] = File.join(ENV['HOMEDRIVE'], ENV['HOMEDIR'])
23
+ elsif ENV['HOMEDIR']
24
+ ENV['HOME'] = ENV['HOMEDIR']
25
+ elsif ENV['HOMEDRIVE']
26
+ ENV['HOME'] = ENV['HOMEDRIVE']
27
+ elsif ENV['USERPROFILE']
28
+ ENV['HOME'] = ENV['USERPROFILE']
29
+ else
30
+ puts "No suitable HOME environment found. This means that all of HOME, HOMEDIR, HOMEDRIVE, and USERPROFILE are not set"
31
+ exit 1
32
+ end
33
+ end
34
+
35
+ TOLERANCE = 0.00003 unless Object.const_defined?(:TOLERANCE)
36
+ rescue LoadError
37
+ puts "Please install the MSpec gem to run the specs."
38
+ exit 1
39
+ end
40
+ end
41
+
42
+ v = MSpec::VERSION.split('.').collect { |d| "1%02d" % d.to_i }.join.to_i
43
+ unless v >= 101105100
44
+ puts "Please install MSpec version >= 1.5.0 to run the specs"
45
+ exit 1
46
+ end
47
+
48
+ $VERBOSE = nil unless ENV['OUTPUT_WARNINGS']
49
+
50
+ def has_tty?
51
+ if STDOUT.tty? then
52
+ yield
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: third_base
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-21 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: code@jeremyevans.net
18
+ executables:
19
+ - third_base
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - README
27
+ - bin/third_base
28
+ - lib/third_base.rb
29
+ - lib/third_base/compat.rb
30
+ - lib/third_base/date.rb
31
+ - lib/third_base/datetime.rb
32
+ - lib/third_base/compat/date/format.rb
33
+ - lib/third_base/compat/date.rb
34
+ - benchmark/datetime.rb
35
+ - benchmark/date.rb
36
+ - spec/spec_helper.rb
37
+ - spec/date_spec_helper.rb
38
+ - spec/compat_spec_helper.rb
39
+ - spec/datetime_spec_helper.rb
40
+ - spec/date/add_month_spec.rb
41
+ - spec/date/add_spec.rb
42
+ - spec/date/boat_spec.rb
43
+ - spec/date/civil_spec.rb
44
+ - spec/date/commercial_spec.rb
45
+ - spec/date/constants_spec.rb
46
+ - spec/date/succ_spec.rb
47
+ - spec/date/downto_spec.rb
48
+ - spec/date/eql_spec.rb
49
+ - spec/date/hash_spec.rb
50
+ - spec/date/julian_spec.rb
51
+ - spec/date/minus_month_spec.rb
52
+ - spec/date/minus_spec.rb
53
+ - spec/date/leap_spec.rb
54
+ - spec/date/ordinal_spec.rb
55
+ - spec/date/parse_spec.rb
56
+ - spec/date/today_spec.rb
57
+ - spec/date/step_spec.rb
58
+ - spec/date/upto_spec.rb
59
+ - spec/date/strftime_spec.rb
60
+ - spec/date/strptime_spec.rb
61
+ - spec/date/accessor_spec.rb
62
+ - spec/datetime/add_spec.rb
63
+ - spec/datetime/minus_spec.rb
64
+ - spec/datetime/eql_spec.rb
65
+ - spec/datetime/boat_spec.rb
66
+ - spec/datetime/parse_spec.rb
67
+ - spec/datetime/now_spec.rb
68
+ - spec/datetime/constructor_spec.rb
69
+ - spec/datetime/accessor_spec.rb
70
+ - spec/datetime/strftime_spec.rb
71
+ - spec/datetime/strptime_spec.rb
72
+ - spec/compat/date_spec.rb
73
+ - spec/compat/compat_class_methods_spec.rb
74
+ - spec/compat/compat_instance_methods_spec.rb
75
+ - spec/compat/datetime_spec.rb
76
+ has_rdoc: true
77
+ homepage: http://third-base.rubyforge.org
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --inline-source
81
+ - --line-numbers
82
+ - README
83
+ - LICENSE
84
+ - lib
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ requirements: []
100
+
101
+ rubyforge_project: third-base
102
+ rubygems_version: 1.3.0
103
+ signing_key:
104
+ specification_version: 2
105
+ summary: A Fast and Easy Date/DateTime Class
106
+ test_files: []
107
+