Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deadlines to Output #114

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature: make time code more dry
  • Loading branch information
burgess01 committed Mar 1, 2023
commit 117e44381b6400b12ac1a30fba68bef137d71f8c
32 changes: 17 additions & 15 deletions gatorgrade/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ def _run_gg_check(check: GatorGraderCheck) -> CheckResult:
return CheckResult(passed=passed, description=description, diagnostic=diagnostic)


def calculate_deadline_time_dif(older_time: datetime, latest_time: datetime):
"""Input two times and return the difference of the two in days, hours, minutes, and seconds.

Args:
older_time: The larger datetime object
latest_time: The smaller datetime object
"""
time_difference = older_time - latest_time
days = time_difference.days
hours, remainder = divmod(time_difference.seconds, 3600)
minutes, seconds = divmod(remainder, 60)

return days, hours, minutes, seconds


def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], deadline) -> bool:
"""Run shell and GatorGrader checks and display whether each has passed or failed.

Expand Down Expand Up @@ -114,30 +129,17 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]], deadline) -> b
# if a deadline is included:
if deadline != None:
# turn the string into a datetime variable

deadline = datetime.strptime(deadline[:-1], "%m/%d/%y %H:%M:%S")
# if the deadline has passed, print out late
now = datetime.now()
if now > deadline:
time_after_deadline = now - deadline
# days
days = time_after_deadline.days
# hours
hours, remainder = divmod(time_after_deadline.seconds, 3600)
minutes, seconds = divmod(remainder, 60)

days, hours, minutes, seconds = calculate_deadline_time_dif(now, deadline)
print(
f"\n-~- Your assignment is late. The deadline was {abs(days)} days, {hours} hours, {minutes} minutes, and {seconds} seconds ago. -~-"
)
# else, print out the remaining time until the assignment is due
else:
time_until_deadline = deadline - now
# days
days = time_until_deadline.days
# hours
hours, remainder = divmod(time_until_deadline.seconds, 3600)
minutes, seconds = divmod(remainder, 60)

days, hours, minutes, seconds = calculate_deadline_time_dif(deadline, now)
print(
f"\n-~- Your assignment is due in {days * -1} days, {hours} hours, {minutes} minutes, and {seconds} seconds. -~-"
)
Expand Down