📜 ⬆️ ⬇️

We work with bank (working) days

Six months ago, when developing a financial accounting system, the issue of identification of banking days was raised. It happened in the following context - when invoicing is given a certain period of time (in banking days) after which it is necessary to sound the alarm if the invoice has not yet been paid.

Armed with the labor code decided to find out what days can be considered operational for the bank. Article 112 reads:

Non-working holidays

Non-working holidays in the Russian Federation are:
January 1, 2, 3, 4 and 5 - New Year holidays;
January 7 - Christmas;
February 23 - Defender of the Fatherland Day;
March 8 - International Women's Day;
May 1 - Spring and Labor Day;
May 9 - Victory Day;
June 12 - Day of Russia;
November 4 - National Unity Day.
')
If the weekend and non-working holidays coincide, the day off is postponed to the next working day after the holiday.


Based on this information, a simple PHP class was written that allows you to:
  1. count the number of banking (working) days for a certain period of time
  2. calculate date + N banking days
  3. and, naturally, determine which day is a certain number.

Examples of using:
echo BankDay::getEndDate( '2008-10-14' , 10, 'dmY' );
//28.10.2008
echo BankDay::getEndDate( 'now' , 10);
//1229008080
echo BankDay::getNumDays( '2008-02-25' , '2008-03-15' );
//13
echo BankDay::getNumDays( 'now' , '10 days' );
//7
echo BankDay::isWorkDay( '2009-01-06' );
//false
* This source code was highlighted with Source Code Highlighter .




— «» = «» = «»
echo BankDay::getEndDate( '2008-10-14' , 10, 'dmY' );
//28.10.2008
echo BankDay::getEndDate( 'now' , 10);
//1229008080
echo BankDay::getNumDays( '2008-02-25' , '2008-03-15' );
//13
echo BankDay::getNumDays( 'now' , '10 days' );
//7
echo BankDay::isWorkDay( '2009-01-06' );
//false
* This source code was highlighted with Source Code Highlighter .




— «» = «» = «»
echo BankDay::getEndDate( '2008-10-14' , 10, 'dmY' );
//28.10.2008
echo BankDay::getEndDate( 'now' , 10);
//1229008080
echo BankDay::getNumDays( '2008-02-25' , '2008-03-15' );
//13
echo BankDay::getNumDays( 'now' , '10 days' );
//7
echo BankDay::isWorkDay( '2009-01-06' );
//false
* This source code was highlighted with Source Code Highlighter .




— «» = «» = «»

Source: https://habr.com/ru/post/67092/


All Articles