Created
October 25, 2019 18:15
-
-
Save vic4key/fecc2836686ca11f53948d66badafdc6 to your computer and use it in GitHub Desktop.
Calculate working hours in a month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate working hours in a month | |
# Pretty | |
def F(M, Y): | |
import calendar | |
def f(b, i, d, n): | |
d = d - n * i + b if d > 0 else 0 # day -> wday | |
d = {7: 4, 8: 0, 0: 0}.get(d, 8) # wday -> hrs | |
return d | |
m = calendar.monthcalendar(Y, M) | |
m = [[f(m[0].count(0) + 1, i, d, len(w)) for d in w] for i, w in enumerate(m)] | |
print(*m, sum([sum(w) for w in m]), sep="\n") | |
# Minify | |
def F(M, Y): import calendar; m = calendar.monthcalendar(Y, M); f = lambda b, i, d, n: {7: 4, 8: 0, 0: 0}.get(d - n * i + b if d > 0 else 0, 8); print(sum([sum(w) for w in [[f(m[0].count(0) + 1, i, d, len(w)) for d in w] for i, w in enumerate(m)]])) | |
F(9, 2019) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment