日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python增加工作日列_将工作日添加到日期字段

發布時間:2025/3/12 python 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python增加工作日列_将工作日添加到日期字段 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖在Django的日期字段中添加一些工作日。這是針對產品訂購,我們對不同的產品有不同的交付周期,我們希望為每個產品生成一個目標日期。在

例如,產品X可能需要10個工作日才能交付,如果此產品是在2013年3月1日星期五訂購的,則目標日期應為2013年3月15日星期五(不包括作為一天的訂購日期)。在

我環顧了一下,似乎有一些python庫可以完成這類工作,但似乎都過于復雜了。我認為有一個相當簡單的方法可以做到這一點。在

**編輯**

我現在使用的是BusinessHours PyPi包,但是似乎遇到了一些問題。在

他們給了你一個如何調用包的例子。在eg: Class: BusinessHours(datetime1,datetime2,worktiming=[9 ,18],weekends=[6,7],holidayfile=None)

Class Parameters:

datetime1 - The datetime object with the starting date.

datetime2 - The datetime object with the ending date.

worktiming - The working office hours . A list containing two values start time and end time

weekends - The days in a week which have to be considered as weekends sent as a list, 1 for monday ... 7 for sunday.

holidayfile - A file consisting of the predetermined office holidays.Each date starts in a new line and currently must only be in the format dd-mm-yyyy

from BusinessHours import BusinessHours

from datetime import datetime

testing = BusinessHours(datetime(2007,10,15),datetime.now())

print testing.getdays()

利用這些信息,我做了下面的測試腳本

^{pr2}$

我的假期文件包含以下內容(2月的一個隨機工作日)07-02-2013

當我運行腳本時,我得到以下錯誤。在Traceback (most recent call last):

File "business_days", line 9, in ?

print testing.getdays()

File "/usr/lib/python2.4/site-packages/BusinessHours.py", line 63, in getdays

holidate = date(int(year) , int(month) , int(day))

NameError: global name 'date' is not defined

這是包中的代碼部分。在60 for definedholiday in definedholidays:

61 flag=0;

62 day , month , year = definedholiday.split('-')

63 holidate = date(int(year) , int(month) , int(day))

64 for weekend in self.weekends:

65 #check if mentioned holiday lies in defined weekend , shouldnt deduct twice

66 if(holidate.isoweekday==weekend):

67 flag=1;

68 break;

感謝任何人給我的幫助,我的Python版本是2.4.3

總結

以上是生活随笔為你收集整理的python增加工作日列_将工作日添加到日期字段的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。