module Attio::Concerns::TimeFilterable

def self.included(base)

def self.included(base)
  base.extend(ClassMethods)
end

def age_in_days

Returns:
  • (Integer) - Days since creation
def age_in_days
  return nil unless respond_to?(:created_at) && created_at
  created = created_at.is_a?(String) ? Time.parse(created_at) : created_at
  ((Time.now - created) / (24 * 60 * 60)).round
end

def created_in?(period)

Returns:
  • (Boolean) - True if created in the period

Parameters:
  • period (Util::TimePeriod) -- The time period
def created_in?(period)
  return false unless respond_to?(:created_at) && created_at
  date = created_at.is_a?(String) ? Time.parse(created_at) : created_at
  period.includes?(date)
end

def new?(days = 7)

Returns:
  • (Boolean) - True if created within specified days

Parameters:
  • days (Integer) -- Number of days to consider "new"
def new?(days = 7)
  age = age_in_days
  age && age <= days
end

def old?(days = 365)

Returns:
  • (Boolean) - True if created more than specified days ago

Parameters:
  • days (Integer) -- Number of days to consider "old"
def old?(days = 365)
  age = age_in_days
  age && age > days
end

def updated_in?(period)

Returns:
  • (Boolean) - True if updated in the period

Parameters:
  • period (Util::TimePeriod) -- The time period
def updated_in?(period)
  return false unless respond_to?(:updated_at) && updated_at
  date = updated_at.is_a?(String) ? Time.parse(updated_at) : updated_at
  period.includes?(date)
end