ice_cube_chosko 0.1.0 → 0.1.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.
@@ -13,6 +13,11 @@ module IceCube
13
13
  true
14
14
  end
15
15
 
16
+ # Never overrides duration
17
+ def duration
18
+ nil
19
+ end
20
+
16
21
  def next_time(t, schedule, closing_time)
17
22
  unless closing_time && closing_time < t
18
23
  time if time.to_i >= t.to_i
@@ -42,7 +42,7 @@ module IceCube
42
42
  end
43
43
 
44
44
  def self.match_zone(input_time, reference)
45
- return unless time = ensure_time(input_time)
45
+ return unless time = ensure_time(input_time, reference)
46
46
  time = if reference.respond_to? :time_zone
47
47
  time.in_time_zone(reference.time_zone)
48
48
  else
@@ -58,13 +58,21 @@ module IceCube
58
58
  end
59
59
 
60
60
  # Ensure that this is either nil, or a time
61
- def self.ensure_time(time, date_eod = false)
61
+ def self.ensure_time(time, reference = nil, date_eod = false)
62
62
  case time
63
63
  when DateTime
64
64
  warn "IceCube: DateTime support is deprecated (please use Time) at: #{ caller[2] }"
65
65
  Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
66
66
  when Date
67
- date_eod ? end_of_date(time) : time.to_time
67
+ if date_eod
68
+ end_of_date(time, reference)
69
+ else
70
+ if reference
71
+ build_in_zone([time.year, time.month, time.day], reference)
72
+ else
73
+ time.to_time
74
+ end
75
+ end
68
76
  else
69
77
  time
70
78
  end
@@ -15,6 +15,7 @@ module IceCube
15
15
 
16
16
  include Validations::Count
17
17
  include Validations::Until
18
+ include Validations::OverrideDuration
18
19
 
19
20
  # Validations ordered for efficiency in sequence of:
20
21
  # * descending intervals
@@ -22,12 +23,13 @@ module IceCube
22
23
  # * base values by cardinality (n = 60, 60, 31, 24, 12, 7)
23
24
  # * locks by cardinality (n = 365, 60, 60, 31, 24, 12, 7)
24
25
  # * interval multiplier
26
+ # * duration
25
27
  VALIDATION_ORDER = [
26
28
  :year, :month, :day, :wday, :hour, :min, :sec, :count, :until,
27
29
  :base_sec, :base_min, :base_day, :base_hour, :base_month, :base_wday,
28
30
  :day_of_year, :second_of_minute, :minute_of_hour, :day_of_month,
29
31
  :hour_of_day, :month_of_year, :day_of_week,
30
- :interval
32
+ :interval, :duration
31
33
  ]
32
34
 
33
35
  attr_reader :validations
@@ -5,6 +5,8 @@ module IceCube
5
5
  module Validations::Day
6
6
 
7
7
  def day(*days)
8
+ days = days.flatten
9
+ return self if days.empty?
8
10
  days.flatten.each do |day|
9
11
  unless day.is_a?(Fixnum) || day.is_a?(Symbol)
10
12
  raise ArgumentError, "expecting Fixnum or Symbol value for day, got #{day.inspect}"
@@ -0,0 +1,53 @@
1
+ module IceCube
2
+
3
+ module Validations::OverrideDuration
4
+
5
+ # Value reader for duration
6
+ def duration
7
+ @duration
8
+ end
9
+
10
+ def override_duration(duration)
11
+ @duration = duration
12
+ replace_validations_for(:duration, duration.nil? ? nil : [Validation.new(duration)])
13
+ self
14
+ end
15
+
16
+ class Validation
17
+
18
+ attr_reader :duration
19
+
20
+ def initialize(duration)
21
+ @duration = duration
22
+ end
23
+
24
+ def type
25
+ :duration
26
+ end
27
+
28
+ def dst_adjust?
29
+ false
30
+ end
31
+
32
+ # Always valid
33
+ def validate(step_time, schedule)
34
+ end
35
+
36
+ # Do nothing, duration does not affect output string
37
+ def build_s(builder)
38
+ end
39
+
40
+ def build_hash(builder)
41
+ builder[:duration] = duration
42
+ end
43
+
44
+ # Do nothing.Do not export DURATION to ical beacuse it would conflict
45
+ # with DTEND property of schedule (if any)
46
+ def build_ical(builder)
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -11,7 +11,6 @@ module IceCube
11
11
  deprecated_alias :until_date, :until_time
12
12
 
13
13
  def until(time)
14
- time = TimeUtil.ensure_time(time, true)
15
14
  @until = time
16
15
  replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
17
16
  self
@@ -34,7 +33,8 @@ module IceCube
34
33
  end
35
34
 
36
35
  def validate(step_time, schedule)
37
- raise UntilExceeded if step_time > time
36
+ end_time = TimeUtil.ensure_time(time, schedule.start_time, true)
37
+ raise UntilExceeded if step_time > end_time
38
38
  end
39
39
 
40
40
  def build_s(builder)
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = '0.1.0'
4
-
3
+ VERSION = '0.1.1'
4
+
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -23,42 +23,26 @@ RSpec.configure do |config|
23
23
 
24
24
  config.include WarningHelpers
25
25
 
26
- config.around :each, :if_active_support_time => true do |example|
27
- example.run if defined? ActiveSupport
28
- end
29
-
30
- config.around :each, :if_active_support_time => false do |example|
31
- unless defined? ActiveSupport
32
- stubbed_active_support = ::ActiveSupport = Module.new
33
- example.run
34
- Object.send :remove_const, :ActiveSupport
26
+ config.before :each do |example|
27
+ if example.metadata[:requires_active_support]
28
+ raise 'ActiveSupport required but not present' unless defined?(ActiveSupport)
35
29
  end
36
30
  end
37
31
 
38
32
  config.around :each do |example|
39
33
  if zone = example.metadata[:system_time_zone]
40
- @orig_zone = ENV['TZ']
34
+ orig_zone = ENV['TZ']
41
35
  ENV['TZ'] = zone
42
36
  example.run
43
- ENV['TZ'] = @orig_zone
37
+ ENV['TZ'] = orig_zone
44
38
  else
45
39
  example.run
46
40
  end
47
41
  end
48
42
 
49
- config.before :each do
50
- if time_args = @example.metadata[:system_time]
51
- case time_args
52
- when Array then Time.stub!(:now).and_return Time.local(*time_args)
53
- when Time then Time.stub!(:now).and_return time_args
54
- end
55
- end
56
- end
57
-
58
43
  config.around :each, expect_warnings: true do |example|
59
44
  capture_warnings do
60
45
  example.run
61
46
  end
62
47
  end
63
-
64
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube_chosko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Crepezzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -28,58 +28,16 @@ dependencies:
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.12.0
33
+ version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.12.0
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 3.0.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 3.0.0
55
- - !ruby/object:Gem::Dependency
56
- name: tzinfo
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: i18n
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
40
+ version: '3'
83
41
  description: ice_cube is a recurring date library for Ruby. It allows for quick,
84
42
  programatic expansion of recurring date rules.
85
43
  email: john@crepezzi.com
@@ -87,9 +45,13 @@ executables: []
87
45
  extensions: []
88
46
  extra_rdoc_files: []
89
47
  files:
48
+ - config/locales/de.yml
90
49
  - config/locales/en.yml
91
50
  - config/locales/es.yml
51
+ - config/locales/fr.yml
92
52
  - config/locales/ja.yml
53
+ - config/locales/ru.yml
54
+ - config/locales/sv.yml
93
55
  - lib/ice_cube.rb
94
56
  - lib/ice_cube/builders/hash_builder.rb
95
57
  - lib/ice_cube/builders/ical_builder.rb
@@ -130,6 +92,7 @@ files:
130
92
  - lib/ice_cube/validations/minutely_interval.rb
131
93
  - lib/ice_cube/validations/month_of_year.rb
132
94
  - lib/ice_cube/validations/monthly_interval.rb
95
+ - lib/ice_cube/validations/override_duration.rb
133
96
  - lib/ice_cube/validations/schedule_lock.rb
134
97
  - lib/ice_cube/validations/second_of_minute.rb
135
98
  - lib/ice_cube/validations/secondly_interval.rb