Skip to content

Commit

Permalink
Rewrite "days_remaining_in_year" in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Feb 6, 2013
1 parent e82d1ea commit 294d126
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions days_remaining_in_year.sh → days_remaining_in_year.py
@@ -1,10 +1,15 @@
#!/bin/sh
#!/usr/bin/python
# Days Remaining in the Current Year
# Author: Thomas Perl

import datetime

today = datetime.datetime.now()
day_of_year = int(today.strftime('%j'))

# Leap year check will work until 2100 (mod 100 and mod 400 rules ignored)
# See http://en.wikipedia.org/wiki/Leap_year#Algorithm
leap_year=$(($(date +%Y) % 4 == 0))
leap_year = (today.year % 4 == 0)

echo $((365 + $leap_year - $(date +%j)))
print (366 if leap_year else 365) - day_of_year

0 comments on commit 294d126

Please sign in to comment.