update valid time from menu

This commit is contained in:
Aung Myo
2018-01-09 16:00:24 +06:30
parent 6aab87a89d
commit 871683fdc0
2 changed files with 23 additions and 14 deletions

View File

@@ -37,6 +37,25 @@ class MenuCategory < ApplicationRecord
end
end
def valid_time
menu_category = MenuCategory.find(self.id)
menu = Menu.find(menu_category.menu_id)
from = menu.valid_time_from.strftime("%H:%m:%S")
to = menu.valid_time_to.strftime("%H:%m:%S")
current = Time.now.utc.getlocal.strftime("%H:%m:%S")
from = from.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
to = to.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
current = current.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
if current.between?(from, to)
return true
else
return nil
end
end
private
# def generate_menu_category_code