Created
August 26, 2015 05:21
-
-
Save swaroopch/97fb4de4e121acd754cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
from __future__ import absolute_import, division, print_function, unicode_literals | |
import arrow | |
import click | |
click.disable_unicode_literals_warning = True | |
def is_weekend(i): | |
assert isinstance(i, arrow.Arrow) | |
return i.weekday() in (5, 6) | |
@click.command() | |
@click.argument("day") | |
@click.argument("working_days", type=click.IntRange(0, 360)) | |
def datemanip(day, working_days): | |
""" | |
Example: | |
> datemanip today 4 | |
20150831 Mon | |
Use in conjunction with `cal -y` for your date manipulation needs. | |
""" | |
if day == "today": | |
day = arrow.now() | |
else: | |
day = arrow.get(day, "YYYYMMDD") | |
i = day | |
while True: | |
i = i.replace(days=+1) | |
working_days -= 1 | |
# Skip weekend | |
while is_weekend(i): | |
i = i.replace(days=+1) | |
# Increment `i` & decrement working_days in lockstep | |
if working_days == 0: | |
break | |
print(i.format("YYYYMMDD ddd")) | |
if __name__ == "__main__": | |
datemanip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment