Skip to content

Commit

Permalink
Merge branch 'master' into add-missing-expect
Browse files Browse the repository at this point in the history
  • Loading branch information
pacso authored Jul 18, 2024
2 parents 5e79034 + 6b999d7 commit 45c7d2b
Show file tree
Hide file tree
Showing 38 changed files with 253 additions and 103 deletions.
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
{
"name": "IceCube",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",

// Configure tool-specific properties.
"customizations" : {
"jetbrains" : {
"backend" : "RubyMine"
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
23 changes: 7 additions & 16 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- id: read-version
run: |
echo "::set-output name=VERSION::`cat lib/ice_cube/version.rb | grep -i version | awk '{ print $3 }' | sed -e 's/\"//g'`"
- uses: dangoslen/changelog-enforcer@v2.3.1
- uses: dangoslen/changelog-enforcer@v3
with:
skipLabels: 'skip-changelog'
expectedLatestVersion: ${{ steps.read-version.outputs.VERSION }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
ruby-version: '3.1'
bundler-cache: true
- run: bundle exec standardrb
test:
Expand All @@ -42,22 +42,13 @@ jobs:
- lint
strategy:
matrix:
rails: ['5.2', '6.0.4', '6.1', '7.0']
ruby: ['2.6', '2.7', '3.0', '3.1']
exclude:
- rails: '5.2'
ruby: '3.0'
- rails: '5.2'
ruby: '3.1'
- rails: '7.0'
ruby: '2.6'
- rails: '7.0'
ruby: '2.7'
rails: ['6.1', '7.0', '7.1']
ruby: ['3.1', '3.2', '3.3']
runs-on: ubuntu-latest
env:
RAILS_VERSION: ${{ matrix.rails }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Removed use of `delegate` method added in [66f1d797](https://github.com/ice-cube-ruby/ice_cube/commit/66f1d797092734563bfabd2132c024c7d087f683) , reverting to previous implementation. ([#522](https://github.com/ice-cube-ruby/ice_cube/pull/522)) by [@pacso](https://github.com/pacso)
- Updated supported versions of Ruby and Rails and fixed standardrb lint issues. ([#552](https://github.com/ice-cube-ruby/ice_cube/pull/552)) by [@pacso](https://github.com/pacso)
- Fixed `I18n.load_path` injection ([#546](https://github.com/ice-cube-ruby/ice_cube/pull/546)) by [@glaszig](https://github.com/glaszig)

### Fixed
- Fix for weekly interval results when requesting `occurrences_between` on a narrow range ([#487](https://github.com/seejohnrun/ice_cube/pull/487)) by [@jakebrady5](https://github.com/jakebrady5)
- When using a rule with hour_of_day validations, and asking for occurrences on the day that DST skips forward, valid occurrences would be missed. ([#464](https://github.com/seejohnrun/ice_cube/pull/464)) by [@jakebrady5](https://github.com/jakebrady5)
- Include `exrules` when exporting a schedule to YAML, JSON or a Hash. ([#519](https://github.com/ice-cube-ruby/ice_cube/pull/519)) by [@pacso](https://github.com/pacso)
- Documentation links updated to point to the new repository location. ([#553](https://github.com/ice-cube-ruby/ice_cube/pull/553)) by [@pacso](https://github.com/pacso)
- Input validation added for day_of_week validator. Fixes infinite loops when invalid day_of_week occurrences are provided. ([#554](https://github.com/ice-cube-ruby/ice_cube/pull/554)) by [@pacso](https://github.com/pacso)

## [0.16.4] - 2021-10-21
### Added
Expand Down
7 changes: 3 additions & 4 deletions ice_cube.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ Gem::Specification.new do |s|
s.description = "ice_cube is a recurring date library for Ruby. It allows for quick, programatic expansion of recurring date rules."
s.author = "John Crepezzi"
s.email = "[email protected]"
s.homepage = "https://seejohnrun.github.io/ice_cube/"
s.homepage = "https://ice-cube-ruby.github.io/ice_cube/"
s.license = "MIT"

s.metadata["changelog_uri"] = "https://github.com/seejohnrun/ice_cube/blob/master/CHANGELOG.md"
s.metadata["wiki_uri"] = "https://github.com/seejohnrun/ice_cube/wiki"
s.metadata["changelog_uri"] = "https://github.com/ice-cube-ruby/ice_cube/blob/master/CHANGELOG.md"
s.metadata["wiki_uri"] = "https://github.com/ice-cube-ruby/ice_cube/wiki"

s.version = IceCube::VERSION
s.platform = Gem::Platform::RUBY
s.files = Dir["lib/**/*.rb", "config/**/*.yml"]
s.test_files = Dir.glob("spec/*.rb")
s.require_paths = ["lib"]

s.add_development_dependency("rake")
Expand Down
3 changes: 2 additions & 1 deletion lib/ice_cube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module IceCube

autoload :TimeUtil, "ice_cube/time_util"
autoload :FlexibleHash, "ice_cube/flexible_hash"
autoload :I18n, "ice_cube/i18n"

require "ice_cube/i18n"

autoload :Rule, "ice_cube/rule"
autoload :Schedule, "ice_cube/schedule"
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/builders/string_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def ordinal(number)
ord = IceCube::I18n.t("ice_cube.integer.ordinals")[number] ||
IceCube::I18n.t("ice_cube.integer.ordinals")[number % 10] ||
IceCube::I18n.t("ice_cube.integer.ordinals")[:default]
number >= 0 ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
(number >= 0) ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/flexible_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def delete(key)

def _match_key(key)
return key if __getobj__.has_key? key
if Symbol == key.class
if key.instance_of?(Symbol)
__getobj__.keys.detect { |k| return k if k == key.to_s }
elsif String == key.class
elsif key.instance_of?(String)
__getobj__.keys.detect { |k| return k if k.to_s == key }
end
key
Expand Down
31 changes: 10 additions & 21 deletions lib/ice_cube/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
require "ice_cube/null_i18n"

module IceCube
module I18n
LOCALES_PATH = File.expand_path(File.join("..", "..", "..", "config", "locales"), __FILE__)

def self.t(*args, **kwargs)
backend.t(*args, **kwargs)
end

def self.l(*args, **kwargs)
backend.l(*args, **kwargs)
end

def self.backend
@backend ||= detect_backend!
end

def self.detect_backend!
::I18n.load_path += Dir[File.join(LOCALES_PATH, "*.yml")]
::I18n
rescue NameError
NullI18n
end
LOCALES_PATH = File.expand_path(File.join("..", "..", "config", "locales"), __dir__)

# rubocop:disable Naming/ConstantName
I18n = begin
require "i18n"
::I18n.load_path += Dir[File.join(LOCALES_PATH, "*.yml")]
::I18n
rescue LoadError
NullI18n
end
# rubocop:enable Naming/ConstantName
end
12 changes: 6 additions & 6 deletions lib/ice_cube/input_alignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def initialize(rule, value, rule_part)

attr_reader :rule, :value, :rule_part

def verify(freq, options = {}, &block)
def verify(freq, options = {}, &)
@rule.validations[:interval] or return

case @rule
when DailyRule
verify_wday_alignment(freq, &block)
verify_wday_alignment(freq, &)
when MonthlyRule
verify_month_alignment(freq, &block)
verify_month_alignment(freq, &)
else
verify_freq_alignment(freq, &block)
verify_freq_alignment(freq, &)
end
end

Expand All @@ -28,12 +28,12 @@ def interval_validation
end

def interval_value
@interval_value ||= rule_part == :interval ? value : interval_validation.interval
@interval_value ||= (rule_part == :interval) ? value : interval_validation.interval
end

def fixed_validations
@fixed_validations ||= @rule.validations.values.flatten.select { |v|
interval_type = (v.type == :wday ? :day : v.type)
interval_type = ((v.type == :wday) ? :day : v.type)
v.class < Validations::FixedValue &&
interval_type == rule.base_interval_validation.type
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/null_i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module NullI18n
def self.t(key, options = {})
base = key.to_s.split(".").reduce(config) { |hash, current_key| hash[current_key] }

base = base[options[:count] == 1 ? "one" : "other"] if options[:count]
base = base[(options[:count] == 1) ? "one" : "other"] if options[:count]

case base
when Hash
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/occurrence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def to_s(format = nil)
else
t0, t1 = start_time.to_s, end_time.to_s
end
duration > 0 ? "#{t0} - #{t1}" : t0
(duration > 0) ? "#{t0} - #{t1}" : t0
end

def overnight?
Expand Down
5 changes: 1 addition & 4 deletions lib/ice_cube/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def from_hash(original_hash)

rule = IceCube::Rule.send(interval_type, hash[:interval] || 1)

if match[1] == "Weekly"
rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0))
end

rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) if rule.is_a? WeeklyRule
rule.until(TimeUtil.deserialize_time(hash[:until])) if hash[:until]
rule.count(hash[:count]) if hash[:count]

Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/rules/weekly_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def realign(step_time, start_time)
time = TimeUtil::TimeWrapper.new(start_time)
offset = wday_offset(step_time, start_time)
time.add(:day, offset)
super step_time, time.to_time
super(step_time, time.to_time)
end

# Calculate how many days to the first wday validation in the correct
Expand Down
6 changes: 3 additions & 3 deletions lib/ice_cube/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def all_occurrences_enumerator
end

# Iterate forever
def each_occurrence(&block)
enumerate_occurrences(start_time, &block).to_a
def each_occurrence(&)
enumerate_occurrences(start_time, &).to_a
self
end

Expand Down Expand Up @@ -191,7 +191,7 @@ def previous_occurrences(num, from)
from = TimeUtil.match_zone(from, start_time) or raise ArgumentError, "Time required, got #{from.inspect}"
return [] if from <= start_time
a = enumerate_occurrences(start_time, from - 1).to_a
a.size > num ? a[-1 * num, a.size] : a
(a.size > num) ? a[-1 * num, a.size] : a
end

# The remaining occurrences (same requirements as all_occurrences)
Expand Down
22 changes: 11 additions & 11 deletions lib/ice_cube/time_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.match_zone(input_time, reference)
else
time.getlocal(reference.utc_offset)
end
Date === input_time ? beginning_of_date(time, reference) : time
(Date === input_time) ? beginning_of_date(time, reference) : time
end

# Ensure that this is either nil, or a time
Expand Down Expand Up @@ -286,12 +286,12 @@ def to_time
def add(type, val)
type = :day if type == :wday
@time += case type
when :year then TimeUtil.days_in_n_years(@time, val) * ONE_DAY
when :month then TimeUtil.days_in_n_months(@time, val) * ONE_DAY
when :day then val * ONE_DAY
when :hour then val * ONE_HOUR
when :min then val * ONE_MINUTE
when :sec then val
when :year then TimeUtil.days_in_n_years(@time, val) * ONE_DAY
when :month then TimeUtil.days_in_n_months(@time, val) * ONE_DAY
when :day then val * ONE_DAY
when :hour then val * ONE_HOUR
when :min then val * ONE_MINUTE
when :sec then val
end
end

Expand All @@ -318,20 +318,20 @@ def sec=(value)
end

def clear_sec
@time.sec > 0 ? @time -= @time.sec : @time
(@time.sec > 0) ? @time -= @time.sec : @time
end

def clear_min
@time.min > 0 ? @time -= (@time.min * ONE_MINUTE) : @time
(@time.min > 0) ? @time -= (@time.min * ONE_MINUTE) : @time
end

def clear_hour
@time.hour > 0 ? @time -= (@time.hour * ONE_HOUR) : @time
(@time.hour > 0) ? @time -= (@time.hour * ONE_HOUR) : @time
end

# Move to the first of the month, 0 hours
def clear_day
@time.day > 1 ? @time -= (@time.day - 1) * ONE_DAY : @time
(@time.day > 1) ? @time -= (@time.day - 1) * ONE_DAY : @time
end

# Clear to january 1st
Expand Down
7 changes: 5 additions & 2 deletions lib/ice_cube/validations/day_of_week.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Validation
attr_reader :day, :occ

def initialize(day, occ)
raise ArgumentError, "Integer occurrence value required" unless occ.is_a?(Integer)
raise ArgumentError, "Invalid day_of_week occurrence: #{occ.inspect}" if occ.zero? || occ.abs > 5

@day = day
@occ = occ
end
Expand All @@ -29,12 +32,12 @@ def dst_adjust?

def validate(step_time, start_time)
wday = step_time.wday
offset = day < wday ? (7 - wday + day) : (day - wday)
offset = (day < wday) ? (7 - wday + day) : (day - wday)
wrapper = TimeUtil::TimeWrapper.new(step_time)
wrapper.add :day, offset
loop do
which_occ, num_occ = TimeUtil.which_occurrence_in_month(wrapper.to_time, day)
this_occ = occ < 0 ? (num_occ + occ + 1) : occ
this_occ = (occ < 0) ? (num_occ + occ + 1) : occ
break offset if which_occ == this_occ
wrapper.add :day, 7
offset += 7
Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/validations/day_of_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def dst_adjust?

def validate(step_time, start_time)
days_in_year = TimeUtil.days_in_year(step_time)
yday = day < 0 ? day + days_in_year + 1 : day
yday = (day < 0) ? day + days_in_year + 1 : day
offset = yday - step_time.yday
offset >= 0 ? offset : offset + days_in_year
(offset >= 0) ? offset : offset + days_in_year
end

def build_s(builder)
Expand Down
8 changes: 4 additions & 4 deletions lib/ice_cube/validations/fixed_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def validate(time, start_time)
def validate_interval_lock(time, start_time)
t0 = starting_unit(start_time)
t1 = time.send(type)
t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
(t0 >= t1) ? t0 - t1 : INTERVALS[type] - t1 + t0
end

# Lock the hour if explicitly set by hour_of_day, but allow for the nearest
Expand Down Expand Up @@ -73,16 +73,16 @@ def validate_day_lock(time, start_time)
if value && value > 0
until_next_month = days_in_month + sleeps
else
until_next_month = start < 28 ? days_in_month : TimeUtil.days_to_next_month(date)
until_next_month = (start < 28) ? days_in_month : TimeUtil.days_to_next_month(date)
until_next_month += sleeps - month_overflow
end

sleeps >= 0 ? sleeps : until_next_month
(sleeps >= 0) ? sleeps : until_next_month
end

def starting_unit(start_time)
start = value || start_time.send(type)
start = start % INTERVALS[type] if start < 0
start %= INTERVALS[type] if start < 0
start
end
end
Expand Down
Loading

0 comments on commit 45c7d2b

Please sign in to comment.