ttilley-time_crisis 0.0.1
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +81 -0
- data/VERSION.yml +4 -0
- data/lib/time_crisis.rb +6 -0
- data/lib/time_crisis/date_range.rb +54 -0
- data/lib/time_crisis/meteorological_seasons.rb +57 -0
- data/lib/time_crisis/named_months.rb +24 -0
- data/lib/time_crisis/support.rb +8 -0
- data/lib/time_crisis/support/advance.rb +47 -0
- data/lib/time_crisis/support/change.rb +97 -0
- data/lib/time_crisis/support/conversions.rb +82 -0
- data/lib/time_crisis/support/current.rb +23 -0
- data/lib/time_crisis/support/days_in_month.rb +11 -0
- data/lib/time_crisis/support/readable_inspect.rb +33 -0
- data/test/test_helper.rb +10 -0
- data/test/time_crisis_test.rb +7 -0
- data/time_crisis.gemspec +63 -0
- metadata +84 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Travis Tilley
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "time_crisis"
|
8
|
+
gem.summary = %Q{date and time related extensions}
|
9
|
+
gem.description = %Q{date and time related extensions}
|
10
|
+
gem.email = "ttilley@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ttilley/time_crisis"
|
12
|
+
gem.authors = ["Travis Tilley"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
begin
|
43
|
+
require 'reek/rake_task'
|
44
|
+
Reek::RakeTask.new do |t|
|
45
|
+
t.fail_on_error = true
|
46
|
+
t.verbose = false
|
47
|
+
t.source_files = 'lib/**/*.rb'
|
48
|
+
end
|
49
|
+
rescue LoadError
|
50
|
+
task :reek do
|
51
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
require 'roodi'
|
57
|
+
require 'roodi_task'
|
58
|
+
RoodiTask.new do |t|
|
59
|
+
t.verbose = false
|
60
|
+
end
|
61
|
+
rescue LoadError
|
62
|
+
task :roodi do
|
63
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
task :default => :test
|
68
|
+
|
69
|
+
require 'rake/rdoctask'
|
70
|
+
Rake::RDocTask.new do |rdoc|
|
71
|
+
if File.exist?('VERSION')
|
72
|
+
version = File.read('VERSION')
|
73
|
+
else
|
74
|
+
version = ""
|
75
|
+
end
|
76
|
+
|
77
|
+
rdoc.rdoc_dir = 'rdoc'
|
78
|
+
rdoc.title = "time_crisis #{version}"
|
79
|
+
rdoc.rdoc_files.include('README*')
|
80
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
81
|
+
end
|
data/VERSION.yml
ADDED
data/lib/time_crisis.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module TimeCrisis::DateRange
|
2
|
+
module InstanceMethods
|
3
|
+
def from(unit, scale)
|
4
|
+
range(unit, scale, 'past')
|
5
|
+
end
|
6
|
+
|
7
|
+
def for(unit, scale)
|
8
|
+
range(unit, scale, 'future')
|
9
|
+
end
|
10
|
+
|
11
|
+
def range(unit=nil, scale=nil, direction=nil)
|
12
|
+
direction ||= 'past'
|
13
|
+
unit ||= 1
|
14
|
+
scale ||= 'years'
|
15
|
+
|
16
|
+
scale = scale.pluralize if scale.respond_to?(:pluralize)
|
17
|
+
|
18
|
+
period_base = self.to_date
|
19
|
+
period_advance = period_base.advance({
|
20
|
+
scale.to_sym => (direction == 'past' ? -unit : unit)
|
21
|
+
})
|
22
|
+
|
23
|
+
# I'd rather be using ..., but I need to flip-flop the range order
|
24
|
+
if direction == 'past'
|
25
|
+
(period_advance.advance(:days => 1))..period_base
|
26
|
+
else
|
27
|
+
period_base..(period_advance.advance(:days => -1))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
def range(options={})
|
34
|
+
start = options[:begin].nil? ? false : options[:begin].to_date
|
35
|
+
stop = options[:end].nil? ? false : options[:end].to_date
|
36
|
+
|
37
|
+
scale = options[:scale] || 'years'
|
38
|
+
unit = options[:unit] || 1
|
39
|
+
|
40
|
+
if start && !stop
|
41
|
+
start.for(unit, scale)
|
42
|
+
elsif !start && stop
|
43
|
+
stop.from(unit, scale)
|
44
|
+
elsif start && stop
|
45
|
+
(start..stop)
|
46
|
+
else
|
47
|
+
raise ArgumentError, "Cannot create a range with neither start nor end..."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Date.send(:include, TimeCrisis::DateRange::InstanceMethods)
|
54
|
+
Date.extend(TimeCrisis::DateRange::ClassMethods)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module TimeCrisis
|
2
|
+
# Meteorological seasons are reckoned by temperature, with summer being
|
3
|
+
# the hottest quarter of the year and winter the coldest quarter of the
|
4
|
+
# year. Using this reckoning, the Roman calendar began the year and the
|
5
|
+
# spring season on the first of March, with each season occupying three
|
6
|
+
# months. In 1780 the Societas Meteorologica Palatina, an early
|
7
|
+
# international organization for meteorology, defined seasons as groupings
|
8
|
+
# of three whole months. Ever since, professional meteorologists
|
9
|
+
# everywhere have used this definition. So, in meteorology for the
|
10
|
+
# Northern hemisphere: spring begins on 1 March, summer on 1 June, autumn
|
11
|
+
# on 1 September, and winter on 1 December.
|
12
|
+
# - http://en.wikipedia.org/wiki/Season
|
13
|
+
module MeteorologicalSeasons
|
14
|
+
def beginning_of_meteorological_spring
|
15
|
+
::Date.civil(self.year, 3, 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
def beginning_of_meteorological_summer
|
19
|
+
::Date.civil(self.year, 6, 1)
|
20
|
+
end
|
21
|
+
|
22
|
+
def beginning_of_meteorological_autumn
|
23
|
+
::Date.civil(self.year, 9, 1)
|
24
|
+
end
|
25
|
+
alias beginning_of_meteorological_fall beginning_of_meteorological_autumn
|
26
|
+
|
27
|
+
def beginning_of_meteorological_winter
|
28
|
+
::Date.civil(self.year, 12, 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
def meteorological_spring?
|
32
|
+
(beginning_of_meteorological_spring...beginning_of_meteorological_summer).include?(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def meteorological_summer?
|
36
|
+
(beginning_of_meteorological_summer...beginning_of_meteorological_autumn).include?(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def meteorological_autumn?
|
40
|
+
(beginning_of_meteorological_autumn...beginning_of_meteorological_winter).include?(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def meteorological_winter?
|
44
|
+
(beginning_of_year...beginning_of_meteorological_spring).include?(self) ||
|
45
|
+
(beginning_of_meteorological_winter..end_of_year).include?(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
def meteorological_season
|
49
|
+
return 'spring' if meteorological_spring?
|
50
|
+
return 'summer' if meteorological_summer?
|
51
|
+
return 'fall' if meteorological_autumn?
|
52
|
+
return 'winter' if meteorological_winter?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Date.send(:include, TimeCrisis::MeteorologicalSeasons)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TimeCrisis
|
2
|
+
module NamedMonths
|
3
|
+
def january(year=nil); month_range(1, year); end
|
4
|
+
def february(year=nil); month_range(2, year); end
|
5
|
+
def march(year=nil); month_range(3, year); end
|
6
|
+
def april(year=nil); month_range(4, year); end
|
7
|
+
def may(year=nil); month_range(5, year); end
|
8
|
+
def june(year=nil); month_range(6, year); end
|
9
|
+
def july(year=nil); month_range(7, year); end
|
10
|
+
def august(year=nil); month_range(8, year); end
|
11
|
+
def september(year=nil); month_range(9, year); end
|
12
|
+
def october(year=nil); month_range(10, year); end
|
13
|
+
def november(year=nil); month_range(11, year); end
|
14
|
+
def december(year=nil); month_range(12, year); end
|
15
|
+
|
16
|
+
def month_range(month, year = nil)
|
17
|
+
year ||= current.year
|
18
|
+
base = ::Date.civil(year, month, 1)
|
19
|
+
base.for(1, 'months')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Date.extend(TimeCrisis::NamedMonths)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module TimeCrisis::Support; end
|
2
|
+
|
3
|
+
require 'time_crisis/support/current'
|
4
|
+
require 'time_crisis/support/days_in_month'
|
5
|
+
require 'time_crisis/support/change'
|
6
|
+
require 'time_crisis/support/advance'
|
7
|
+
require 'time_crisis/support/conversions'
|
8
|
+
require 'time_crisis/support/readable_inspect'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module TimeCrisis::Support::Advance
|
2
|
+
module Date
|
3
|
+
def advance(options)
|
4
|
+
options = options.dup
|
5
|
+
d = self
|
6
|
+
d = d >> options.delete(:years) * 12 if options[:years]
|
7
|
+
d = d >> options.delete(:months) if options[:months]
|
8
|
+
d = d + options.delete(:weeks) * 7 if options[:weeks]
|
9
|
+
d = d + options.delete(:days) if options[:days]
|
10
|
+
d
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Time
|
15
|
+
def advance(options)
|
16
|
+
unless options[:weeks].nil?
|
17
|
+
options[:weeks], partial_weeks = options[:weeks].divmod(1)
|
18
|
+
options[:days] = (options[:days] || 0) + 7 * partial_weeks
|
19
|
+
end
|
20
|
+
|
21
|
+
unless options[:days].nil?
|
22
|
+
options[:days], partial_days = options[:days].divmod(1)
|
23
|
+
options[:hours] = (options[:hours] || 0) + 24 * partial_days
|
24
|
+
end
|
25
|
+
|
26
|
+
d = to_date.advance(options)
|
27
|
+
time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
|
28
|
+
seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
|
29
|
+
seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module DateTime
|
34
|
+
def advance(options)
|
35
|
+
d = to_date.advance(options)
|
36
|
+
datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
|
37
|
+
seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
|
38
|
+
seconds_to_advance == 0 ? datetime_advanced_by_date : datetime_advanced_by_date.since(seconds_to_advance)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
[Date, Time, DateTime].each do |klass|
|
44
|
+
unless klass.instance_methods.include?('advance')
|
45
|
+
klass.send(:include, TimeCrisis::Support::Advance.const_get(klass.to_s))
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module TimeCrisis::Support::Change
|
2
|
+
module Date
|
3
|
+
def change(options={})
|
4
|
+
::Date.civil(
|
5
|
+
options[:year] || self.year,
|
6
|
+
options[:month] || self.month,
|
7
|
+
options[:day] || self.day
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def beginning_of_year
|
12
|
+
change(:month => 1, :day => 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
def end_of_year
|
16
|
+
change(:month => 12, :day => 31)
|
17
|
+
end
|
18
|
+
|
19
|
+
def beginning_of_month
|
20
|
+
change(:day => 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
def end_of_month
|
24
|
+
last_day = self.class.days_in_month(self.month, self.year)
|
25
|
+
change(:day => last_day)
|
26
|
+
end
|
27
|
+
|
28
|
+
def beginning_of_day
|
29
|
+
to_time
|
30
|
+
end
|
31
|
+
|
32
|
+
def end_of_day
|
33
|
+
to_time.end_of_day
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Time
|
38
|
+
def change(options={})
|
39
|
+
::Time.send(
|
40
|
+
utc? ? :utc_time : :local,
|
41
|
+
options[:year] || year,
|
42
|
+
options[:month] || month,
|
43
|
+
options[:day] || day,
|
44
|
+
options[:hour] || hour,
|
45
|
+
options[:min] || (options[:hour] ? 0 : min),
|
46
|
+
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
|
47
|
+
options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def beginning_of_year
|
52
|
+
change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0)
|
53
|
+
end
|
54
|
+
|
55
|
+
def end_of_year
|
56
|
+
change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59)
|
57
|
+
end
|
58
|
+
|
59
|
+
def beginning_of_month
|
60
|
+
change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)
|
61
|
+
end
|
62
|
+
|
63
|
+
def end_of_month
|
64
|
+
last_day = self.class.days_in_month(self.month, self.year)
|
65
|
+
change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
66
|
+
end
|
67
|
+
|
68
|
+
def beginning_of_day
|
69
|
+
change(:hour => 0, :min => 0, :sec => 0, :usec => 0)
|
70
|
+
end
|
71
|
+
|
72
|
+
def end_of_day
|
73
|
+
change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
module DateTime
|
78
|
+
def change(options={})
|
79
|
+
::DateTime.civil(
|
80
|
+
options[:year] || year,
|
81
|
+
options[:month] || month,
|
82
|
+
options[:day] || day,
|
83
|
+
options[:hour] || hour,
|
84
|
+
options[:min] || (options[:hour] ? 0 : min),
|
85
|
+
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
|
86
|
+
options[:offset] || offset,
|
87
|
+
options[:start] || start
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
[Date, Time, DateTime].each do |klass|
|
94
|
+
unless klass.instance_methods.include?('change')
|
95
|
+
klass.send(:include, TimeCrisis::Support::Change.const_get(klass.to_s))
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rational'
|
2
|
+
|
3
|
+
module TimeCrisis::Support::Conversions
|
4
|
+
module Date
|
5
|
+
def to_date
|
6
|
+
self
|
7
|
+
end if RUBY_VERSION < '1.9'
|
8
|
+
|
9
|
+
def to_time(form = :local)
|
10
|
+
::Time.send(form, year, month, day)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_datetime
|
14
|
+
::DateTime.civil(year, month, day, 0, 0, 0, 0)
|
15
|
+
end if RUBY_VERSION < '1.9'
|
16
|
+
end
|
17
|
+
|
18
|
+
module Time
|
19
|
+
def to_date
|
20
|
+
::Date.new(year, month, day)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_time
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_datetime
|
28
|
+
::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module DateTime
|
33
|
+
def to_date
|
34
|
+
::Date.civil(year, month, day)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_time
|
38
|
+
self.offset == 0 ? ::Time.utc(year, month, day, hour, min, sec) : self
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_datetime
|
42
|
+
self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module String
|
47
|
+
def to_time(form = :utc)
|
48
|
+
d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction).map { |arg| arg || 0 }
|
49
|
+
d[6] *= 1000000
|
50
|
+
::Time.send(form, *d)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_date
|
54
|
+
::Date.civil(::Date._parse(self, false).values_at(:year, :mon, :mday))
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_datetime
|
58
|
+
d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :sec_fraction).map { |arg| arg || 0 }
|
59
|
+
d[5] += d.pop
|
60
|
+
::DateTime.civil(*d)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# active support has support for time zones, so don't overwrite its' version
|
66
|
+
unless Time.instance_methods.include?('local_time')
|
67
|
+
Date.class_eval do
|
68
|
+
# Ruby 1.9 has Date#to_time which converts to localtime only.
|
69
|
+
remove_method :to_time if instance_methods.include?(:to_time)
|
70
|
+
include TimeCrisis::Support::Conversions::Date
|
71
|
+
end
|
72
|
+
|
73
|
+
DateTime.class_eval do
|
74
|
+
# Ruby 1.9 has DateTime#to_time which internally relies on Time.
|
75
|
+
remove_method :to_time if instance_methods.include?(:to_time)
|
76
|
+
include TimeCrisis::Support::Conversions::DateTime
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
Time.send(:include, TimeCrisis::Support::Conversions::Time)
|
81
|
+
|
82
|
+
String.send(:include, TimeCrisis::Support::Conversions::String)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TimeCrisis::Support::Current
|
2
|
+
module Time
|
3
|
+
def current
|
4
|
+
now
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Date
|
9
|
+
def current
|
10
|
+
today
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module DateTime
|
15
|
+
def current
|
16
|
+
::Time.now.to_datetime
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Time.extend(TimeCrisis::Support::Current::Time) unless Time.respond_to?(:current)
|
22
|
+
Date.extend(TimeCrisis::Support::Current::Date) unless Date.respond_to?(:current)
|
23
|
+
DateTime.extend(TimeCrisis::Support::Current::DateTime) unless DateTime.respond_to?(:current)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module TimeCrisis::Support::DaysInMonth
|
2
|
+
GregorianDaysInMonth = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
3
|
+
|
4
|
+
def days_in_month(month, year = current.year)
|
5
|
+
(month == 2 && ::Date.gregorian_leap?(year)) ? 29 : GregorianDaysInMonth[month]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Date.extend(TimeCrisis::Support::DaysInMonth) unless Date.respond_to?(:days_in_month)
|
10
|
+
Time.extend(TimeCrisis::Support::DaysInMonth) unless Time.respond_to?(:days_in_month)
|
11
|
+
DateTime.extend(TimeCrisis::Support::DaysInMonth) unless DateTime.respond_to?(:days_in_month)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module TimeCrisis::Support::ReadableInspect
|
2
|
+
module Date
|
3
|
+
def readable_inspect
|
4
|
+
strftime("%a, %d %b %Y")
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
alias_method :default_inspect, :inspect
|
10
|
+
alias_method :inspect, :readable_inspect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module DateTime
|
16
|
+
def readable_inspect
|
17
|
+
to_s(:rfc822)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.class_eval do
|
22
|
+
alias_method :default_inspect, :inspect
|
23
|
+
alias_method :inspect, :readable_inspect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Date.send(:include, TimeCrisis::Support::ReadableInspect::Date) unless
|
30
|
+
Date.instance_methods.include?('readable_inspect')
|
31
|
+
|
32
|
+
DateTime.send(:include, TimeCrisis::Support::ReadableInspect::DateTime) unless
|
33
|
+
DateTime.instance_methods.include?('readable_inspect')
|
data/test/test_helper.rb
ADDED
data/time_crisis.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{time_crisis}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Travis Tilley"]
|
12
|
+
s.date = %q{2009-09-17}
|
13
|
+
s.description = %q{date and time related extensions}
|
14
|
+
s.email = %q{ttilley@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"lib/time_crisis.rb",
|
27
|
+
"lib/time_crisis/date_range.rb",
|
28
|
+
"lib/time_crisis/meteorological_seasons.rb",
|
29
|
+
"lib/time_crisis/named_months.rb",
|
30
|
+
"lib/time_crisis/support.rb",
|
31
|
+
"lib/time_crisis/support/advance.rb",
|
32
|
+
"lib/time_crisis/support/change.rb",
|
33
|
+
"lib/time_crisis/support/conversions.rb",
|
34
|
+
"lib/time_crisis/support/current.rb",
|
35
|
+
"lib/time_crisis/support/days_in_month.rb",
|
36
|
+
"lib/time_crisis/support/readable_inspect.rb",
|
37
|
+
"test/test_helper.rb",
|
38
|
+
"test/time_crisis_test.rb",
|
39
|
+
"time_crisis.gemspec"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/ttilley/time_crisis}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.5}
|
45
|
+
s.summary = %q{date and time related extensions}
|
46
|
+
s.test_files = [
|
47
|
+
"test/test_helper.rb",
|
48
|
+
"test/time_crisis_test.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ttilley-time_crisis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Tilley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-17 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: date and time related extensions
|
26
|
+
email: ttilley@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION.yml
|
41
|
+
- lib/time_crisis.rb
|
42
|
+
- lib/time_crisis/date_range.rb
|
43
|
+
- lib/time_crisis/meteorological_seasons.rb
|
44
|
+
- lib/time_crisis/named_months.rb
|
45
|
+
- lib/time_crisis/support.rb
|
46
|
+
- lib/time_crisis/support/advance.rb
|
47
|
+
- lib/time_crisis/support/change.rb
|
48
|
+
- lib/time_crisis/support/conversions.rb
|
49
|
+
- lib/time_crisis/support/current.rb
|
50
|
+
- lib/time_crisis/support/days_in_month.rb
|
51
|
+
- lib/time_crisis/support/readable_inspect.rb
|
52
|
+
- test/test_helper.rb
|
53
|
+
- test/time_crisis_test.rb
|
54
|
+
- time_crisis.gemspec
|
55
|
+
has_rdoc: false
|
56
|
+
homepage: http://github.com/ttilley/time_crisis
|
57
|
+
licenses:
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: date and time related extensions
|
82
|
+
test_files:
|
83
|
+
- test/test_helper.rb
|
84
|
+
- test/time_crisis_test.rb
|