Sha256: 719da47121ca79d26624e6bb0f499e9b41987e6c8f44877d6a6e14f1e2c60e9d
Contents?: true
Size: 1.01 KB
Versions: 4
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true module Darthjee module CoreExt module Date # Calculates the number of days between 2 dates # # @param [::Date,::Time] other_date future/past date for comparisom # @return [::Integer] days between two dates # # @example One year apart date # date = Date.new(2018, 11, 21) # other_date = Date.new(2019, 11, 21) # # date.days_between(other_date)) # returns 365 # # @example Four year apart date (having a leap year) # date = Date.new(2018, 11, 21) # other_date = Date.new(2014, 11, 21) # # date.days_between(other_date)) # returns 365 * 4 + 1 = 1461 # # @example Checking against time # date = Date.new(2018, 11, 21) # time = Time.new(2017, 11, 21, 12, 0, 0) # # date.days_between(time)) # returns 365 def days_between(other_date) (self - other_date.to_date).abs end end end end class Date include Darthjee::CoreExt::Date end
Version data entries
4 entries across 4 versions & 1 rubygems