G
G
getNullData2017-05-11 12:03:41
PHP
getNullData, 2017-05-11 12:03:41

Subtraction of periods, how to implement?

Good day!
I have a question and I don't know how to solve it.
Let's say we have three periods.

  1. from 2017-11-06 to 2017-11-20
  2. from 2017-11-10 to 2017-11-19 (status: false)
  3. from 2017-11-14 to 2017-11-25

How to subtract the period number 2 to get the output
  1. from 2017-11-06 to 2017-11-10
  2. from 2017-11-20 to 2017-11-25

I'm using a datetime object.
# Где 
$period->getDate()->getFirstDate() //2017-11-06T00:00:00
# и соответственно 
$period->getDate()->getLastDate() //2017-11-20T00:00:00
# если статус false, то его надо вычитать.
$period->getDate()->getStatus() //2017-11-20T00:00:00

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-05-11
@Rsa97

Subtraction (A - B) is reduced to four options:
1. A->firstDate >= B->firstDate && A->lastDate <= B->lastDate Period
A is completely removed.
2. A->firstDate > B->firstDate && A->lastDate > B->lastDate
A->firstDate := B->lastDate
3. A->firstDate < B->firstDate && A->lastDate < B->lastDate
A->lastDate := B-> firstBade
4. A->firstDate < B->firstDate && A->lastDate > B->lastDate
Period A is replaced by two new ones:
A1->firstDate := A->firstDate, A1->lastDate := B->firstDate
A2->firstDate := B->lastDate, A2->lastDate := A->lastDate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question