date-performance 0.4.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/AUTHORS +1 -0
- data/BENCHMARKS +30 -0
- data/COPYING +22 -0
- data/README.txt +134 -0
- data/Rakefile +90 -0
- data/doc/asciidoc.conf +21 -0
- data/doc/changes.html +32 -0
- data/doc/changes.txt +7 -0
- data/doc/images/icons/callouts/1.png +0 -0
- data/doc/images/icons/callouts/10.png +0 -0
- data/doc/images/icons/callouts/11.png +0 -0
- data/doc/images/icons/callouts/12.png +0 -0
- data/doc/images/icons/callouts/13.png +0 -0
- data/doc/images/icons/callouts/14.png +0 -0
- data/doc/images/icons/callouts/15.png +0 -0
- data/doc/images/icons/callouts/2.png +0 -0
- data/doc/images/icons/callouts/3.png +0 -0
- data/doc/images/icons/callouts/4.png +0 -0
- data/doc/images/icons/callouts/5.png +0 -0
- data/doc/images/icons/callouts/6.png +0 -0
- data/doc/images/icons/callouts/7.png +0 -0
- data/doc/images/icons/callouts/8.png +0 -0
- data/doc/images/icons/callouts/9.png +0 -0
- data/doc/images/icons/caution.png +0 -0
- data/doc/images/icons/example.png +0 -0
- data/doc/images/icons/home.png +0 -0
- data/doc/images/icons/important.png +0 -0
- data/doc/images/icons/next.png +0 -0
- data/doc/images/icons/note.png +0 -0
- data/doc/images/icons/prev.png +0 -0
- data/doc/images/icons/tip.png +0 -0
- data/doc/images/icons/up.png +0 -0
- data/doc/images/icons/warning.png +0 -0
- data/doc/license.html +42 -0
- data/doc/license.txt +1 -0
- data/doc/stylesheets/handbookish-manpage.css +36 -0
- data/doc/stylesheets/handbookish-quirks.css +2 -0
- data/doc/stylesheets/handbookish.css +119 -0
- data/ext/date_performance.c +401 -0
- data/ext/extconf.rb +9 -0
- data/lib/date/memoize.rb +86 -0
- data/lib/date/performance.rb +44 -0
- data/misc/asciidoc.rake +121 -0
- data/misc/project.rake +922 -0
- data/test/date_memoize_test.rb +70 -0
- data/test/extension_test.rb +120 -0
- metadata +110 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'date/performance'
|
2
|
+
require 'date/memoize'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class DateMemoizeTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Date::Memoize.install!
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_installed_by_default
|
12
|
+
assert Date::Memoize.installed?, "didn't install when required"
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_civil_memoization
|
16
|
+
expected = Date.new_without_memoization(2002, 03, 22)
|
17
|
+
actual = Date.new(2002, 03, 22)
|
18
|
+
assert_not_same expected, actual
|
19
|
+
assert_equal expected, actual
|
20
|
+
expected, actual = actual, Date.new(2002, 03, 22)
|
21
|
+
assert_same expected, actual
|
22
|
+
assert_equal expected, actual
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_strptime_memoization
|
26
|
+
Date::Memoize.uninstall!
|
27
|
+
expected = Date.strptime('2002-03-22', '%Y-%m-%d')
|
28
|
+
Date::Memoize.install!
|
29
|
+
actual = Date.strptime('2002-03-22', '%Y-%m-%d')
|
30
|
+
assert_equal expected, actual
|
31
|
+
assert_not_same expected, actual
|
32
|
+
expected, actual = actual, Date.strptime('2002-03-22', '%Y-%m-%d')
|
33
|
+
assert_same expected, actual
|
34
|
+
assert_equal expected, actual
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parse_memoization
|
38
|
+
Date::Memoize.uninstall!
|
39
|
+
expected = Date.parse('2002-03-22')
|
40
|
+
Date::Memoize.install!
|
41
|
+
actual = Date.parse('2002-03-22')
|
42
|
+
assert_equal expected, actual
|
43
|
+
assert_not_same expected, actual, "With (#{actual.to_s}) and without (#{expected.to_s}) memoization are the same (#{actual.object_id}, #{expected.object_id})."
|
44
|
+
expected, actual = actual, Date.parse('2002-03-22')
|
45
|
+
assert_same expected, actual
|
46
|
+
assert_equal expected, actual
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_uninstall_is_detected
|
50
|
+
Date::Memoize.uninstall!
|
51
|
+
assert !Date::Memoize.installed?, "didn't uninstall or uninstall not detected properly"
|
52
|
+
methods = Date.methods.select{|m| m.to_s =~ /_without_memoization$/}
|
53
|
+
flunk "Memoization methods not removed: #{methods.inspect}" if methods.any?
|
54
|
+
vars = Date.send(:instance_variables).select{|v| v.to_s =~ /^@__memoized_/}
|
55
|
+
flunk "Memoization instance variables not removed: #{vars.inspect}" if vars.any?
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_uninstall_removes_methods
|
59
|
+
Date::Memoize.uninstall!
|
60
|
+
methods = Date.methods.select{|m| m.to_s =~ /_without_memoization$/}
|
61
|
+
assert_equal 0, methods.length, "Memoization methods not removed: #{methods.inspect}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_uninstall_removes_instance_variables
|
65
|
+
Date::Memoize.uninstall!
|
66
|
+
vars = Date.send(:instance_variables).select{|v| v.to_s =~ /^@__memoized_/}
|
67
|
+
assert_equal 0, vars.length, "Memoization instance variables not removed: #{vars.inspect}"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'date/performance'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class ExtensionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_civil_to_jd
|
7
|
+
assert_equal 2419577, Date.civil_to_jd(1912, 6, 23)
|
8
|
+
assert_equal 2419577, Date.civil_to_jd(1912, 6, 23, Date::GREGORIAN)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_jd_to_civil
|
12
|
+
expected = [ 1912, 6, 23 ]
|
13
|
+
assert_equal expected, Date.jd_to_civil(2419577)
|
14
|
+
assert_equal expected, Date.jd_to_civil(2419577, Date::GREGORIAN)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_jd_to_ajd
|
18
|
+
expected = Rational(4839153, 2)
|
19
|
+
assert_equal expected, Date.jd_to_ajd(2419577)
|
20
|
+
assert_equal expected, Date.jd_to_ajd(2419577, 0)
|
21
|
+
assert_equal expected, Date.jd_to_ajd(2419577, 0, 0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_ajd_to_jd
|
25
|
+
ajd = Rational(4839153, 2)
|
26
|
+
expected = [ 2419577, Rational(1, 2) ]
|
27
|
+
assert_equal(expected, Date.ajd_to_jd(ajd))
|
28
|
+
assert_equal(expected, Date.ajd_to_jd(ajd, 0))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_new
|
32
|
+
expected = Date.new!(Rational(4839153, 2))
|
33
|
+
assert_equal expected, Date.new(1912, 6, 23)
|
34
|
+
assert_equal expected, Date.new(1912, 6, 23, Date::ITALY)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_new_raises_argument_error
|
38
|
+
assert_raise ArgumentError do
|
39
|
+
Date.new(1912, 25, 55)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_civil_cached_on_new
|
44
|
+
date = Date.new(1912, 6, 23)
|
45
|
+
assert_not_nil(expected = date.send(:instance_variable_get, :@__civil__))
|
46
|
+
assert_equal expected, date.civil
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_civil_cached_on_new!
|
50
|
+
date = Date.new!(Rational(4839153, 2))
|
51
|
+
assert !date.send(:instance_variables).include?('@__civil__'), '@__civil__ ivar should not exist'
|
52
|
+
assert_equal([1912, 6, 23], date.civil)
|
53
|
+
assert_equal([1912, 6, 23], date.instance_variable_get(:@__civil__))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_sys_strftime
|
57
|
+
date = Date.new(1912, 6, 23)
|
58
|
+
assert_equal "1912-06-23", date.sys_strftime
|
59
|
+
assert_equal "06/23/1912", date.sys_strftime("%m/%d/%Y")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_sys_strptime
|
63
|
+
assert_equal Date.new(1912, 6, 23), Date.sys_strptime("1912-06-23")
|
64
|
+
assert_equal Date.new(1912, 6, 23), Date.sys_strptime("1912-06-23", "%Y-%m-%d")
|
65
|
+
end
|
66
|
+
|
67
|
+
# This falls back on Ruby's strptime on BSD systems because BSD's strptime doesn't
|
68
|
+
# handle years before 1900.
|
69
|
+
def test_strptime_fallback
|
70
|
+
assert_equal Date.new(1, 1, 1), Date.strptime("01/01/0001", "%m/%d/%Y")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Make sure we're not breaking DateTime
|
74
|
+
def test_datetime
|
75
|
+
datetime = DateTime.parse("1912-06-23T04:20:37Z")
|
76
|
+
assert_equal 1912, datetime.year
|
77
|
+
assert_equal 6, datetime.month
|
78
|
+
assert_equal 23, datetime.day
|
79
|
+
assert_equal 4, datetime.hour
|
80
|
+
assert_equal 20, datetime.min
|
81
|
+
assert_equal 37, datetime.sec
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_new_fails_with_nils
|
85
|
+
assert_raise(TypeError) { Date.new(nil, nil, nil) }
|
86
|
+
assert_raise(TypeError) { Date.new(2007, nil, nil) }
|
87
|
+
assert_raise(TypeError) { Date.new(2007, 9, nil) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_strftime_with_weekday
|
91
|
+
assert_equal "Monday", Date.new(2007, 1, 1).strftime("%A")
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_strftime_with_datetime
|
95
|
+
dt = DateTime.new(2007, 1, 1, 4, 20, 00)
|
96
|
+
assert_equal "2007-01-01T04:20:00+00:00", dt.strftime("%FT%T%:z")
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_constructor_with_negative_days
|
100
|
+
#leap year
|
101
|
+
month_ends = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
102
|
+
(1..12).each do |m|
|
103
|
+
d = Date.new(2008, m, -1)
|
104
|
+
assert_equal d.day, month_ends[m-1]
|
105
|
+
end
|
106
|
+
#normal year
|
107
|
+
month_ends = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
108
|
+
(1..12).each do |m|
|
109
|
+
d = Date.new(2009, m, -1)
|
110
|
+
assert_equal d.day, month_ends[m-1]
|
111
|
+
end
|
112
|
+
#before calendar reform for Italy
|
113
|
+
month_ends = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
114
|
+
(1..12).each do |m|
|
115
|
+
d = Date.new(1581, m, -1)
|
116
|
+
assert_equal d.day, month_ends[m-1]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: date-performance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Tomayko
|
8
|
+
autorequire:
|
9
|
+
bindir:
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Adds some semblance of performance to Ruby's core Date class.
|
17
|
+
email: r@tomayko.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
- COPYING
|
25
|
+
files:
|
26
|
+
- README.txt
|
27
|
+
- COPYING
|
28
|
+
- lib/date/memoize.rb
|
29
|
+
- lib/date/performance.rb
|
30
|
+
- test/date_memoize_test.rb
|
31
|
+
- test/extension_test.rb
|
32
|
+
- doc/asciidoc.conf
|
33
|
+
- doc/changes.html
|
34
|
+
- doc/changes.txt
|
35
|
+
- doc/images
|
36
|
+
- doc/images/icons
|
37
|
+
- doc/images/icons/callouts
|
38
|
+
- doc/images/icons/callouts/1.png
|
39
|
+
- doc/images/icons/callouts/10.png
|
40
|
+
- doc/images/icons/callouts/11.png
|
41
|
+
- doc/images/icons/callouts/12.png
|
42
|
+
- doc/images/icons/callouts/13.png
|
43
|
+
- doc/images/icons/callouts/14.png
|
44
|
+
- doc/images/icons/callouts/15.png
|
45
|
+
- doc/images/icons/callouts/2.png
|
46
|
+
- doc/images/icons/callouts/3.png
|
47
|
+
- doc/images/icons/callouts/4.png
|
48
|
+
- doc/images/icons/callouts/5.png
|
49
|
+
- doc/images/icons/callouts/6.png
|
50
|
+
- doc/images/icons/callouts/7.png
|
51
|
+
- doc/images/icons/callouts/8.png
|
52
|
+
- doc/images/icons/callouts/9.png
|
53
|
+
- doc/images/icons/caution.png
|
54
|
+
- doc/images/icons/example.png
|
55
|
+
- doc/images/icons/home.png
|
56
|
+
- doc/images/icons/important.png
|
57
|
+
- doc/images/icons/next.png
|
58
|
+
- doc/images/icons/note.png
|
59
|
+
- doc/images/icons/prev.png
|
60
|
+
- doc/images/icons/tip.png
|
61
|
+
- doc/images/icons/up.png
|
62
|
+
- doc/images/icons/warning.png
|
63
|
+
- doc/license.html
|
64
|
+
- doc/license.txt
|
65
|
+
- doc/stylesheets
|
66
|
+
- doc/stylesheets/handbookish-manpage.css
|
67
|
+
- doc/stylesheets/handbookish-quirks.css
|
68
|
+
- doc/stylesheets/handbookish.css
|
69
|
+
- Rakefile
|
70
|
+
- misc/asciidoc.rake
|
71
|
+
- misc/project.rake
|
72
|
+
- ext/extconf.rb
|
73
|
+
- ext/date_performance.c
|
74
|
+
- AUTHORS
|
75
|
+
- BENCHMARKS
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://tomayko.com/src/date-performance/
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --title
|
81
|
+
- Date::Performance API Documentation
|
82
|
+
- --extension
|
83
|
+
- rake=rb
|
84
|
+
- --line-numbers
|
85
|
+
- --inline-source
|
86
|
+
- --tab-width=4
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: wink
|
104
|
+
rubygems_version: 1.1.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 2
|
107
|
+
summary: Adds some semblance of performance to Ruby's core Date class.
|
108
|
+
test_files:
|
109
|
+
- test/date_memoize_test.rb
|
110
|
+
- test/extension_test.rb
|