I am in need of an equation to solve the following problem: I run an
auction website. We offer the ability for a user to "feature" their
auction on our homepage. They can feature their auction at any point
during the auction, and are charged based on how many days are
remaining in their auction. I need an equation that calculates how
many days we can feature their auction.
Consider the following variables:
auctionDuration - the total length of the auction
auctionStartDate - the date the auction started
featuredAuctionDuration - number of days this auction has already been featured
I can also calculate:
auctionEndDate - The date this auction will end
daysRun - the number of days this auction has already run
daysRemaining - the number of days until the auction closes
For example if:
auctionDuration = 14
auctionStart = 1/1/2005
featuredAuctionDuration = 0
This is an auction started on the 1st of Jan. It has not been featured yet.
auctionDuration - daysRun = featurableDays
If today is 1/3, this equation should return 12 (number of days
between 1/3 and 1/14).
But, consider this scenario:
auctionDuration = 14
auctionStartDate = 1/1/2005
featuredAuctionDuration = 5
This auction has already been given a featured status for 5 days (it
will be featured from 1/1 - 1/5). The equation needs to account for
this and not include those days in the calculation. If today is 1/3,
then it must return 9 (the number of days between 1/6 and 1/14).
Does anyone want to take a crack at this? Please let me know if you
need clarification. |
Request for Question Clarification by
hammer-ga
on
23 Jan 2005 08:20 PST
I think we're missing a piece. The missing piece would be the
featuredStartDate for auctions where featuredAuctionDuration > 0.
In your example, just because the auction has a
featuredAuctionDuration of 5, does that automatically mean that the
first featured day was the same as the auction start date? Or might
the person have requested 5 featured days on 1/3, meaning that the
remaining days would be 7 (1/8 - 1/14)?
How would you want to handle the above situation? Or am I
misunderstanding the example?
- Hammer
|
Request for Question Clarification by
hammer-ga
on
23 Jan 2005 08:22 PST
Also, is there a particular programming language in which you need this solution?
- Hammer
|
Clarification of Question by
jebsilver-ga
on
23 Jan 2005 08:41 PST
The user cannot choose the start day of the featured status. So we
would apply this status to the first available day of the auction. On
a new auction, this would be auctionStart. On an auction that has
already been featured for x days, the featuring would start at x+1,
assuming featuredAuctionDuration < auctionDuration. If
featuredAuctionDuration = auctionDuration, the equation should return
0.
I am writing this in ColdFusion, but I can translate from psuedo code
using the variable syntax I provided.
Thanks.
|
Request for Question Clarification by
elmarto-ga
on
23 Jan 2005 13:41 PST
Hi jebsilver!
Is it possible that this is the equation that you're looking for?
if featuredAuctionDuration <= daysRun then
featurableDays = daysRemaining
if featuredAuctionDuration > daysRun then
featurableDays = auctionDuration - featuredAuctionDuration
This equation fits the examples you gave, and I think it solves your
problem. Please let me know if you feel there's something missing in
this code or if you would accept this as an answer.
Best wishes,
elmarto
|
Request for Question Clarification by
efn-ga
on
23 Jan 2005 14:06 PST
It's clear that an auction has a known start date, end date, and duration.
The goal is to calculate the number of featureable days as of the current date.
It appears that when the calculation is needed, an auction may already
have a limited featured period that terminates in the past, on the
current day, or in the future. Is this correct?
Assuming that it is, then I would guess that the number of featureable
days is the number of days from x to the end of the auction, where x
is the later of the current day and the end of the existing featured
period. In other words, if there is an existing featured period that
ends in the future, the featureable days are those between the end of
the existing featured period and the end of the auction, and if there
is not an existing featured period that ends in the future, the
featureable days are those from the current day to the end of the
auction. Is that right?
If both of these assumptions are correct, then hammer was correct that
there is data missing. To calculate the number of featureable days,
you need to know when an existing featured period ends. All that you
specified was available about this is the featuredAuctionDuration.
You can't get the end date from the featuredAuctionDuration without
knowing when the existing featured period starts. You could get it if
you stipulate that an existing featured period always starts at the
beginning of the auction. This would only make sense if an existing
featured period is different from the kind of featuring a customer can
order, because you have said that the featured period a customer can
order can start after the start of the auction. Is this the case?
Does an existing featured period always start at the beginning of an
auction?
If the answer to this last question is also yes, then I think elmarto
has given you a simple and correct solution.
|
Clarification of Question by
jebsilver-ga
on
23 Jan 2005 19:21 PST
I believe elmarto's solution is perfect, and is working well in tests.
I think it needs to be submitted as an answer so I can accept it.
|