easiest way to set future date

E

enspired

I need to calculate an end date based on a start date (Date.today + #
of trial days). Basically, the app allows different services to be
purchased for different durations. So one service might be a year while
another might be 6 months. What's the best way to accomplish this,
keeping in mind that service durations could be configured in days,
months or years (although I could just make it months if adhering to
YAGNI)?

def before_create
# set service_start_date/service_end_date based on service_level
trial_days = self.service_level.trial_days || 0
start_date = Date.today + (trial_days * (24 * 60 * 60))
duration = self.service_level.duration # number of units * frequency
frequency = self.service_level.frequency # can be 'D', 'M', 'Y'

# determine end_date
#end_date = start_date (???)

self.service_start_date = start_date
self.service_end_date = end_date
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top