ttilley-time_crisis 0.0.3 → 0.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.
@@ -3,55 +3,58 @@ Arbitrary Date Ranges
3
3
 
4
4
  You can create a Range with a beginning and end Date using the convenience methods 'for' and 'from'. 'for' will create a range into the future while 'from' creates a range into the past.
5
5
 
6
- Date.today.for(2, 'years')
7
- => Fri, 18 Sep 2009..Sat, 17 Sep 2011
6
+ TimeCrisis::Date.today.for(2, 'years')
7
+ => #<TimeCrisis::Date 2009-09-22>..#<TimeCrisis::Date 2011-09-21>
8
8
 
9
- Date.today.from(2, 'years')
10
- => Wed, 19 Sep 2007..Fri, 18 Sep 2009
9
+ TimeCrisis::Date.today.from(2, 'years')
10
+ => #<TimeCrisis::Date 2007-09-23>..#<TimeCrisis::Date 2009-09-22>
11
11
 
12
12
  If you want to be more literal in your syntax, you can use the range method directly:
13
13
 
14
- Date.today.range(2, 'months', 'future')
15
- => Fri, 18 Sep 2009..Tue, 17 Nov 2009
14
+ TimeCrisis::Date.today.range(2, 'months', 'future')
15
+ => #<TimeCrisis::Date 2009-09-22>..#<TimeCrisis::Date 2009-11-21>
16
16
 
17
- Date.today.range(2, 'months', 'past')
18
- => Sun, 19 Jul 2009..Fri, 18 Sep 2009
17
+ TimeCrisis::Date.today.range(2, 'months', 'past')
18
+ => #<TimeCrisis::Date 2009-07-23>..#<TimeCrisis::Date 2009-09-22>
19
19
 
20
20
  There is also a class method for defining ranges that allows you to specify a beginning and end for the range, or just one of beginning or end and then the scale (months, years) and unit (number of scale).
21
21
 
22
- Date.range(:begin => Date.today, :scale => 'months', :unit => 3)
23
- => Fri, 18 Sep 2009..Thu, 17 Dec 2009
22
+ TimeCrisis::Date.range(:begin => Date.today, :scale => 'months', :unit => 3)
23
+ => #<TimeCrisis::Date 2009-09-22>..#<TimeCrisis::Date 2009-12-21>
24
24
 
25
- Date.range(:begin => Date.civil(2008, 3, 1), :end => Date.civil(2008, 12, 31))
26
- => Sat, 01 Mar 2008..Wed, 31 Dec 2008
25
+ TimeCrisis::Date.range(:begin => Date.civil(2008, 3, 1), :end => Date.civil(2008, 12, 31))
26
+ => #<TimeCrisis::Date 2008-03-01>..#<TimeCrisis::Date 2008-12-31>
27
27
 
28
28
  Named Months
29
29
  ============
30
30
 
31
31
  A range of dates for a month can be created using that month's name, optionally passing in a year.
32
32
 
33
- Date.february # 28 days in feb 2009
34
- => Sun, 01 Feb 2009..Sat, 28 Feb 2009
33
+ TimeCrisis::Date.february # 28 days in feb 2009
34
+ => #<TimeCrisis::Date 2009-02-01>..#<TimeCrisis::Date 2009-02-28>
35
35
 
36
- Date.february(2008) # 29 days in feb 2008
37
- => Fri, 01 Feb 2008..Fri, 29 Feb 2008
36
+ TimeCrisis::Date.february(2008) # 29 days in feb 2008
37
+ => #<TimeCrisis::Date 2008-02-01>..#<TimeCrisis::Date 2008-02-29>
38
38
 
39
39
 
40
40
  Meteorological Season Calculations
41
41
  ==================================
42
42
 
43
- Date.civil(2009, 4, 1).meteorological_spring?
43
+ TimeCrisis::Date.beginning_of_meteorological_spring
44
+ => #<TimeCrisis::Date 2009-03-01>
45
+
46
+ TimeCrisis::Date.beginning_of_meteorological_spring(2008)
47
+ => #<TimeCrisis::Date 2008-03-01>
48
+
49
+ TimeCrisis::Date.civil(2009, 4, 1).meteorological_spring?
44
50
  => true
45
51
 
46
- Date.civil(2009, 4, 1).meteorological_winter?
52
+ TimeCrisis::Date.civil(2009, 4, 1).meteorological_winter?
47
53
  => false
48
54
 
49
- Date.civil(2009, 10, 1).meteorological_season
55
+ TimeCrisis::Date.civil(2009, 10, 1).meteorological_season
50
56
  => "fall"
51
57
 
52
- Date.today.beginning_of_meteorological_summer
53
- => Mon, 01 Jun 2009
54
-
55
58
 
56
59
 
57
60
  Copyright (c) 2009 Travis Tilley. See LICENSE for details.
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "ttilley@gmail.com"
11
11
  gem.homepage = "http://github.com/ttilley/time_crisis"
12
12
  gem.authors = ["Travis Tilley"]
13
+ gem.add_dependency 'third_base'
13
14
  gem.add_development_dependency "thoughtbot-shoulda"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 3
2
+ :patch: 0
4
3
  :major: 0
4
+ :minor: 1
@@ -1,9 +1,12 @@
1
- module TimeCrisis; end
1
+ require 'third_base'
2
2
 
3
- # the support directory is a simplified version of the same methods in
4
- # ActiveSupport, and are completely unnecessary if we're actually
5
- # using that library. I just didn't want to depend on it.
6
- require 'time_crisis/support' unless defined?(ActiveSupport)
3
+ module TimeCrisis
4
+ include ThirdBase
5
+ end
6
+
7
+ # add needed bits of active support to time crisis
8
+ # necessary now that it uses ThirdBase
9
+ require 'time_crisis/support'
7
10
 
8
11
  require 'time_crisis/meteorological_seasons'
9
12
  require 'time_crisis/date_range'
@@ -7,8 +7,8 @@ class TimeCrisis::DateRange < Range
7
7
  options[:end] = args.shift unless args.empty?
8
8
  options[:exclude_end] = args.shift unless args.empty?
9
9
 
10
- start = options[:begin].nil? ? false : options[:begin].to_date
11
- stop = options[:end].nil? ? false : options[:end].to_date
10
+ start = options[:begin].nil? ? false : options[:begin].to_tc_date
11
+ stop = options[:end].nil? ? false : options[:end].to_tc_date
12
12
 
13
13
  unit = options[:unit] || 1
14
14
  scale = options[:scale] || 'years'
@@ -24,12 +24,12 @@ class TimeCrisis::DateRange < Range
24
24
  end
25
25
 
26
26
  def include?(datelike)
27
- super(datelike.to_date)
27
+ super(datelike.to_tc_date)
28
28
  end
29
29
 
30
30
  def each_slice_by_date(*args, &block)
31
31
  dates = args.map! do |datelike|
32
- date = datelike.to_date
32
+ date = datelike.to_tc_date
33
33
  raise ArgumentError, "Date not within range: #{date}" unless self.include?(date)
34
34
  date
35
35
  end
@@ -98,5 +98,8 @@ module TimeCrisis::DateRange::Date
98
98
  end
99
99
  end
100
100
 
101
- Date.send(:include, TimeCrisis::DateRange::Date::InstanceMethods)
102
- Date.extend(TimeCrisis::DateRange::Date::ClassMethods)
101
+ TimeCrisis::Date.send(:include, TimeCrisis::DateRange::Date::InstanceMethods)
102
+ TimeCrisis::Date.extend(TimeCrisis::DateRange::Date::ClassMethods)
103
+
104
+ ::Date.send(:include, TimeCrisis::DateRange::Date::InstanceMethods)
105
+ ::Date.extend(TimeCrisis::DateRange::Date::ClassMethods)
@@ -11,47 +11,55 @@ module TimeCrisis
11
11
  # on 1 September, and winter on 1 December.
12
12
  # - http://en.wikipedia.org/wiki/Season
13
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
14
+ module ClassMethods
15
+ def beginning_of_meteorological_spring(year=current.year)
16
+ TimeCrisis::Date.civil(year, 3, 1)
17
+ end
34
18
 
35
- def meteorological_summer?
36
- (beginning_of_meteorological_summer...beginning_of_meteorological_autumn).include?(self)
37
- end
19
+ def beginning_of_meteorological_summer(year=current.year)
20
+ TimeCrisis::Date.civil(year, 6, 1)
21
+ end
38
22
 
39
- def meteorological_autumn?
40
- (beginning_of_meteorological_autumn...beginning_of_meteorological_winter).include?(self)
41
- end
23
+ def beginning_of_meteorological_autumn(year=current.year)
24
+ TimeCrisis::Date.civil(year, 9, 1)
25
+ end
26
+ alias beginning_of_meteorological_fall beginning_of_meteorological_autumn
42
27
 
43
- def meteorological_winter?
44
- (beginning_of_year...beginning_of_meteorological_spring).include?(self) ||
45
- (beginning_of_meteorological_winter..end_of_year).include?(self)
28
+ def beginning_of_meteorological_winter(year=current.year)
29
+ TimeCrisis::Date.civil(year, 12, 1)
30
+ end
46
31
  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?
32
+
33
+ module InstanceMethods
34
+ def meteorological_spring?
35
+ [3,4,5].include?(self.month)
36
+ end
37
+
38
+ def meteorological_summer?
39
+ [6,7,8].include?(self.month)
40
+ end
41
+
42
+ def meteorological_autumn?
43
+ [9,10,11].include?(self.month)
44
+ end
45
+ alias meteorological_fall? meteorological_autumn?
46
+
47
+ def meteorological_winter?
48
+ [1,2,12].include?(self.month)
49
+ end
50
+
51
+ def meteorological_season
52
+ case self.month
53
+ when (1..2) then 'winter'
54
+ when (3..5) then 'spring'
55
+ when (6..8) then 'summer'
56
+ when (9..11) then 'fall'
57
+ when 12 then 'winter'
58
+ end
59
+ end
53
60
  end
54
61
  end
55
62
  end
56
63
 
57
- Date.send(:include, TimeCrisis::MeteorologicalSeasons)
64
+ TimeCrisis::Date.extend(TimeCrisis::MeteorologicalSeasons::ClassMethods)
65
+ TimeCrisis::Date.send(:include, TimeCrisis::MeteorologicalSeasons::InstanceMethods)
@@ -13,12 +13,16 @@ module TimeCrisis
13
13
  def november(year=nil); month_range(11, year); end
14
14
  def december(year=nil); month_range(12, year); end
15
15
 
16
- def month_range(month, year = nil)
16
+ def month_range(month=nil, year=nil)
17
+ month ||= current.month
17
18
  year ||= current.year
18
- base = ::Date.civil(year, month, 1)
19
+
20
+ base = TimeCrisis::Date.civil(year, month, 1)
19
21
  base.for(1, 'months')
20
22
  end
21
23
  end
22
24
  end
23
25
 
24
- Date.extend(TimeCrisis::NamedMonths)
26
+ TimeCrisis::Date.extend(TimeCrisis::NamedMonths)
27
+
28
+ ::Date.extend(TimeCrisis::NamedMonths)
@@ -1,8 +1,7 @@
1
1
  module TimeCrisis::Support; end
2
2
 
3
+ require 'time_crisis/support/conversions'
3
4
  require 'time_crisis/support/current'
4
- require 'time_crisis/support/days_in_month'
5
5
  require 'time_crisis/support/change'
6
6
  require 'time_crisis/support/advance'
7
- require 'time_crisis/support/conversions'
8
- require 'time_crisis/support/readable_inspect'
7
+ require 'time_crisis/support/readable_inspect'
@@ -11,37 +11,15 @@ module TimeCrisis::Support::Advance
11
11
  end
12
12
  end
13
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
14
  module DateTime
34
15
  def advance(options)
35
- d = to_date.advance(options)
36
- datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
16
+ d = to_tc_date.advance(options)
17
+ advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
37
18
  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)
19
+ seconds_to_advance == 0 ? advanced_by_date : (advanced_by_date + Rational(seconds_to_advance.round, 86400).to_f)
39
20
  end
40
21
  end
41
22
  end
42
23
 
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
24
+ TimeCrisis::Date.send(:include, TimeCrisis::Support::Advance::Date)
25
+ TimeCrisis::DateTime.send(:include, TimeCrisis::Support::Advance::DateTime)
@@ -1,7 +1,7 @@
1
1
  module TimeCrisis::Support::Change
2
2
  module Date
3
3
  def change(options={})
4
- ::Date.civil(
4
+ TimeCrisis::Date.civil(
5
5
  options[:year] || self.year,
6
6
  options[:month] || self.month,
7
7
  options[:day] || self.day
@@ -21,77 +21,26 @@ module TimeCrisis::Support::Change
21
21
  end
22
22
 
23
23
  def end_of_month
24
- last_day = self.class.days_in_month(self.month, self.year)
24
+ last_day = TimeCrisis::Date.days_in_month(self.month, self.year)
25
25
  change(:day => last_day)
26
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
27
  end
76
28
 
77
29
  module DateTime
78
30
  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
31
+ TimeCrisis::DateTime.civil(
32
+ options[:year] || year,
33
+ options[:month] || month,
34
+ options[:day] || day,
35
+ options[:hour] || hour,
36
+ options[:min] || (options[:hour] ? 0 : min),
37
+ options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
38
+ options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec),
39
+ options[:offset] || offset
88
40
  )
89
41
  end
90
42
  end
91
43
  end
92
44
 
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
45
+ TimeCrisis::Date.send(:include, TimeCrisis::Support::Change::Date)
46
+ TimeCrisis::DateTime.send(:include, TimeCrisis::Support::Change::DateTime)
@@ -1,82 +1,77 @@
1
- require 'rational'
2
-
3
1
  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)
2
+ module Ruby
3
+ module Date
4
+ def to_tc_date
5
+ TimeCrisis::Date.civil(year, month, day)
6
+ end
7
+
8
+ def to_tc_datetime
9
+ TimeCrisis::DateTime.civil(year, month, day, 0, 0, 0, 0)
10
+ end
11
11
  end
12
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
13
+ module Time
14
+ def to_tc_date
15
+ TimeCrisis::Date.civil(year, month, day)
16
+ end
22
17
 
23
- def to_time
24
- self
18
+ def to_tc_datetime
19
+ TimeCrisis::DateTime.civil(year, month, day, hour, min, sec, 0, utc_offset)
20
+ end
25
21
  end
26
22
 
27
- def to_datetime
28
- ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400))
29
- end
30
- end
23
+ module DateTime
24
+ def to_tc_date
25
+ TimeCrisis::Date.civil(year, month, day)
26
+ end
31
27
 
32
- module DateTime
33
- def to_date
34
- ::Date.civil(year, month, day)
28
+ def to_tc_datetime
29
+ TimeCrisis::DateTime.civil(year, month, day, hour, min, sec, 0, (offset * 86400).to_i)
30
+ end
35
31
  end
36
32
 
37
- def to_time
38
- self.offset == 0 ? ::Time.utc(year, month, day, hour, min, sec) : self
39
- end
33
+ module String
34
+ def to_tc_date(opts={})
35
+ TimeCrisis::Date.parse(self, opts)
36
+ end
40
37
 
41
- def to_datetime
42
- self
38
+ def to_tc_datetime(opts={})
39
+ TimeCrisis::DateTime.parse(self, opts)
40
+ end
43
41
  end
44
42
  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))
43
+
44
+ module Internal
45
+ module Date
46
+ def to_tc_date
47
+ self
48
+ end
49
+ alias to_date to_tc_date
50
+
51
+ def to_tc_datetime
52
+ TimeCrisis::DateTime.civil(year, month, day, 0, 0, 0, 0)
53
+ end
54
+ alias to_datetime to_tc_datetime
55
55
  end
56
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)
57
+ module DateTime
58
+ def to_tc_date
59
+ TimeCrisis::Date.civil(year, month, day)
60
+ end
61
+ alias to_date to_tc_date
62
+
63
+ def to_tc_datetime
64
+ self
65
+ end
66
+ alias to_datetime to_tc_datetime
61
67
  end
62
68
  end
63
69
  end
64
70
 
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)
71
+ TimeCrisis::Date.send(:include, TimeCrisis::Support::Conversions::Internal::Date)
72
+ TimeCrisis::DateTime.send(:include, TimeCrisis::Support::Conversions::Internal::DateTime)
81
73
 
82
- String.send(:include, TimeCrisis::Support::Conversions::String)
74
+ ::Date.send(:include, TimeCrisis::Support::Conversions::Ruby::Date)
75
+ ::Time.send(:include, TimeCrisis::Support::Conversions::Ruby::Time)
76
+ ::DateTime.send(:include, TimeCrisis::Support::Conversions::Ruby::DateTime)
77
+ ::String.send(:include, TimeCrisis::Support::Conversions::Ruby::String)
@@ -1,10 +1,4 @@
1
1
  module TimeCrisis::Support::Current
2
- module Time
3
- def current
4
- now
5
- end
6
- end
7
-
8
2
  module Date
9
3
  def current
10
4
  today
@@ -13,11 +7,10 @@ module TimeCrisis::Support::Current
13
7
 
14
8
  module DateTime
15
9
  def current
16
- ::Time.now.to_datetime
10
+ now
17
11
  end
18
12
  end
19
13
  end
20
14
 
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)
15
+ TimeCrisis::Date.extend(TimeCrisis::Support::Current::Date)
16
+ TimeCrisis::DateTime.extend(TimeCrisis::Support::Current::DateTime)
@@ -1,9 +1,9 @@
1
1
  module TimeCrisis::Support::ReadableInspect
2
2
  module Date
3
3
  def readable_inspect
4
- strftime("%a, %d %b %Y")
4
+ "#<TimeCrisis::Date #{strftime('%Y-%m-%d')}>"
5
5
  end
6
-
6
+
7
7
  def self.included(base)
8
8
  base.class_eval do
9
9
  alias_method :default_inspect, :inspect
@@ -11,12 +11,12 @@ module TimeCrisis::Support::ReadableInspect
11
11
  end
12
12
  end
13
13
  end
14
-
14
+
15
15
  module DateTime
16
16
  def readable_inspect
17
- to_s(:rfc822)
17
+ "#<TimeCrisis::DateTime #{strftime('%Y-%m-%dT%H:%M:%S%Z')}>"
18
18
  end
19
-
19
+
20
20
  def self.included(base)
21
21
  base.class_eval do
22
22
  alias_method :default_inspect, :inspect
@@ -26,8 +26,5 @@ module TimeCrisis::Support::ReadableInspect
26
26
  end
27
27
  end
28
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')
29
+ TimeCrisis::Date.send(:include, TimeCrisis::Support::ReadableInspect::Date)
30
+ TimeCrisis::DateTime.send(:include, TimeCrisis::Support::ReadableInspect::DateTime)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{time_crisis}
8
- s.version = "0.0.3"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Travis Tilley"]
12
- s.date = %q{2009-09-21}
12
+ s.date = %q{2009-09-22}
13
13
  s.description = %q{date and time related extensions}
14
14
  s.email = %q{ttilley@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,7 +32,6 @@ Gem::Specification.new do |s|
32
32
  "lib/time_crisis/support/change.rb",
33
33
  "lib/time_crisis/support/conversions.rb",
34
34
  "lib/time_crisis/support/current.rb",
35
- "lib/time_crisis/support/days_in_month.rb",
36
35
  "lib/time_crisis/support/readable_inspect.rb",
37
36
  "test/test_helper.rb",
38
37
  "test/time_crisis_test.rb",
@@ -53,11 +52,14 @@ Gem::Specification.new do |s|
53
52
  s.specification_version = 3
54
53
 
55
54
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<third_base>, [">= 0"])
56
56
  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
57
  else
58
+ s.add_dependency(%q<third_base>, [">= 0"])
58
59
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
60
  end
60
61
  else
62
+ s.add_dependency(%q<third_base>, [">= 0"])
61
63
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
64
  end
63
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttilley-time_crisis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Tilley
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-21 00:00:00 -07:00
12
+ date: 2009-09-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: third_base
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: thoughtbot-shoulda
17
27
  type: :development
@@ -47,7 +57,6 @@ files:
47
57
  - lib/time_crisis/support/change.rb
48
58
  - lib/time_crisis/support/conversions.rb
49
59
  - lib/time_crisis/support/current.rb
50
- - lib/time_crisis/support/days_in_month.rb
51
60
  - lib/time_crisis/support/readable_inspect.rb
52
61
  - test/test_helper.rb
53
62
  - test/time_crisis_test.rb
@@ -1,11 +0,0 @@
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)