因为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()
新闻热点
疑难解答