cartodb/app/models/carto/helpers/billing_cycle.rb
2020-06-15 10:58:47 +08:00

28 lines
613 B
Ruby

require 'active_support/time'
module Carto
module BillingCycle
def last_billing_cycle
day = period_end_date.day
date = day > Date.today.day ? (Date.today - 1.month) : Date.today
begin
Date.new(date.year, date.month, day)
rescue ArgumentError
day = day - 1
retry
end
end
def next_billing_cycle
day = period_end_date.day
date = day > Date.today.day ? Date.today : Date.today + 1.month
begin
Date.new(date.year, date.month, day)
rescue ArgumentError
day = day - 1
retry
end
end
end
end