因為issue report 很多情況下按周report,所以用Python實現自動issue tracking時難免會用第幾周作為圖形的下標
def cal_label(self, date): m = re.search('(/d+)([^/d])(/d+)([^/d](/d+))', date) if self.step == 'all': res = 'all' elif self.step == 'year': res = m.group(1) elif self.step == 'month': res = r''.join(m.group(1,2,3)) elif self.step == 'week': #TODO guard form = '%Y{0}%m{0}%d'.format(m.group(2)) week = time.strftime('%W %w', time.strptime(date, form)) [W, w] = re.split(' ', week) res = W + 'W' else: ValueError("can't support other format, %s" %(self.step)) return(str(res))
這里引用一下‘一個人的天空’的博客,關于Python time module的詳細用法可以去那里看:
http://www.cnblogs.com/QQ78292959/archive/2013/03/22/2975786.html
這里已知‘2017/3/3’ format string, 所以先strptime成stuct_time然后strftime成format string,
%W表示第幾周
%w表示本周的第幾天
還有另一種方法用datetime
import datetime
datetime.datetime(2017,3,3).isocalendar()
新聞熱點
疑難解答