hanke-henry 1.0

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.
@@ -0,0 +1,11 @@
1
+ require 'autotest/bundler'
2
+
3
+ Autotest.add_hook(:initialize) {|at|
4
+ at.add_exception %r{^\.git} # ignore Version Control System
5
+ at.add_exception %r{^./tmp}
6
+ at.clear_mappings # take out the default (test/test*rb)
7
+ at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
8
+ Dir['spec/**/*_spec.rb']
9
+ }
10
+ nil
11
+ }
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ html/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.3"
5
+ - ruby-head
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ matrix:
11
+ allow_failures:
12
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hanke-henry-calendar.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Hirotsugu Asari
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ [![Build Status](https://secure.travis-ci.org/BanzaiMan/hanke-henry.png)](http://travis-ci.org/BanzaiMan/hanke-henry)
2
+
3
+ # Hanke-Henry Calendar
4
+
5
+ `hanke-henry` is a gem that deals with the proposed
6
+ [Hanke-Henry Calendar][1].
7
+ This calendar has the following characteristics over
8
+ the presently adopted Gregorian Calendar:
9
+
10
+ 1. Calendar remains identical for the most part.
11
+ 1. No time zones.
12
+ 1. No Daylight Savings Time.
13
+
14
+ The typical year in the current Gregorian calendar has 365 days, which is 52
15
+ weeks and 1 day.
16
+ The leap years occur every 4 years (with some exceptions).
17
+ The basic idea of the Hanke-Henry calendar is to gather the overflow days of
18
+ the typical year and the leap days and into chunks of 7, which will form a
19
+ mini-month (called _Xtr_) at the end of the year every so often.
20
+
21
+ The H-H calendar also proposes to abolish time zones and Daylight Savings Time,
22
+ essentially standardizing on the current UTC.
23
+
24
+ `hanke-henry` extends the Date and DateTime classes to deal with this
25
+ calendar.
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ gem 'hanke-henry'
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install hanke-henry
40
+
41
+ ## Usage
42
+
43
+ require 'hanke-henry' # requires 'date' as well
44
+ d1 = Date.hh(2012, 1, 1) # => #<Date: 2012-01-01 ((2455928j,0s,0n),+0s,2299161j)>
45
+ d1.hh # => "2012-1-1"
46
+ d1.xtr? # => false
47
+ d2 = Date.hh(2015, :x, 5) # => #<Date: 2015-12-31 ((2457388j,43200s,0n),+0s,2299161j)>
48
+ d2.xtr? # => true
49
+
50
+ ## Contributing
51
+ By contributing, you certify that you have full legal rights to your
52
+ contribution and agree that it can be redistributed under the license
53
+ described in `LICENSE.txt`.
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
60
+
61
+ ### Development
62
+ git clone git://github.com/BanzaiMan/hanke-henry.git
63
+ cd hanke-henry
64
+ bundle install
65
+ bundle exec autotest
66
+
67
+ [1]: http://henry.pha.jhu.edu/calendar.html
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'rdoc/task'
4
+
5
+ task :default => [:spec]
6
+
7
+ desc 'Run specs'
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.rspec_opts = ['--color']
10
+ end
11
+
12
+ desc 'Generate documentation with RDoc'
13
+ RDoc::Task.new do |rdoc|
14
+ rdoc.rdoc_files.include("lib/**/hanke*.rb")
15
+ end
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hanke-henry/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "hanke-henry"
8
+ gem.version = HankeHenry::VERSION
9
+ gem.authors = ["Hirotsugu Asari"]
10
+ gem.email = ["asari.ruby@gmail.com"]
11
+ gem.description = %q{Date and DateTime extensions for the Hanke-Henry Calendar}
12
+ gem.summary = gem.description
13
+ gem.homepage = "http://github.com/BanzaiMan/hanke-henry"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec', '>= 2.0'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rdoc'
23
+ gem.add_development_dependency 'autotest'
24
+ end
@@ -0,0 +1,4 @@
1
+ require 'hanke-henry/version'
2
+ require 'hanke-henry/date'
3
+ require 'hanke-henry/date_time'
4
+ require 'hanke-henry/hanke_henry_date'
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), 'hanke_henry_date')
2
+
3
+ class Date
4
+ extend HankeHenryDate::Module
5
+ include HankeHenryDate
6
+
7
+ private
8
+ def self._hh_arg_limit
9
+ 4
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), 'hanke_henry_date')
2
+
3
+ class DateTime
4
+ extend HankeHenryDate::Module
5
+ include HankeHenryDate
6
+
7
+ private
8
+ def self._hh_arg_limit
9
+ 8
10
+ end
11
+ end
@@ -0,0 +1,200 @@
1
+ require 'date'
2
+
3
+ ##
4
+ # This module extends Date and DateTime classes to represent the Hanke-Henry
5
+ # calendar.
6
+ #
7
+ module HankeHenryDate
8
+ XTR_YEARS = [
9
+ 4, 9, 15, 20, 26, 32, 37, 43, 48, 54, 60, 65, 71, 76,
10
+ 82, 88, 93, 99, 105, 111, 116, 122, 128, 133, 139, 144, 150, 156,
11
+ 161, 167, 172, 178, 184, 189, 195, 201, 207, 212, 218, 224, 229, 235,
12
+ 240, 246, 252, 257, 263, 268, 274, 280, 285, 291, 296, 303, 308, 314,
13
+ 320, 325, 331, 336, 342, 348, 353, 359, 364, 370, 376, 381, 387, 392,
14
+ 398
15
+ ]
16
+
17
+ # A 400-year cycle runs from year 1 through 400, 401 through 800, and so on.
18
+ # N-th element in DAYS_SINCE_LAST_CYCLE is the number of days since the
19
+ # conclusion of the previous cycle at the beginning of the year N (mod 400).
20
+ # So, for day D, DAYS_SINCE_LAST_CYCLE.select {|d| d < D}.length indicates
21
+ # the year mod 400.
22
+ DAYS_SINCE_LAST_CYCLE = [
23
+ 0, 364, 728, 1092, 1463, 1827, 2191, 2555, 2919, 3290, 3654, 4018, 4382, 4746,
24
+ 5110, 5481, 5845, 6209, 6573, 6937, 7308, 7672, 8036, 8400, 8764, 9128, 9499,
25
+ 9863, 10227, 10591, 10955, 11319, 11690, 12054, 12418, 12782, 13146, 13517,
26
+ 13881, 14245, 14609, 14973, 15337, 15708, 16072, 16436, 16800, 17164, 17535,
27
+ 17899, 18263, 18627, 18991, 19355, 19726, 20090, 20454, 20818, 21182, 21546,
28
+ 21917, 22281, 22645, 23009, 23373, 23744, 24108, 24472, 24836, 25200, 25564,
29
+ 25935, 26299, 26663, 27027, 27391, 27762, 28126, 28490, 28854, 29218, 29582,
30
+ 29953, 30317, 30681, 31045, 31409, 31773, 32144, 32508, 32872, 33236, 33600,
31
+ 33971, 34335, 34699, 35063, 35427, 35791, 36162, 36526, 36890, 37254, 37618,
32
+ 37982, 38353, 38717, 39081, 39445, 39809, 40173, 40544, 40908, 41272, 41636,
33
+ 42000, 42371, 42735, 43099, 43463, 43827, 44191, 44562, 44926, 45290, 45654,
34
+ 46018, 46382, 46753, 47117, 47481, 47845, 48209, 48580, 48944, 49308, 49672,
35
+ 50036, 50400, 50771, 51135, 51499, 51863, 52227, 52598, 52962, 53326, 53690,
36
+ 54054, 54418, 54789, 55153, 55517, 55881, 56245, 56609, 56980, 57344, 57708,
37
+ 58072, 58436, 58807, 59171, 59535, 59899, 60263, 60627, 60998, 61362, 61726,
38
+ 62090, 62454, 62825, 63189, 63553, 63917, 64281, 64645, 65016, 65380, 65744,
39
+ 66108, 66472, 66836, 67207, 67571, 67935, 68299, 68663, 69034, 69398, 69762,
40
+ 70126, 70490, 70854, 71225, 71589, 71953, 72317, 72681, 73045, 73416, 73780,
41
+ 74144, 74508, 74872, 75236, 75607, 75971, 76335, 76699, 77063, 77434, 77798,
42
+ 78162, 78526, 78890, 79254, 79625, 79989, 80353, 80717, 81081, 81445, 81816,
43
+ 82180, 82544, 82908, 83272, 83643, 84007, 84371, 84735, 85099, 85463, 85834,
44
+ 86198, 86562, 86926, 87290, 87661, 88025, 88389, 88753, 89117, 89481, 89852,
45
+ 90216, 90580, 90944, 91308, 91672, 92043, 92407, 92771, 93135, 93499, 93870,
46
+ 94234, 94598, 94962, 95326, 95690, 96061, 96425, 96789, 97153, 97517, 97888,
47
+ 98252, 98616, 98980, 99344, 99708, 100079, 100443, 100807, 101171, 101535,
48
+ 101899, 102270, 102634, 102998, 103362, 103726, 104097, 104461, 104825, 105189,
49
+ 105553, 105917, 106288, 106652, 107016, 107380, 107744, 108115, 108479, 108843,
50
+ 109207, 109571, 109935, 110299, 110670, 111034, 111398, 111762, 112126, 112497,
51
+ 112861, 113225, 113589, 113953, 114317, 114688, 115052, 115416, 115780, 116144,
52
+ 116508, 116879, 117243, 117607, 117971, 118335, 118706, 119070, 119434, 119798,
53
+ 120162, 120526, 120897, 121261, 121625, 121989, 122353, 122724, 123088, 123452,
54
+ 123816, 124180, 124544, 124915, 125279, 125643, 126007, 126371, 126735, 127106,
55
+ 127470, 127834, 128198, 128562, 128933, 129297, 129661, 130025, 130389, 130753,
56
+ 131124, 131488, 131852, 132216, 132580, 132951, 133315, 133679, 134043, 134407,
57
+ 134771, 135142, 135506, 135870, 136234, 136598, 136962, 137333, 137697, 138061,
58
+ 138425, 138789, 139160, 139524, 139888, 140252, 140616, 140980, 141351, 141715,
59
+ 142079, 142443, 142807, 143178, 143542, 143906, 144270, 144634, 144998, 145369,
60
+ 145733
61
+ ]
62
+
63
+ DAYS_IN_COMPLETE_CYCLE = 400 * 364 + XTR_YEARS.length * 7
64
+
65
+ DAYS_SINCE_NEW_YEAR = [0, 30, 60, 91, 121, 151, 182, 212, 242, 273, 303, 333, 364]
66
+
67
+ HH_OFFSET = 1721423.5 # Julian date for Jan 1, 1 (on H-H calendar)
68
+
69
+ ##
70
+ # This module is used for extending Date and DateTime classes to include
71
+ # class method +.hh+ that takes arguments representing Hanke-Henry calendar
72
+ # dates and returns Date and DateTime objects.
73
+ #
74
+ module Module
75
+ ##
76
+ #
77
+ def hh(*args)
78
+ hh_year, hh_month, hh_day, hour, minute, second = _validate(*args)
79
+ julian = _to_julian_date(hh_year, hh_month, hh_day)
80
+ if self.ancestors.include? DateTime
81
+ d = DateTime.jd julian
82
+ DateTime.new(d.year, d.month, d.day, hour, minute, second)
83
+ else
84
+ Date.jd julian
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ # Xtrs have we seen in years since year 400N
91
+ def _xtrs(year)
92
+ XTR_YEARS.select { |y| y < year % 400 }.length
93
+ end
94
+
95
+ def _validate(*args)
96
+ if args.length > (_hh_arg_limit || 4)
97
+ raise ArgumentError, "Wrong number of arguments (#{args.length} for 0..#{_hh_arg_limit})"
98
+ end
99
+
100
+ year, month, day, hour, minute, second = args
101
+
102
+ # defaults
103
+ year ||= -4712
104
+ month ||= 1
105
+ day ||= 1
106
+ hour ||= 0
107
+ minute ||= 0
108
+ second ||= 0
109
+ months_in_year = (XTR_YEARS.include? year % 400)? 13 : 12
110
+
111
+ if (month = month.to_s) == 'x'
112
+ month = 13
113
+ else
114
+ month = month.to_i
115
+ end
116
+
117
+ if month == 13
118
+ unless XTR_YEARS.include? year % 400
119
+ raise ArgumentError, "Hanke-Henry year #{year} does not have Xtr"
120
+ end
121
+ days_in_month = 7
122
+ elsif month % 3 == 0 # month is 3, 6, 9 or 12
123
+ days_in_month = 31
124
+ else
125
+ days_in_month = 30
126
+ end
127
+
128
+ if day > days_in_month || day < -days_in_month || month > months_in_year ||
129
+ month < -months_in_year || month == 0 || day == 0
130
+ raise ArgumentError, 'invalid date'
131
+ else
132
+ # handle cases where month or day is negative
133
+ month %= (months_in_year + 1)
134
+ day %= (days_in_month + 1)
135
+ end
136
+
137
+ [ year, month, day, hour, minute, second ]
138
+ end
139
+
140
+ ## translate args given in Hanke-Henry calendar into Julian date,
141
+ ## so that it can be passed to Date.jd
142
+ def _to_julian_date(year, month, day)
143
+ ## Hanke-Henry and Gregorian days will sync up every 400 years
144
+ complete_cycles = (year-1) / 400 # how many 400-year cycles since year 0
145
+ years_since_last_complete_cycle = (year-1) % 400
146
+ xtrs = _xtrs(year) # Xtrs before this year since the laste year 400N
147
+
148
+ days_since_epoch = complete_cycles * DAYS_IN_COMPLETE_CYCLE +
149
+ years_since_last_complete_cycle * 364 +
150
+ xtrs * 7 +
151
+ DAYS_SINCE_NEW_YEAR[month - 1] +
152
+ day + 1
153
+
154
+ days_since_epoch + HH_OFFSET
155
+ end
156
+
157
+ end
158
+
159
+ ##
160
+ # +#xtr?+ returns true if the +DateTime+ object falls in a Hanke-Henry year
161
+ # which contains the Xtr week.
162
+ #
163
+ def xtr?
164
+ XTR_YEARS.include?((_from_julian_date(self.jd)[0]) % 400)
165
+ end
166
+
167
+ ##
168
+ # +hh+ returns a string representation of the Hanke-Henry date.
169
+ #
170
+ def hh
171
+ "%d-%0s-%0d" % _from_julian_date(self.jd)
172
+ end
173
+
174
+ private
175
+
176
+ # given Julian date jd, compute H-H date
177
+ def _from_julian_date(jd)
178
+ year = (jd - HH_OFFSET).floor / DAYS_IN_COMPLETE_CYCLE * 400
179
+ day = (jd - HH_OFFSET).floor % DAYS_IN_COMPLETE_CYCLE # remainining days
180
+
181
+ remainder_years = DAYS_SINCE_LAST_CYCLE.select { |d| d < day }.length
182
+ year += remainder_years
183
+
184
+ day -= DAYS_SINCE_LAST_CYCLE[year % 400 - 1]
185
+
186
+ days_in_month = [0, 30, 60, 91, 121, 151, 182, 212, 242, 273, 303, 333]
187
+ if XTR_YEARS.include? remainder_years % 400
188
+ days_in_month << 364
189
+ end
190
+
191
+ month = days_in_month.select { |d| d < day }.length
192
+ day -= days_in_month[month - 1]
193
+
194
+ if month == 13
195
+ month = :x
196
+ end
197
+
198
+ [year, month, day]
199
+ end
200
+ end
@@ -0,0 +1,3 @@
1
+ module HankeHenry
2
+ VERSION = "1.0"
3
+ end
@@ -0,0 +1,171 @@
1
+ require 'rspec'
2
+ require 'hanke-henry'
3
+
4
+ class HHDate < Date
5
+ extend HankeHenryDate::Module
6
+ include HankeHenryDate
7
+
8
+ private
9
+ def self._hh_arg_limit
10
+ 4
11
+ end
12
+ end
13
+
14
+ describe 'HHDate' do
15
+ describe '.hh' do
16
+ context 'valid parameters are passed' do
17
+ it 'does not raise error' do
18
+ HHDate.hh(2012, 1, 1).should be_a Date
19
+ HHDate.hh(2015, -13, 1).should be_a Date
20
+ HHDate.hh(2012, 1, 1).should_not be_a DateTime
21
+ end
22
+ end
23
+
24
+ context 'when passed 2012, 1, 1' do
25
+ before :each do
26
+ @date = HHDate.hh(2012, 1, 1)
27
+ end
28
+
29
+ describe '#jd' do
30
+ let(:subject) { @date.jd }
31
+ it 'returns the same value as Date.new(2012,1,1).jd' do
32
+ subject.should == Date.new(2012,1,1).jd
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'when passed 2012, 1, -1' do
38
+ before :each do
39
+ @date = HHDate.hh(2012, 1, -1)
40
+ end
41
+
42
+ describe '#jd' do
43
+ let(:subject) { @date.jd }
44
+ it 'returns the same value as HHDate.new(2012,1,30)' do
45
+ subject.should == HHDate.new(2012,1,30).jd
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when more than 4 arguments are passed' do
51
+ it 'raises ArgumentError' do
52
+ lambda { HHDate.hh(2012, 1, 2, 3, 4) }.should raise_error ArgumentError
53
+ end
54
+ end
55
+
56
+ context 'when argument limit is altered' do
57
+ it 'respects the new limit' do
58
+ class HHDate
59
+ private
60
+ def self._hh_arg_limit
61
+ 8
62
+ end
63
+ end
64
+ lambda { HHDate.hh(2012, 1, 2, 3, 4, 5, 6, 7, 8) }.should raise_error ArgumentError
65
+
66
+ class HHDate2 < HHDate
67
+ private
68
+ def self._hh_arg_limit
69
+ 5
70
+ end
71
+ end
72
+ lambda { HHDate2.hh(2012, 1, 2, 3, 4, 5) }.should raise_error ArgumentError
73
+ end
74
+ end
75
+
76
+ context 'when invalid day is passed' do
77
+ it 'raises ArgumentError' do
78
+ lambda { HHDate.hh(2015, :"7", 31) }.should raise_error ArgumentError
79
+ lambda { HHDate.hh(2012, 7, 31) }.should raise_error ArgumentError
80
+ lambda { HHDate.hh(2012, 1, 31) }.should raise_error ArgumentError
81
+ lambda { HHDate.hh(2012, -13, 1) }.should raise_error ArgumentError
82
+ lambda { HHDate.hh(2015, :x, 8) }.should raise_error ArgumentError
83
+ lambda { HHDate.hh(2012, 0, 8) }.should raise_error ArgumentError
84
+ lambda { HHDate.hh(2012, 1, 0) }.should raise_error ArgumentError
85
+ end
86
+ end
87
+
88
+ context 'when :x is passed as month for a non-Xtr year' do
89
+ it 'raises ArgumentError' do
90
+ lambda { HHDate.hh(2012, :x, 2, 3) }.should raise_error ArgumentError
91
+ end
92
+ end
93
+
94
+ context 'when :x is passed as month for an Xtr year' do
95
+ let(:subject) { HHDate.hh(2015, :x, 2, 3) }
96
+ it 'returns a valid Date object' do
97
+ subject.should be_true
98
+ subject.should be_a Date
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+ # Jan 1, 2012 designate the same day on both Gregorian and Hanke-Henry calendards
105
+ describe '#hh' do
106
+ context 'when called on HHDate.new(2012,1,1)' do
107
+ let(:subject) { HHDate.new(2012,1,1) }
108
+ it 'returns the same value as the Greogrian calendar counterpart' do
109
+ subject.hh.should == '2012-1-1'
110
+ end
111
+ end
112
+ end
113
+
114
+ # Jan 1, 2400 on the Gregorian = Dec 31, 2399 on H-H
115
+ describe '#hh' do
116
+ context 'when called on HHDate.new(2400,1,1)' do
117
+ let(:subject) { HHDate.new(2400,1,1) }
118
+ it 'returns "2399-12-31"' do
119
+ subject.hh.should == '2399-12-31'
120
+ end
121
+ end
122
+ end
123
+
124
+ # http://henry.pha.jhu.edu/calendarDir/ccctDir/ccctHTML/2015.1.html
125
+ # Dec 31, 2015 on Gregorian = X 5, 2015
126
+ describe '#hh' do
127
+ context 'when called on HHDate.new(2015,12,31)' do
128
+ let(:subject) { HHDate.new(2015,12,31) }
129
+ it 'returns "2015-x-5"' do
130
+ subject.hh.should == '2015-x-5'
131
+ end
132
+ end
133
+ end
134
+
135
+ describe '#xtr?' do
136
+ context 'when called on a normal HHDate object with year 2012' do
137
+ let(:subject) { HHDate.new(2012) }
138
+ it 'returns false' do
139
+ subject.xtr?.should be_false
140
+ end
141
+ end
142
+
143
+ context 'when called on a HHDate object for year 2015' do
144
+ let(:subject) { HHDate.hh(2015) }
145
+ it 'returns true' do
146
+ subject.xtr?.should be_true
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ class HHDateTime < DateTime
153
+ extend HankeHenryDate::Module
154
+ include HankeHenryDate
155
+
156
+ private
157
+ def self._hh_arg_limit
158
+ 8
159
+ end
160
+ end
161
+
162
+ describe 'HHDateTime' do
163
+ describe '.hh' do
164
+ context 'valid parameters are passed' do
165
+ it 'does not raise error' do
166
+ HHDateTime.hh(2012, 1, 1).should be_a DateTime
167
+ HHDateTime.hh(2015, -13, 1).should be_a DateTime
168
+ end
169
+ end
170
+ end
171
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hanke-henry
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hirotsugu Asari
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: autotest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Date and DateTime extensions for the Hanke-Henry Calendar
79
+ email:
80
+ - asari.ruby@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .autotest
86
+ - .gitignore
87
+ - .rspec
88
+ - .travis.yml
89
+ - Gemfile
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - autotest/discover.rb
94
+ - hanke-henry.gemspec
95
+ - lib/hanke-henry.rb
96
+ - lib/hanke-henry/date.rb
97
+ - lib/hanke-henry/date_time.rb
98
+ - lib/hanke-henry/hanke_henry_date.rb
99
+ - lib/hanke-henry/version.rb
100
+ - spec/hanke_henry_spec.rb
101
+ homepage: http://github.com/BanzaiMan/hanke-henry
102
+ licenses: []
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: -1893432582186334947
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: -1893432582186334947
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.24
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Date and DateTime extensions for the Hanke-Henry Calendar
131
+ test_files:
132
+ - spec/hanke_henry_spec.rb