Share Pastebin
Guest
Public paste!

Untitled

By: a guest | May 2nd, 2008 | Syntax: Python | Size: 1.31 KB | Hits: 22 | Expires: Never
Copy text to clipboard
  1. from mx import DateTime as DT
  2.  
  3. def getDate():
  4.     dstr = raw_input("Enter date as year, month, day; or enter nothing for today: ")
  5.     if dstr == "":
  6.         return DT.now()
  7.     else:
  8.         dstr = dstr.split(',')
  9.         year, month, day = int(dstr[0]), int(dstr[1]), int(dstr[2])
  10.         return DT.Date(year, month, day)
  11.    
  12. def getDiff():
  13.     print "Enter positive int for days after date; negative int for days before date."
  14.     return int(raw_input("Enter the number of days: "))
  15.  
  16. def printDate(date):
  17.     print "Date entered was", str(date)[:10]
  18.    
  19. def printDatePlusN(date, n):
  20.     plus_minus = ""
  21.     if n >= 0:
  22.         plus_minus = "plus"
  23.     else:
  24.         plus_minus = "minus"
  25.     print "%s %s %s days is %s" % (str(date)[:10], plus_minus, str(abs(n)),
  26.         str(date + n)[:10])
  27.  
  28. def main():
  29.     date = getDate()
  30.     printDate(date)
  31.     n = getDiff()
  32.     printDatePlusN(date, n)
  33.  
  34. if __name__ == '__main__':
  35.     main()
  36.    
  37.  
  38. """
  39. sample output:
  40. =============================================
  41. Enter date as year, month, day; or enter nothing for today:
  42. Date entered was 2008-05-02
  43. Enter positive int for days after date; negative int for days before date.
  44. Enter the number of days: -100000
  45. 2008-05-02 minus 100000 days is 1734-07-18
  46. =============================================
  47. """