Git Product home page Git Product logo

Comments (1)

craiglittle avatar craiglittle commented on June 14, 2024

Hey there, @bbbneo333! Thanks for using the gem and for reaching out with your question.

The issue with creating a intersected schedule with an empty set of hours versus failing hard with an exception is that an empty schedule would be functionally pointless in every scenario where it is to be used: Time calculations would always return zero, selecting a group of periods would always return an empty set, and determining whether a time was in business hours would always return false.

Now, we could implement a null object pattern within the gem for this case, but I don't know if it's worth the overhead of maintenance given the niche applicability.

With that said, here are a couple suggested approaches for your use case:

# exception handling

def schedules_intersect?(schedule1, schedule2)
  (schedule1 & schedule2).intervals.any?
rescue Biz::Error::Configuration => error
  error.message == 'hours not provided' ? false : raise
end

schedules_intersect?(s1, s2)

# null-object pattern

class NullSchedule
  def intervals
    []
  end
end

def intersected_schedule(schedule1, schedule2)
  schedule1 & schedule2
rescue Biz::Error::Configuration => error
  error.message == 'hours not provided' ? NullSchedule.new : raise
end

intersected_schedule(s1, s2).intervals.any?

I'm going to close this issue for now as I don't think there's anything actionable, but please do let me know how you addressed your issue and/or if the above suggestions were helpful.

from biz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.