Sử dụng CustomBusinessHour.rollforward() để tiến timestamp đến offset hợp lệ tiếp theo (nếu timestamp không nằm trên offset).
Ví dụ
import pandas as pd
timestamp = pd.Timestamp('2021-12-20 08:35:10')
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n=5, weekmask='Mon Tue Wed Fri')
print("Timestamp:", timestamp)
print("CustomBusinessHour Offset:", cbhOffset)
print("Updated Timestamp:", timestamp + cbhOffset)
roll = cbhOffset.rollforward(pd.Timestamp('2021-12-30 08:35:10'))
print("Rollforward result:", roll)
Kết quả
Timestamp: 2021-12-20 08:35:10 CustomBusinessHour Offset: <5 * CustomBusinessHours: CBH=09:00-17:00> Updated Timestamp: 2021-12-20 14:00:00 Rollforward result: 2021-12-31 09:00:00