【发布时间】:2019-10-31 20:46:03
【问题描述】:
我有一个模型商店的营业时间。开放时间表包含如下字段。我想查询开放和关闭时间如:08:00 - 17:00
t.time "closes"
视图助手如下:。其中 0 是星期天
我得到以下数组。
=> [Sat, 01 Jan 2000 08:00:00 UTC +00:00]
我想忽略日期部分,只显示小时和分钟。
感谢 tadman 和 Caleb,我们可以得到以下结果:
def display_day(value)
is_open = @company.opentimes.where(day: value, openpublic: true)
if is_open.pluck(:openpublic) == false
'closed'
else
start = is_open.pluck(:opens)
close = is_open.pluck(:closes)
if start.nil?
'no data'
else
DateTime.parse(start[0].to_s).strftime('%H.%M')
DateTime.parse(close[0].to_s).strftime('%H.%M')
end
end
end
我将清理代码并将其发布到那里。同时,如果您有任何建议,请随时提出建议。
【问题讨论】:
标签: sql ruby-on-rails ruby postgresql