Skip to content

Instantly share code, notes, and snippets.

@andyrudoff
Created September 30, 2020 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyrudoff/ee5e68d2498dc819b363c8b82d6d78c2 to your computer and use it in GitHub Desktop.
Save andyrudoff/ee5e68d2498dc819b363c8b82d6d78c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# ww -- calculate the current Intel work week (which is slightly different than ISO week)
#
import datetime
def ww(d):
# find first day of ww 1 by finding Jan 1 of
# d's year and back up to the Sunday for that week
first = datetime.date(d.year, 1, 1)
first = first - datetime.timedelta(days = (first.weekday() + 1) % 7)
# similarly, find the first day of the next year's ww 1
nxt = datetime.date(d.year + 1, 1, 1)
nxt = nxt - datetime.timedelta(days = (nxt.weekday() + 1) % 7)
# the work week is now calculated by counting the
# number of weeks that passed since "first", except
# near the end of the year when we might run into
# ww 1 of next year, so we check for that first
if d >= nxt:
return 1
# the work week is the number of weeks
# that have passed since "first". we add one since the
# first ww is ww 1 not ww 0.
delta = d - first
return delta.days / 7 + 1
def testww():
d = datetime.date(2008, 11, 20)
enddate = datetime.date(2013, 2, 2)
delta = datetime.timedelta(days = 1)
while d <= enddate:
print d.strftime("%Y-%m-%d"), ww(d)
d += delta
if __name__ == '__main__':
print ww(datetime.date.today())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment