«
Rule languages supports between
range = between <between>
log = range.cover?(<compare>) ? "Within" : "Outside"
logger.info("#{log} time range")
between | compare | log | |
---|---|---|---|
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | Time.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | Time.now | Outside | |
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | TimeOfDay.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | TimeOfDay.now | Outside | |
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | '<%=(Time.now).strftime('%H:%M:%S')%>' | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | '<%=(Time.now).strftime('%H:%M:%S')%>' | Outside |
range = between <between>
log = range.include?(<compare>) ? "Within" : "Outside"
logger.info("#{log} time range")
between | compare | log | |
---|---|---|---|
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | Time.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | Time.now | Outside | |
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | TimeOfDay.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | TimeOfDay.now | Outside | |
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | '<%=(Time.now).strftime('%H:%M:%S')%>' | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | '<%=(Time.now).strftime('%H:%M:%S')%>' | Outside |
case <compare>
when between(<between>)
logger.info("Within time range")
else
logger.info("Not in time range")
end
between | compare | log | |
---|---|---|---|
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | Time.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | Time.now | Not in | |
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | TimeOfDay.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | TimeOfDay.now | Not in | |
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | '<%=(Time.now).strftime('%H:%M:%S')%>' | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | '<%=(Time.now).strftime('%H:%M:%S')%>' | Not in |
rule 'Testing Between Range' do
on_start
run do
range = between <between>
if range.cover? <compare>
logger.info("Within time range")
else
logger.info("Outside time range")
end
end
end
between | compare | log | |
---|---|---|---|
'<%=(Time.now - (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>' | Time.now | Within | |
'<%=(Time.now + (5*60)).strftime('%H:%M:%S')%>'..'<%=(Time.now + (10*60)).strftime('%H:%M:%S')%>' | Time.now | Outside |
require 'date'
range = between <between>
in_range = range.include?(<compare>)
logger.info("in range: #{in_range}")
between | compare | operation | result | |
---|---|---|---|---|
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Date.today | cover? | true | |
'<%=(Date.today + 10 ).strftime('%m-%d')%>'..'<%=(Date.today + 20).strftime('%m-%d')%>' | Date.today | cover? | false | |
'<%=(Date.today - 20 ).strftime('%m-%d')%>'..'<%=(Date.today - 10).strftime('%m-%d')%>' | Date.today | cover? | false | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Date.today | include? | true | |
'<%=(Date.today + 10 ).strftime('%m-%d')%>'..'<%=(Date.today + 20).strftime('%m-%d')%>' | Date.today | include? | false | |
'<%=(Date.today - 20 ).strftime('%m-%d')%>'..'<%=(Date.today - 10).strftime('%m-%d')%>' | Date.today | include? | false |
result = between(<range>).include? <type>.parse('<value>')
logger.info("between? #{result}")
type | value | range | result | |
---|---|---|---|---|
MonthDay | 02-03 | '01-25'..'02-05' | true | |
MonthDay | 11-25 | '01-25'..'02-05' | false |
require 'date'
range = between <between>
in_range = range.include?(<compare>)
logger.info("in range: #{in_range}")
between | compare | operation | result | |
---|---|---|---|---|
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Date.today | cover? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Time.now | cover? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | DateTime.now | cover? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | MonthDay.now | cover? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Date.today | include? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Time.now | include? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | DateTime.now | include? | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | MonthDay.now | include? | true |
require 'date'
require 'java'
java_import java.time.LocalDate
today = LocalDate.now
date_yesterday = today.minus_days(1)
date_tomorrow = today.plus_days(1)
yesterday = MonthDay.of(date_yesterday.month_value, date_yesterday.day_of_month)
tomorrow = MonthDay.of(date_tomorrow.month_value, date_tomorrow.day_of_month)
range = between <between>
in_range = range.include?(<compare>)
logger.info("in range: #{in_range}")
between | compare | result | |
---|---|---|---|
'<%=Date.today.prev_day.strftime('%m-%d')%>'..'<%=Date.today.next_day.strftime('%m-%d')%>' | Date.today | true | |
yesterday..tomorrow | Date.today | true | |
yesterday..'<%=Date.today.next_day.strftime('%m-%d')%>' | Date.today | true | |
'<%=Date.today.prev_day.strftime('%m-%d')%>'..tomorrow | Date.today | true |