BUG: error calculating BusinessHourMixin.apply for long business hour per day
State: closed

- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew: handle the case where adding of business hour to the timestamp results in an ending time landing in the next business time period. Example

Input:
```python
bh = BusinessHour(n=4, start='00:00', end='23:00')
dt = datetime(2014, 7, 3, 22)
dt + bh
```
Expected:
```python
datetime(2014, 7, 4, 3)
```

Labels:
name: Bug
name: Datetime
description: Datetime data dtype

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=h1) Report
> Merging [#26381](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/304d8d4bc3b3cde7e2b463426bf484701df142cd?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26381/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26381      +/-   ##
==========================================
- Coverage   91.68%   91.67%   -0.01%     
==========================================
  Files         174      174              
  Lines       50704    50704              
==========================================
- Hits        46488    46485       -3     
- Misses       4216     4219       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.18% <100%> (ø)` | :arrow_up: |
| #single | `41.19% <0%> (-0.14%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.69% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.01% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.7% <0%> (+0.1%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=footer). Last update [304d8d4...fffac75](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=h1) Report
> Merging [#26381](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/304d8d4bc3b3cde7e2b463426bf484701df142cd?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26381/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26381      +/-   ##
==========================================
- Coverage   91.68%   91.68%   -0.01%     
==========================================
  Files         174      174              
  Lines       50704    50738      +34     
==========================================
+ Hits        46488    46518      +30     
- Misses       4216     4220       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.19% <100%> (ø)` | :arrow_up: |
| #single | `41.16% <0%> (-0.17%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.69% <100%> (-0.01%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `93.54% <0%> (-0.4%)` | :arrow_down: |
| [pandas/plotting/\_style.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19zdHlsZS5weQ==) | `76.92% <0%> (-0.26%)` | :arrow_down: |
| [pandas/plotting/\_misc.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19taXNjLnB5) | `38.23% <0%> (-0.23%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.02% <0%> (-0.12%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.66% <0%> (-0.06%)` | :arrow_down: |
| [pandas/core/groupby/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9nZW5lcmljLnB5) | `88.96% <0%> (-0.05%)` | :arrow_down: |
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `96.65% <0%> (-0.02%)` | :arrow_down: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.89% <0%> (-0.02%)` | :arrow_down: |
| ... and [9 more](https://codecov.io/gh/pandas-dev/pandas/pull/26381/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=footer). Last update [304d8d4...61079a7](https://codecov.io/gh/pandas-dev/pandas/pull/26381?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jiangyue12392 : Thanks for submitting this!  For those tests cases that you've added, what happens currently without your fixes?
@gfyoung The current code without fixes would return a wrong value if the adding of business hour to the timestamp results in an ending time landing in the next business time period. For example, if the working hour is 00:00 to 23:00 and 4 business hours are added at 22:00, the current code would return 02:00 in the next day instead of 03:00 the next business day.
@jiangyue12392 : I see.  For clarify, could you show the output of those examples, using a format like this (we use this format for our issue tracker):

# Example
~~~python
print("Hello World")
~~~

This outputs:

~~~
Hello World
~~~
@gfyoung Example inputs and outputs:
Input:
```python
bh = BusinessHour(n=4, start='00:00', end='23:00')
dt = datetime(2014, 7, 3, 22)
dt + bh
```
Expected:
```python
datetime(2014, 7, 4, 3)
```
Current Output:
```python
datetime(2014, 7, 4, 2)
```
Got it.  Can you add a `whatsnew` entry as well?
@gfyoung `whatsnew` entry added
@jiangyue12392 : A `whatsnew` entry means adding a bullet point to this file:

https://github.com/pandas-dev/pandas/blob/master/doc/source/whatsnew/v0.25.0.rst

I recommend adding it under the `Timedelta` section.
@gfyoung new entry added
looks fine, ex- @mroeschke comment on the whatsnew.
lgtm. ping on green.
@jreback 
Thanks @jiangyue12392, nice work!