Expand/Shrink
Argumenty příkazové řádky:
python date_conversion2.1.py 20.12.2005 20.3.2005 1.3.2008 18.7.77 36.5.2004 1.14.1999 30.2.2006 29.2.2006 30.2.2006
  1   import sys
  2   import re
  3   
  4   
  5   for date in sys.argv[1:]:
  6       m = re.match( "^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$", date)
  7       if m:
  8           d, m, y = [int( g) for g in m.groups()]
  9           if d < 1 or d > 31:
 10               print "Wrong day '%d' in '%s'" % (d, date)
 11           elif m < 1 or m > 12:
 12               print "Wrong month '%d' in '%s'" % (m, date)
 13           else:
 14               print "%d-%02d-%02d" % (y, m, d)
 15       else:
 16           print "Date in wrong format:", date
stdout:
2005-12-20
2005-03-20
2008-03-01
Date in wrong format: 18.7.77
Wrong day '36' in '36.5.2004'
Wrong month '14' in '1.14.1999'
2006-02-30
2006-02-29
2006-02-30
Doba běhu: 43.8 ms