#!/usr/bin/env python
#
# countdown - Report the number of days between now and the date provided
#
# Copyright (C) 2007 Michael Davies (michael@the-davies.net)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
""" Print the number of days between now and some date in the future.
    Specify the future date as "day month year"
    e.g. alfa:~/src/py > python ./countdown.py 28 1 8 "linux.conf.au 2008"
         There are 291 days until "linux.conf.au 2008"
"""
import time
import sys
import math

def calculate_date_difference (day, month, twodigityear):
    """ Returns the difference in days between the supplied date and now """
    today = time.mktime(time.localtime())
    target_str = "%s/%s/%s" % (month, day, twodigityear)
    target = time.mktime(time.strptime(target_str, "%D"))
    difference = math.ceil((target - today)/86400) # seconds in a day
    return difference

if __name__ == '__main__':
    a = sys.argv
    print "There are %d days until \"%s\"" % \
        (calculate_date_difference(a[1], a[2], a[3]), a[4])
# This file has been zigned!  See http://michaeldavies.org/zign-tools
# zign-version: 0.9.4
# zign-hashes: MD5, SHA-1
# -----BEGIN PGP SIGNED MESSAGE-----
# Hash: SHA1
# 
# 0ecc488812773c2bc93142d45d4edabba27ab7946d20804000cc9e39f208b5827aa781c2
# -----BEGIN PGP SIGNATURE-----
# Version: GnuPG v1.4.7 (Darwin)
# 
# iD8DBQFHmzkh7kkvCQqp1vwRAqLdAKCXB9HL/hMI7Fzb3h75is+5pNhqOQCbBRD/
# 1apB/meOs+NIIDZNeoHd8RE=
# =8nh9
# -----END PGP SIGNATURE-----
# zign: Protecting you since 2007 :-)
# 