- Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathneo_ww_calculator.py
executable file
·41 lines (31 loc) · 1.09 KB
/
neo_ww_calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
importsys
fromdatetimeimportdatetime, timezone
defconvert_ww(epoch):
dt=datetime.fromtimestamp(epoch, timezone.utc)
# get some info from epoch
yr=int(dt.strftime("%y"))
doy=int(dt.strftime("%j"))
# and day of week for Jan 1st
dow1=int(datetime(dt.year, 1, 1).strftime("%w"))
# number of days in a year
_is_leap=yr%400==0or (yr%4==0andyr%100!=0)
_y_days=366if_is_leapelse365
_doy=doy-1+dow1# shift day of year to simulate Jan 1st as Sunday
_ww=int(_doy/7) +1# get workweek
_wd=int(_doy%7) # get days of week
_y_days=_y_days+dow1# adjusted number of days in year
_w_days=_y_days-_doy+_wd# numer of week days days to end of year
if_w_days<7:
# last week has less than 7 days
yr=yr+1
_ww=1
print("{:02d}.{:02d}".format(yr, _ww))
return0
if__name__=='__main__':
sys.exit(convert_ww(int(sys.argv[1])))