Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby if dates is in range

d1      = DateTime.parse('2018/04/01')
  d2      = DateTime.parse('2018/04/29')
  outside = DateTime.parse('2018/04/30')
  inside  = DateTime.parse('2018/04/15')

  # include?
  (d1...d2).include?(d1)      # true
  (d1...d2).include?(d2)      # false
  (d1...d2).include?(outside) # false
  (d1...d2).include?(inside)  # true

  (d1..d2).include?(d1)      # true
  (d1..d2).include?(d2)      # true
  (d1..d2).include?(outside) # false
  (d1..d2).include?(inside)  # true

  # ===
  (d1...d2) === d1      # true
  (d1...d2) === d2      # false
  (d1...d2) === outside # false
  (d1...d2) === inside  # true

  (d1..d2) === d1      # true
  (d1..d2) === d2      # true
  (d1..d2) === outside # false
  (d1..d2) === inside  # true

  # cover?
  (d1...d2).cover?(d1)      # true
  (d1...d2).cover?(d2)      # false
  (d1...d2).cover?(outside) # false
  (d1...d2).cover?(inside)  # true

  (d1..d2).cover?(d1)      # true
  (d1..d2).cover?(d2)      # true
  (d1..d2).cover?(outside) # false
  (d1..d2).cover?(inside)  # true

  # between?
  d1.between?(d1, d2)       # true
  d2.between?(d1, d2)       # true
  outside.between?(d1, d2)  # false
  inside.between?(d1, d2)   # true
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails video_tag with <source 
Ruby :: PG::DatatypeMismatch: ERROR: column "price" cannot be cast automatically to type numeric HINT: You might need t 
Ruby :: ruby intersection of two arrays 
Ruby :: ruby capitalize first character of sentence 
Ruby :: unix timestamp to date time rails 
Ruby :: comment in ruby 
Ruby :: add key and value to hash ruby 
Ruby :: rails strftime 
Ruby :: rails remove column 
Ruby :: ruby raise argumenterror 
Ruby :: button submit rails with font awesome 
Ruby :: rails array sort 
Ruby :: convert to ascii ruby 
Ruby :: ruby change directory 
Ruby :: rails send email from console 
Ruby :: ruby while loops 
Ruby :: timeout in rails 
Ruby :: how to reset migrations rails 
Ruby :: jupyter notebook ruby 
Ruby :: ruby array split into groups 
Ruby :: ruby begin rescue ensure 
Ruby :: ruby array last 
Ruby :: get single hash key ruby 
Ruby :: logstasher-logger gem 
Ruby :: ruby heredoc 
Ruby :: Replacing consecutive numbers with dash between first and last in a range 
Ruby :: pick element from space separated list that is part of params hash 
Ruby :: array sort_by nil ruby 
Ruby :: allow raise inside rescue rspec 
R :: r list files in directory 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =