Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

prepare for gemification

  • Loading branch information...
commit 446fc1f562e35662386d02a4d509b8fa0da00db9 1 parent 143e240
Eric Gjertsen authored
1  .gitignore
View
@@ -1 +1,2 @@
scratch
+Gemfile.lock
3  Gemfile
View
@@ -0,0 +1,3 @@
+source :rubygems
+
+gemspec
2  lib/tempr.rb
View
@@ -0,0 +1,2 @@
+require File.expand_path('tempr/version', File.dirname(__FILE__))
+require File.expand_path('tempr/date_time_range', File.dirname(__FILE__))
0  lib/date_time_range.rb → lib/tempr/date_time_range.rb
View
File renamed without changes
9 lib/tempr/version.rb
View
@@ -0,0 +1,9 @@
+
+module Tempr
+ module Version
+ MAJOR = 0
+ MINOR = 1
+ TINY = 0
+ STRING = "#{MAJOR}.#{MINOR}.#{TINY}"
+ end
+end
20 tempr.gemspec
View
@@ -0,0 +1,20 @@
+require File.expand_path('lib/tempr/version',File.dirname(__FILE__))
+
+Gem::Specification.new do |s|
+ s.name = "tempr"
+ s.version = Tempr::Version::STRING
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Eric Gjertsen"]
+ s.email = ["ericgj72@gmail.com"]
+ s.homepage = "http://github.com/ericgj/tempr"
+ s.summary = "No-fussin' temporal expressions library"
+ s.description = ""
+
+ s.files = `git ls-files -c`.split("\n") - ['tempr.gemspec']
+ s.require_path = 'lib'
+ s.rubyforge_project = 'tempr'
+ s.required_rubygems_version = '>= 1.3.6'
+ s.required_ruby_version = '>= 1.9.2'
+
+ s.add_development_dependency 'minitest'
+end
45 test/at_time.rb
View
@@ -1,33 +1,36 @@
require File.expand_path('test_helper', File.dirname(__FILE__))
-module Fixtures
+module AtTimeTests
+ module Fixtures
- BaseRanges = {:local => Time.parse('2012-01-01 00:00:00 -0500')...
- Time.parse('2013-01-01 00:00:00 -0500'),
- :utc => Time.parse('2012-01-01 00:00:00 UTC')...
- Time.parse('2013-01-01 00:00:00 UTC')
- }
-
-end
+ BaseRanges = {:local => Time.parse('2012-01-01 00:00:00 -0500')...
+ Time.parse('2013-01-01 00:00:00 -0500'),
+ :utc => Time.parse('2012-01-01 00:00:00 UTC')...
+ Time.parse('2013-01-01 00:00:00 UTC')
+ }
+
+ end
-describe 'DateTimeRange#at_time' do
+ describe 'DateTimeRange#at_time' do
- [:local, :utc].each do |time_type|
-
- describe "across daylight savings time boundaries for #{time_type} times" do
+ [:local, :utc].each do |time_type|
- let(:subject) { Fixtures::BaseRanges[time_type].extend(Tempr::DateTimeRange) }
+ describe "across daylight savings time boundaries for #{time_type} times" do
- it 'should be at the same time of day regardless of time zone' do
- subject.each_day.at_time("2:00pm",60*60).each do |range|
- offset = range.begin.utc_offset
- actual = range.begin.getlocal(offset).hour
- #puts "#{range}"
- assert_equal 14, actual, "for range: #{range}"
+ let(:subject) { Fixtures::BaseRanges[time_type].extend(Tempr::DateTimeRange) }
+
+ it 'should be at the same time of day regardless of time zone' do
+ subject.each_day.at_time("2:00pm",60*60).each do |range|
+ offset = range.begin.utc_offset
+ actual = range.begin.getlocal(offset).hour
+ #puts "#{range}"
+ assert_equal 14, actual, "for range: #{range}"
+ end
end
+
end
end
-
end
-end
+
+end # namespace
3  test/suite.rb
View
@@ -0,0 +1,3 @@
+%w[ time_subrange at_time ].each do |test|
+ require File.expand_path(test,File.dirname(__FILE__))
+end
4 test/test_helper.rb
View
@@ -1,4 +1,6 @@
-require File.expand_path('../lib/date_time_range', File.dirname(__FILE__))
+require File.expand_path('../lib/tempr', File.dirname(__FILE__))
+
+gem "minitest"
require 'minitest/spec'
MiniTest::Unit.autorun
458 test/time_subrange.rb
View
@@ -1,255 +1,257 @@
require File.expand_path('test_helper', File.dirname(__FILE__))
-module Fixtures
-
- # 20 seconds / minutes / hours
- BaseRanges = { :each_seconds => Time.parse('2012-02-13 15:32:41')...
- Time.parse('2012-02-13 15:33:01'),
- :each_minutes => Time.parse('2012-02-13 13:46:25')...
- Time.parse('2012-02-13 14:06:25'),
- :each_hours => Time.parse('2012-02-13 12:52:22')...
- Time.parse('2012-02-14 08:52:22')
- }
-
- ExclusiveDateRange = Date.parse('2012-02-13')...Date.parse('2012-02-15')
- NonExclusiveDateRange = Date.parse('2012-02-13')..Date.parse('2012-02-14')
-
- # note: I don't particularly like generating fixtures like this,
- # but it's probably just as suceptible to error as hand-typing here
- module Expected
-
- Default = {
- :each_seconds =>
- (0..19).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin
- memo << (s0+i...s0+i+1)
- end,
- :each_minutes =>
- (0..19).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin
- memo << (s0+i*60...s0+(i+1)*60)
- end,
- :each_hours =>
- (0..19).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin
- memo << (s0+i*60*60...s0+(i+1)*60*60)
- end
- }
+module TimeSubRangeTests
+ module Fixtures
- Params3_0_1 = {
- :each_seconds =>
- (0..6).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin
- memo << (s0+(i*3)...s0+(i*3)+1)
- end,
- :each_minutes =>
- (0..6).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin
- memo << (s0+(i*3)*60...s0+(i*3+1)*60)
- end,
- :each_hours =>
- (0..6).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin
- memo << (s0+(i*3)*60*60...s0+(i*3+1)*60*60)
- end
- }
-
- Params1_5_1 = {
- :each_seconds =>
- (0..14).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin+5
- memo << (s0+i...s0+i+1)
- end,
- :each_minutes =>
- (0..14).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin+5*60
- memo << (s0+i*60...s0+(i+1)*60)
- end,
- :each_hours =>
- (0..14).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin+5*60*60
- memo << (s0+i*60*60...s0+(i+1)*60*60)
- end
- }
+ # 20 seconds / minutes / hours
+ BaseRanges = { :each_seconds => Time.parse('2012-02-13 15:32:41')...
+ Time.parse('2012-02-13 15:33:01'),
+ :each_minutes => Time.parse('2012-02-13 13:46:25')...
+ Time.parse('2012-02-13 14:06:25'),
+ :each_hours => Time.parse('2012-02-13 12:52:22')...
+ Time.parse('2012-02-14 08:52:22')
+ }
- Params3_0_3 = {
- :each_seconds =>
- (0..6).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin
- memo << (s0+(i*3)...s0+(i*3)+3)
- end,
- :each_minutes =>
- (0..6).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin
- memo << (s0+(i*3)*60...s0+(i*3+3)*60)
- end,
- :each_hours =>
- (0..6).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin
- memo << (s0+(i*3)*60*60...s0+(i*3+3)*60*60)
- end
- }
+ ExclusiveDateRange = Date.parse('2012-02-13')...Date.parse('2012-02-15')
+ NonExclusiveDateRange = Date.parse('2012-02-13')..Date.parse('2012-02-14')
- Params5_0_2 = {
- :each_seconds =>
- (0..3).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin
- memo << (s0+(i*5)...s0+(i*5)+2)
- end,
- :each_minutes =>
- (0..3).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin
- memo << (s0+(i*5)*60...s0+(i*5+2)*60)
- end,
- :each_hours =>
- (0..3).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin
- memo << (s0+(i*5)*60*60...s0+(i*5+2)*60*60)
- end
- }
+ # note: I don't particularly like generating fixtures like this,
+ # but it's probably just as suceptible to error as hand-typing here
+ module Expected
+
+ Default = {
+ :each_seconds =>
+ (0..19).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin
+ memo << (s0+i...s0+i+1)
+ end,
+ :each_minutes =>
+ (0..19).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin
+ memo << (s0+i*60...s0+(i+1)*60)
+ end,
+ :each_hours =>
+ (0..19).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin
+ memo << (s0+i*60*60...s0+(i+1)*60*60)
+ end
+ }
+
+ Params3_0_1 = {
+ :each_seconds =>
+ (0..6).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin
+ memo << (s0+(i*3)...s0+(i*3)+1)
+ end,
+ :each_minutes =>
+ (0..6).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin
+ memo << (s0+(i*3)*60...s0+(i*3+1)*60)
+ end,
+ :each_hours =>
+ (0..6).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin
+ memo << (s0+(i*3)*60*60...s0+(i*3+1)*60*60)
+ end
+ }
- Params1_0_3 = {
- :each_seconds =>
- (0..19).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin
- memo << (s0+i...s0+i+3)
- end,
- :each_minutes =>
- (0..19).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin
- memo << (s0+i*60...s0+(i+3)*60)
- end,
- :each_hours =>
- (0..19).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin
- memo << (s0+i*60*60...s0+(i+3)*60*60)
- end
- }
-
- Params7_1_3 = {
- :each_seconds =>
- (0..2).inject([]) do |memo, i|
- s0 = BaseRanges[:each_seconds].begin+1
- memo << (s0+(i*7)...s0+(i*7)+3)
- end,
- :each_minutes =>
- (0..2).inject([]) do |memo, i|
- s0 = BaseRanges[:each_minutes].begin+1*60
- memo << (s0+(i*7)*60...s0+(i*7+3)*60)
- end,
- :each_hours =>
- (0..2).inject([]) do |memo, i|
- s0 = BaseRanges[:each_hours].begin+1*60*60
- memo << (s0+(i*7)*60*60...s0+(i*7+3)*60*60)
- end
- }
+ Params1_5_1 = {
+ :each_seconds =>
+ (0..14).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin+5
+ memo << (s0+i...s0+i+1)
+ end,
+ :each_minutes =>
+ (0..14).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin+5*60
+ memo << (s0+i*60...s0+(i+1)*60)
+ end,
+ :each_hours =>
+ (0..14).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin+5*60*60
+ memo << (s0+i*60*60...s0+(i+1)*60*60)
+ end
+ }
+
+ Params3_0_3 = {
+ :each_seconds =>
+ (0..6).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin
+ memo << (s0+(i*3)...s0+(i*3)+3)
+ end,
+ :each_minutes =>
+ (0..6).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin
+ memo << (s0+(i*3)*60...s0+(i*3+3)*60)
+ end,
+ :each_hours =>
+ (0..6).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin
+ memo << (s0+(i*3)*60*60...s0+(i*3+3)*60*60)
+ end
+ }
+
+ Params5_0_2 = {
+ :each_seconds =>
+ (0..3).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin
+ memo << (s0+(i*5)...s0+(i*5)+2)
+ end,
+ :each_minutes =>
+ (0..3).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin
+ memo << (s0+(i*5)*60...s0+(i*5+2)*60)
+ end,
+ :each_hours =>
+ (0..3).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin
+ memo << (s0+(i*5)*60*60...s0+(i*5+2)*60*60)
+ end
+ }
+
+ Params1_0_3 = {
+ :each_seconds =>
+ (0..19).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin
+ memo << (s0+i...s0+i+3)
+ end,
+ :each_minutes =>
+ (0..19).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin
+ memo << (s0+i*60...s0+(i+3)*60)
+ end,
+ :each_hours =>
+ (0..19).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin
+ memo << (s0+i*60*60...s0+(i+3)*60*60)
+ end
+ }
+
+ Params7_1_3 = {
+ :each_seconds =>
+ (0..2).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_seconds].begin+1
+ memo << (s0+(i*7)...s0+(i*7)+3)
+ end,
+ :each_minutes =>
+ (0..2).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_minutes].begin+1*60
+ memo << (s0+(i*7)*60...s0+(i*7+3)*60)
+ end,
+ :each_hours =>
+ (0..2).inject([]) do |memo, i|
+ s0 = BaseRanges[:each_hours].begin+1*60*60
+ memo << (s0+(i*7)*60*60...s0+(i*7+3)*60*60)
+ end
+ }
+
+ end
end
-
-end
-# ---
+ # ---
-describe 'DateTimeRange, single time iterators' do
+ describe 'DateTimeRange, single time iterators' do
+
+ [:each_seconds, :each_minutes, :each_hours].each do |meth|
+ describe meth do
+
+ let(:subject) { Fixtures::BaseRanges[meth].extend(Tempr::DateTimeRange) }
+
+ it 'must exhibit default behavior if no parameters passed' do
+ results = subject.send(meth).to_a
+ assert_equal Fixtures::Expected::Default[meth], results
+ end
+
+ it 'must iterate using passed step length' do
+ results = subject.send(meth,3).to_a
+ assert_equal Fixtures::Expected::Params3_0_1[meth], results
+ end
+
+ it 'must iterate starting at passed offset' do
+ results = subject.send(meth,1,5).to_a
+ assert_equal Fixtures::Expected::Params1_5_1[meth], results
+ end
+
+ it 'must return ranges of passed duration, duration == step' do
+ results = subject.send(meth,3,0,3).to_a
+ assert_equal Fixtures::Expected::Params3_0_3[meth], results
+ end
+
+ it 'must return ranges of passed duration, duration < step' do
+ results = subject.send(meth,5,0,2).to_a
+ assert_equal Fixtures::Expected::Params5_0_2[meth], results
+ end
+
+ it 'must return ranges of passed duration, duration > step' do
+ results = subject.send(meth,1,0,3).to_a
+ assert_equal Fixtures::Expected::Params1_0_3[meth], results
+ end
- [:each_seconds, :each_minutes, :each_hours].each do |meth|
- describe meth do
-
- let(:subject) { Fixtures::BaseRanges[meth].extend(Tempr::DateTimeRange) }
-
- it 'must exhibit default behavior if no parameters passed' do
- results = subject.send(meth).to_a
- assert_equal Fixtures::Expected::Default[meth], results
- end
-
- it 'must iterate using passed step length' do
- results = subject.send(meth,3).to_a
- assert_equal Fixtures::Expected::Params3_0_1[meth], results
- end
-
- it 'must iterate starting at passed offset' do
- results = subject.send(meth,1,5).to_a
- assert_equal Fixtures::Expected::Params1_5_1[meth], results
+ it 'must return ranges of passed step, offset, and duration' do
+ results = subject.send(meth,7,1,3).to_a
+ assert_equal Fixtures::Expected::Params7_1_3[meth], results
+ end
+
end
+
+ end
+
+ describe "with exclusive date ranges" do
- it 'must return ranges of passed duration, duration == step' do
- results = subject.send(meth,3,0,3).to_a
- assert_equal Fixtures::Expected::Params3_0_3[meth], results
- end
+ let(:subject) { Fixtures::ExclusiveDateRange.extend(Tempr::DateTimeRange) }
- it 'must return ranges of passed duration, duration < step' do
- results = subject.send(meth,5,0,2).to_a
- assert_equal Fixtures::Expected::Params5_0_2[meth], results
+ it 'each_seconds must return ranges starting up to 23:59:59 of the end date' do
+ last_result = subject.each_seconds.to_a.last
+ assert_equal ( (Fixtures::ExclusiveDateRange.end.to_time - 1)...
+ Fixtures::ExclusiveDateRange.end.to_time ),
+ last_result
end
-
- it 'must return ranges of passed duration, duration > step' do
- results = subject.send(meth,1,0,3).to_a
- assert_equal Fixtures::Expected::Params1_0_3[meth], results
+
+ it 'each_minutes must return ranges starting up to 23:59:00 of the end date' do
+ last_result = subject.each_minutes.to_a.last
+ assert_equal ( (Fixtures::ExclusiveDateRange.end.to_time - 60)...
+ Fixtures::ExclusiveDateRange.end.to_time ),
+ last_result
end
- it 'must return ranges of passed step, offset, and duration' do
- results = subject.send(meth,7,1,3).to_a
- assert_equal Fixtures::Expected::Params7_1_3[meth], results
+ it 'each_minutes must return ranges starting up to 23:00:00 of the end date' do
+ last_result = subject.each_hours.to_a.last
+ assert_equal ( (Fixtures::ExclusiveDateRange.end.to_time - 60*60)...
+ Fixtures::ExclusiveDateRange.end.to_time ),
+ last_result
end
end
-
- end
-
- describe "with exclusive date ranges" do
-
- let(:subject) { Fixtures::ExclusiveDateRange.extend(Tempr::DateTimeRange) }
-
- it 'each_seconds must return ranges starting up to 23:59:59 of the end date' do
- last_result = subject.each_seconds.to_a.last
- assert_equal ( (Fixtures::ExclusiveDateRange.end.to_time - 1)...
- Fixtures::ExclusiveDateRange.end.to_time ),
- last_result
- end
-
- it 'each_minutes must return ranges starting up to 23:59:00 of the end date' do
- last_result = subject.each_minutes.to_a.last
- assert_equal ( (Fixtures::ExclusiveDateRange.end.to_time - 60)...
- Fixtures::ExclusiveDateRange.end.to_time ),
- last_result
- end
-
- it 'each_minutes must return ranges starting up to 23:00:00 of the end date' do
- last_result = subject.each_hours.to_a.last
- assert_equal ( (Fixtures::ExclusiveDateRange.end.to_time - 60*60)...
- Fixtures::ExclusiveDateRange.end.to_time ),
- last_result
- end
-
- end
- describe "with non-exclusive date ranges" do
-
- let(:subject) { Fixtures::NonExclusiveDateRange.extend(Tempr::DateTimeRange) }
-
- it 'each_seconds must return ranges starting up to 23:59:59 of the end date + 1' do
- last_result = subject.each_seconds.to_a.last
- assert_equal ( ((Fixtures::NonExclusiveDateRange.end+1).to_time - 1)...
- (Fixtures::NonExclusiveDateRange.end+1).to_time ),
- last_result
- end
+ describe "with non-exclusive date ranges" do
+
+ let(:subject) { Fixtures::NonExclusiveDateRange.extend(Tempr::DateTimeRange) }
+
+ it 'each_seconds must return ranges starting up to 23:59:59 of the end date + 1' do
+ last_result = subject.each_seconds.to_a.last
+ assert_equal ( ((Fixtures::NonExclusiveDateRange.end+1).to_time - 1)...
+ (Fixtures::NonExclusiveDateRange.end+1).to_time ),
+ last_result
+ end
- it 'each_minutes must return ranges starting up to 23:59:00 of the end date + 1' do
- last_result = subject.each_minutes.to_a.last
- assert_equal ( ((Fixtures::NonExclusiveDateRange.end+1).to_time - 60)...
- (Fixtures::NonExclusiveDateRange.end+1).to_time ),
- last_result
- end
+ it 'each_minutes must return ranges starting up to 23:59:00 of the end date + 1' do
+ last_result = subject.each_minutes.to_a.last
+ assert_equal ( ((Fixtures::NonExclusiveDateRange.end+1).to_time - 60)...
+ (Fixtures::NonExclusiveDateRange.end+1).to_time ),
+ last_result
+ end
- it 'each_minutes must return ranges starting up to 23:00:00 of the end date + 1' do
- last_result = subject.each_hours.to_a.last
- assert_equal ( ((Fixtures::NonExclusiveDateRange.end+1).to_time - 60*60)...
- (Fixtures::NonExclusiveDateRange.end+1).to_time ),
- last_result
+ it 'each_minutes must return ranges starting up to 23:00:00 of the end date + 1' do
+ last_result = subject.each_hours.to_a.last
+ assert_equal ( ((Fixtures::NonExclusiveDateRange.end+1).to_time - 60*60)...
+ (Fixtures::NonExclusiveDateRange.end+1).to_time ),
+ last_result
+ end
+
end
+
end
-
-
-end
+end # namespace
Please sign in to comment.
Something went wrong with that request. Please try again.