Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 Help Me ! » How can I extract integers from an integer series ? » 2013-07-18 21:17:31

merianos
Replies: 1

Hello.

I am creating an application, that will allow me to rent a service, based on time. The basic issue is that I apply double charge for pre-defined periods of the day, but this period it is not the same for all of my products.

First I will try to give you the problem in real terms

So, let's say I am renting printers and I have the following two printers:

1) Dot matrix printer
    The dot matrix printer it costs $1 per hour but it costs $2 per hour between 11:00 and 15:00
2) Laser printer
    The laser printer it costs $4 per hour but it costs $8 per hour between 20:00 and 01:00 the morning.

Now lets say I have two clients, that are interested for the dot matrix printer. The first client is interested to rent the printer from 08:00 until 09:30 the morning, and the second one is interested to rent the printer from 13:00 until 16:00. Thus, the first client will be charged with $1.50 because his is renting the printer in single charge period, and the second client must be charged with $5 because he is renting the printer for two hours in the double charge range period and one hour in single charge period.

Also I have a client that he is interested for the laser printer and he is rent it from 18:00 until the 20:30, so the charge is $12,00 because he has rent the printer for two hours in the single range period and for a half hour in the double charge period.

Now lets see methimatics

In programming language I am using (PHP), each second has it's own time stamp that it is the total seconds passed from 01/01/1970 until the checked second. So each date/time I check it has it's own timestamp.

Based on the above example.

Lets say today is

07/19/2013


The first client comes to get the printer at 07/19/2013 08:00 and he will return the printer at 07/19/2013 09:30. The timestamps for these dates/times are the following:

Rent start : 1374220800
Rent end  : 1374226200

The double charge period for the selected date starts at 07/19/2013 11:00 and it is end at 07/19/2013 15:00. The timestamps for these dates/times are the following:

Double charge starts : 1374231600
Double charge ends  : 1374246000

Also the current day starts at 07/19/2013 00:00 and it is ends at 07/19/2013 23:59. The timestamps for these dates/times are the following:

Day start : 1374192000
Day ends : 1374278340

Based on the above numbers we have a number range that looks like that:

[Day start : 1374192000] [Rent start : 1374220800] [Rend end : 1374226200] [Double charge start : 1374231600] [Double charge ends : 1374246000] [Day ends : 1374278340]



The second client comes to get the printer at 07/19/2013 13:00 and he will return the printer at 07/19/2013 16:00. The timestamps for these dates/times are the following:

Rent start : 1374238800
Rent end  :  1374249600

The double charge period for the selected date starts at 07/19/2013 11:00 and it is end at 07/19/2013 15:00. The timestamps for these dates/times are the following:

Double charge starts : 1374231600
Double charge ends  : 1374246000

Also the current day starts at 07/19/2013 00:00 and it is ends at 07/19/2013 23:59. The timestamps for these dates/times are the following:

Day start : 1374192000
Day ends : 1374278340

Based on the above numbers we have a number range that looks like that:

[Day start : 1374192000] [Double charge start : 1374231600] [Rent start : 1374238800] [Double charge ends : 1374246000] [Rend end : 1374226200] [Day ends : 1374278340]



Finally, we have the third client that he is interested on Laser printer. So the third client comes to rent the printer at 07/19/2013 18:00 and he will return the printer at 07/19/2013 20:30. The timestamps are the following:

Rent start : 1374256800
Rent end  : 1374265800

In this case the double charge starts today, but stops tomorrow !!. So the double charge period starts at 07/19/2013 20:00 and it is ends at 07/20/2013 01:00. The time stamps for these dates/times are the following:

Double charge starts : 1374264000
Double charge ends  : 1374282000

and the days start / ends are changing acordingly. So the start date is the 07/19/2013 00:00 and the end date is the 07/20/2013 23:59. So the timestamps are the following:

Day start : 1374192000
Day ends : 1374364740

Based on the above numbers we have a number range that looks like that:

[Day start : 1374192000] [Rent start : 1374256800] [Double charge start : 1374264000] [Rend end : 1374265800] [Double charge ends : 1374282000] [Day ends : 1374364740]


The question now

How can I exctract the seconds that involved in the double charge periods ? What is the best formula can be used in order to extract the time duration of the single and double charges ?


Finally, I have create an image the represents this problem in a time period range:

KtV1W.jpg

Board footer

Powered by FluxBB