tandusrl / acts_as_bookable

A reservation plugin for Rails applications that allows resources to be bookable.
MIT License
140 stars 104 forks source link

Always unavailable_time with Rails 5 #16

Open giugrilli opened 7 years ago

giugrilli commented 7 years ago

Whether I use time fixed or range, it seems impossible to book anything, I followed the readme examples as strictly as possible. It always throws:

-> availability.unavailable_time

Books properly without time constraint. Any hint?

Chosko commented 7 years ago

Can you please provide your Gemfile.lock? And I also need the code you use for creating the Bookable and the Booker.

poidog223 commented 7 years ago

I'm having the same issue but am using rails 4.2.7

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.7)
      actionpack (= 4.2.7)
      actionview (= 4.2.7)
      activejob (= 4.2.7)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.7)
      actionview (= 4.2.7)
      activesupport (= 4.2.7)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.7)
      activesupport (= 4.2.7)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.7)
      activesupport (= 4.2.7)
      globalid (>= 0.3.0)
    activemodel (4.2.7)
      activesupport (= 4.2.7)
      builder (~> 3.1)
    activerecord (4.2.7)
      activemodel (= 4.2.7)
      activesupport (= 4.2.7)
      arel (~> 6.0)
    activesupport (4.2.7)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    acts_as_bookable (0.1.3)
      activerecord (>= 3.2, <= 5.0.0.1)
      ice_cube_chosko (~> 0.1.0)
    arel (6.0.4)
    bcrypt (3.1.11)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    builder (3.2.3)
    byebug (9.0.6)
    coffee-rails (4.1.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.1.x)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    concurrent-ruby (1.0.4)
    debug_inspector (0.0.2)
    devise (4.2.0)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0, < 5.1)
      responders
      warden (~> 1.2.3)
    erubis (2.7.0)
    execjs (2.7.0)
    globalid (0.3.7)
      activesupport (>= 4.1.0)
    i18n (0.7.0)
    ice_cube_chosko (0.1.0)
    jbuilder (2.6.1)
      activesupport (>= 3.0.0, < 5.1)
      multi_json (~> 1.2)
    jquery-rails (4.2.2)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    json (1.8.6)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.4)
      mime-types (>= 1.16, < 4)
    mime-types (3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0521)
    mini_portile2 (2.1.0)
    minitest (5.10.1)
    multi_json (1.12.1)
    nokogiri (1.7.0.1)
      mini_portile2 (~> 2.1.0)
    orm_adapter (0.5.0)
    rack (1.6.5)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.7)
      actionmailer (= 4.2.7)
      actionpack (= 4.2.7)
      actionview (= 4.2.7)
      activejob (= 4.2.7)
      activemodel (= 4.2.7)
      activerecord (= 4.2.7)
      activesupport (= 4.2.7)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.7)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.8)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    railties (4.2.7)
      actionpack (= 4.2.7)
      activesupport (= 4.2.7)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (12.0.0)
    rdoc (4.3.0)
    responders (2.3.0)
      railties (>= 4.2.0, < 5.1)
    sass (3.4.23)
    sass-rails (5.0.6)
      railties (>= 4.0.0, < 6)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sdoc (0.4.2)
      json (~> 1.7, >= 1.7.7)
      rdoc (~> 4.0)
    spring (2.0.1)
      activesupport (>= 4.2)
    sprockets (3.7.1)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.0)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.3.13)
    thor (0.19.4)
    thread_safe (0.3.5)
    tilt (2.0.6)
    turbolinks (5.0.1)
      turbolinks-source (~> 5)
    turbolinks-source (5.0.0)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (3.0.4)
      execjs (>= 0.3.0, < 3)
    warden (1.2.6)
      rack (>= 1.0)
    web-console (2.3.0)
      activemodel (>= 4.0)
      binding_of_caller (>= 0.7.2)
      railties (>= 4.0)
      sprockets-rails (>= 2.0, < 4.0)

PLATFORMS
  ruby

DEPENDENCIES
  acts_as_bookable
  byebug
  coffee-rails (~> 4.1.0)
  devise
  jbuilder (~> 2.0)
  jquery-rails
  rails (= 4.2.7)
  sass-rails (~> 5.0)
  sdoc (~> 0.4.0)
  spring
  sqlite3
  turbolinks
  uglifier (>= 1.3.0)
  web-console (~> 2.0)

BUNDLED WITH
   1.13.7
poidog223 commented 7 years ago

I used the readme instructions to create the Bookable and the Booker in the rails console.

@boat.schedule = IceCube::Schedule.new
# This show is available every day at 6PM and 10PM
@boat.schedule.add_recurrence_rule IceCube::Rule.daily.hour_of_day(18,22)
@boat.save!

Booking

time_ok = Date.today + 18.hours # Today at 6PM
time_wrong = Date.today + 19.hours # Today at 7PM
# Booking a model with `time_type: :fixed` requires a `:time` option
@user.book! @boat, time: time_ok # OK

This is the error being displayed

the Boat is not available at 2017-01-31 08:00:00 -1000

Chosko commented 7 years ago

hmm... that's weird... I need to debug it. It looks like the availability is checked at 8 AM instead of 6PM.

What's your timezone?

poidog223 commented 7 years ago

Yeah, I think it is probably due to a newer gem version? I'm on HST.

Let me know if you need me to push the repository up so you can take a look. Thanks!

lmle commented 7 years ago

@poidog223 Try using Time instead of Date (e.g. Time.new(2017,1,31,18)). I ran into this issue and found out it's because Date is using UTC, while IceCube uses your current time zone, so the times don't resolve correctly. Time fixed this issue because it uses your current time zone, same as IceCube.