艺赛旗(RPA)获取 T-n 工作日 日期解决方案
藝賽旗 RPA8.0全新首發免費下載 點擊下載
http://www.i-search.com.cn/index.html?from=line1
在金融行業中,經常會有關于工作日的需求,前一工作日啊,前兩工作日啊,當月的第幾個工作日啊之類的 ,這些日期怎么獲取呢,下面我分享一個解決方案
本地配置一張節假日的表格, 類似這種,把所有的雙休日和節日配置進去。通過讀取表格將節假日的日期全部讀進緩存,方便我們實現需求。
我們把 excel 存放在工程 code 目錄下(也可以自定義存放路徑)
coding=utf-8
import pandas as pd , sys
import ubpa.iexcel as iexcel
import ubpa.itools.rpa_time as rpa_time
#讀取整列 若excel不是存放在工程code目錄下 此處路徑自定義
holiday_list = iexcel.read_col(path=sys.path[0] + ‘\’ + ‘holiday.xlsx’,cell=‘B2’)
#傳入日期是否為工作日 入參日期樣式 2018-11-23
def is_innerdate_workdate(inner_date):
flag = False
tmp_date=inner_date.replace(’-’,’.’)
if tmp_date not in holiday_list:
flag = True
print(flag)
return flag
#獲取傳入日期的前一工作日 入參日期樣式 2018-11-23
def previous_one_workdate(inner_date):
tmp_date=inner_date.replace(’-’,’.’)
while True:
tmp_date = rpa_time.dete_dalta(days=-1,date=tmp_date,format=’%Y.%m.%d’,return_format=’%Y.%m.%d’)
if tmp_date in holiday_list:
pass
else:
break
previous_one=tmp_date.replace(’.’,’-’)
print(’%s 前一工作日: %s’%(inner_date,previous_one))
return previous_one
#獲取傳入日期的前兩工作日 入參日期樣式 2018-11-23
def previous_two_workdate(inner_date):
previous_one = previous_one_workdate(inner_date)
previous_two = previous_one_workdate(previous_one)
print(’%s 前兩工作日: %s’%(inner_date,previous_two))
return previous_two
#獲取當月的第n個工作日 入參規則 n>0
def get_currentmonth_Nworkdate(n):
tmp_month = rpa_time.get_current_datetime_str(format=’%Y.%m’)
#讀取整列 若excel不是存放在工程code目錄下 此處路徑自定義
df = pd.read_excel(sys.path[0] + ‘\’ + ‘holiday.xlsx’,header=None)
df = df[df[1].str.startswith(tmp_month)]
tmp_list = df[1].tolist()
tmp_date = tmp_month+ ‘.01’
i = 0
if tmp_date not in tmp_list:
i += 1
if i != n:
while True:
tmp_date = rpa_time.dete_dalta(days=1,date=tmp_date,format=’%Y.%m.%d’,return_format=’%Y.%m.%d’)
if tmp_date not in tmp_list:
i += 1
if i == n:
break
效果圖:
上傳我的工程 demo 包:workdate_demo.zip
總結
以上是生活随笔為你收集整理的艺赛旗(RPA)获取 T-n 工作日 日期解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 东南大学研究生毕业论文LaTeX模板se
- 下一篇: 职场 | 关于简历