relativity 0.0.6 → 0.0.7
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/Changelog.rdoc +4 -0
- data/README.rdoc +6 -7
- data/TODO +5 -9
- data/lib/relativity/day_time/new.rb +1 -7
- data/lib/relativity/day_time.rb +13 -0
- data/lib/relativity/day_time_range.rb +12 -7
- data/lib/relativity/version.rb +1 -1
- data/spec/day_time_range/marshal_spec.rb +16 -0
- data/spec/day_time_range/parsing_spec.rb +15 -12
- metadata +6 -5
data/Changelog.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Time, Date and DateTime classes don't have a mode for working with relative
|
|
4
4
|
time inside 1 day (or 1 week, 1 month, 1 quarter, etc.).
|
5
5
|
|
6
6
|
A relative time object, relative to a day or a week, is useful to describe
|
7
|
-
e.g. opening hours of a business. Time ranges are built on top, so the
|
7
|
+
e.g. opening hours of a business. Time ranges are built on top, so the
|
8
8
|
ranges of opening hours can be represented.
|
9
9
|
|
10
10
|
== Example
|
@@ -23,13 +23,12 @@ ranges of opening hours can be represented.
|
|
23
23
|
dt.seconds #=> 40
|
24
24
|
dt.nano_seconds #=> 568257238
|
25
25
|
|
26
|
-
DayTimeRange.
|
27
|
-
dtr = DayTimeRange.new("8 until 12:30")
|
28
|
-
# => #<DayTimeRange:0x9bfa4ec @start_day_time=08:00:00, @end_day_time=12:30:00>
|
26
|
+
dtr = DayTimeRange.new("8 to 12:30") # => 08:00:00 to 12:30:00
|
29
27
|
dtr.start # => 08:00:00
|
30
28
|
dtr.end # => 12:30:00
|
31
29
|
dtr.to_s # => "08:00:00 until 12:30:00"
|
32
30
|
|
33
|
-
night_shift = DayTimeRange.new("21:45..06:05"
|
34
|
-
|
35
|
-
|
31
|
+
night_shift = DayTimeRange.new("21:45..06:05") # => 21:45:00..06:05:00
|
32
|
+
|
33
|
+
wrong_format = DayTimeRange.new("11 to 15", :separator => '..')
|
34
|
+
Relativity::InvalidRangeFormatError: Maybe the range separator was not set correctly? Separator used was ".."
|
data/TODO
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
Features to be implemented:
|
2
2
|
|
3
|
-
|
4
|
-
week_day = WeekDay.new
|
3
|
+
* Add a '...' range (up to, but not including)
|
5
4
|
|
6
|
-
|
5
|
+
* WeekTime
|
6
|
+
* WeekDay
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
week_day_range
|
8
|
+
* WeekTimeRange
|
9
|
+
* WeekDayRange
|
11
10
|
|
12
|
-
ActiveRecord coupling (Aggregation ?)
|
13
11
|
|
14
12
|
=====================================
|
15
13
|
A discussion I sent on 2012-01-12 on ruby-talk:
|
@@ -80,5 +78,3 @@ as abstract as I want it. IIRC , ActiveSupport works on actual Date instances
|
|
80
78
|
(which are not "relative" but anchored to a specific absolute time or date).
|
81
79
|
I did not see this abstract concept of the "last day of the month" or
|
82
80
|
"a Friday in a random week" fully implemented.
|
83
|
-
|
84
|
-
|
@@ -26,14 +26,8 @@ module DayTime::New
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def hh_mm_ss_from_string(input)
|
29
|
-
|
30
|
-
esc_separator = Regexp.escape(separator) # e.g. separator is '.'
|
29
|
+
r = Regexp.new(self.class.matcher)
|
31
30
|
input.strip!
|
32
|
-
match_hh = '(?<hh>\d\d?)'
|
33
|
-
match_mm = '(' + esc_separator + '(?<mm>\d\d?))?'
|
34
|
-
match_ss = '(' + esc_separator + '(?<ss>\d\d?))?'
|
35
|
-
matcher = '\A' + match_hh + match_mm + match_ss + '\Z'
|
36
|
-
r = Regexp.new(matcher)
|
37
31
|
matchdata = r.match(input)
|
38
32
|
raise Relativity::InvalidFormatError if matchdata.nil?
|
39
33
|
return [matchdata[:hh].to_i, matchdata[:mm].to_i, matchdata[:ss].to_i]
|
data/lib/relativity/day_time.rb
CHANGED
@@ -12,4 +12,17 @@ class DayTime
|
|
12
12
|
':'
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.matcher
|
16
|
+
matcher = '\A' + internal_matcher + '\Z'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.internal_matcher
|
20
|
+
separator = default_separator
|
21
|
+
esc_separator = Regexp.escape(separator) # e.g. separator is '.'
|
22
|
+
match_hh = '(?<hh>\d\d?)'
|
23
|
+
match_mm = '(' + esc_separator + '(?<mm>\d\d?))?'
|
24
|
+
match_ss = '(' + esc_separator + '(?<ss>\d\d?))?'
|
25
|
+
match_hh + match_mm + match_ss
|
26
|
+
end
|
27
|
+
|
15
28
|
end
|
@@ -24,19 +24,24 @@ class DayTimeRange
|
|
24
24
|
start.to_s + @separator + self.end.to_s
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.default_separator
|
28
|
-
" until "
|
29
|
-
end
|
30
|
-
|
31
27
|
private
|
32
28
|
|
33
29
|
def start_end_from_string(input, options)
|
34
|
-
@separator =
|
35
|
-
|
36
|
-
|
30
|
+
@separator = options && options[:separator]
|
31
|
+
if @separator
|
32
|
+
esc_separator = Regexp.escape(@separator)
|
33
|
+
matcher = '\A(?<start>.+)' + esc_separator + '(?<end>.+)\Z'
|
34
|
+
else
|
35
|
+
matcher = '\A' +
|
36
|
+
'(?<start>' + DayTime.internal_matcher + ')' +
|
37
|
+
'(?<separator>[^\d]+)' +
|
38
|
+
'(?<end>' + DayTime.internal_matcher + ')' +
|
39
|
+
'\Z'
|
40
|
+
end
|
37
41
|
r = Regexp.new(matcher)
|
38
42
|
matchdata = r.match(input)
|
39
43
|
raise Relativity::InvalidRangeFormatError.new(:separator => @separator) if matchdata.nil?
|
44
|
+
@separator ||= matchdata[:separator]
|
40
45
|
return [DayTime.new(matchdata[:start]), DayTime.new(matchdata[:end])]
|
41
46
|
end
|
42
47
|
|
data/lib/relativity/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DayTimeRange do
|
4
|
+
|
5
|
+
context "separator" do
|
6
|
+
|
7
|
+
it "until should be in the marshal" do
|
8
|
+
Marshal.dump(DayTimeRange.new("22 until 06:30")).should match(/until/)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "test_sep should be in the marshal" do
|
12
|
+
Marshal.dump(DayTimeRange.new("22 test_sep 06:30", :separator => ' test_sep ')).should match(/ test_sep /)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -2,9 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DayTimeRange do
|
4
4
|
|
5
|
-
it "default separator is ' until '" do
|
6
|
-
DayTimeRange.default_separator.should == ' until '
|
7
|
-
end
|
8
5
|
|
9
6
|
it "start time is correct" do
|
10
7
|
dtr = DayTimeRange.new("8 until 11", :separator => " until ")
|
@@ -21,14 +18,6 @@ describe DayTimeRange do
|
|
21
18
|
dtr.start.should == DayTime.new(8)
|
22
19
|
end
|
23
20
|
|
24
|
-
it "InvalidRangeFormatError is raised with incorrect separator format" do
|
25
|
-
lambda {DayTimeRange.new("8..11")}.should raise_error Relativity::InvalidRangeFormatError
|
26
|
-
end
|
27
|
-
|
28
|
-
it "Exception with separator message is raised with incorrect separator format" do
|
29
|
-
lambda {DayTimeRange.new("8..11")}.should raise_error 'Maybe the range separator was not set correctly? Separator used was " until "'
|
30
|
-
end
|
31
|
-
|
32
21
|
it "parsing with other separator remembers the separator" do
|
33
22
|
dtr = DayTimeRange.new("8 - 11", :separator => " - ")
|
34
23
|
dtr.separator.should == " - "
|
@@ -42,7 +31,21 @@ describe DayTimeRange do
|
|
42
31
|
|
43
32
|
it "not setting separator returns default_separator" do
|
44
33
|
dtr = DayTimeRange.new("8 until 11")
|
45
|
-
dtr.separator.should ==
|
34
|
+
dtr.separator.should == " until "
|
35
|
+
end
|
36
|
+
|
37
|
+
it "not setting separator with different separator does not reais exception" do
|
38
|
+
dtr = DayTimeRange.new("8..11")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "not setting separator returns correct separator" do
|
42
|
+
dtr = DayTimeRange.new("8..11")
|
43
|
+
dtr.separator.should == '..'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "not setting separator returns correct full result" do
|
47
|
+
dtr = DayTimeRange.new("8..11")
|
48
|
+
dtr.to_s.should == "08:00:00..11:00:00"
|
46
49
|
end
|
47
50
|
|
48
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relativity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &80499580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.7'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *80499580
|
25
25
|
description: time and time_ranges relative to day, week, month, quarter etc.
|
26
26
|
email:
|
27
27
|
- peter@vandenabeele.com
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- spec/day_time/new_spec.rb
|
56
56
|
- spec/day_time/output_spec.rb
|
57
57
|
- spec/day_time/overflow_spec.rb
|
58
|
+
- spec/day_time_range/marshal_spec.rb
|
58
59
|
- spec/day_time_range/new_spec.rb
|
59
60
|
- spec/day_time_range/output_spec.rb
|
60
61
|
- spec/day_time_range/parsing_spec.rb
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
84
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.10
|
85
86
|
signing_key:
|
86
87
|
specification_version: 3
|
87
88
|
summary: time and time_ranges relative to day, week, month, quarter etc.
|