--- EventCalendar-094.py	2006-02-25 00:41:43.000000000 -0800
+++ EventCalendar-easytime.py	2006-02-25 00:53:40.000000000 -0800
@@ -510,21 +510,36 @@
     str_hour = ''
     str_min = ''
     
-    if len(str_time) == 4:
-        # hour+minute
-        str_hour = str_time[:2]
-        str_min = str_time[2:]
-    
-    elif len(str_time) == 5:
-        # hour+?+minute
-        str_hour = str_time[:2]
-        str_min = str_time[3:]
+    regex_time = '(?P<hour>\\d{1,2})[:]?(?P<minute>\\d{0,2})(?P<meridian_p>[pP][mM]?)?'
+    pattern = re.compile(regex_time)    
+    match = pattern.search(str_time)
+    
+    if match:
+        str_hour = match.group('hour')
+        str_min  = match.group('minute')
+        str_meridian_p = match.group('meridian_p')
         
     else:
         raise ValueError
     
+    int_hour = int(str_hour)
+    
+    # convert to 24 hour format
+    if int_hour == 12:
+        int_hour = 0
+	
+    # check for pm
+    if str_meridian_p:
+        int_hour = int_hour + 12
+    
+    #handle null minutes
+    try:
+        int_min = int(str_min)
+    except (TypeError, ValueError):
+        int_min = 0
+    
     # It raises exception if the input date is incorrect
-    temp = datetime.time(int(str_hour), int(str_min))
+    temp = datetime.time(int_hour, int_min)
 
     return temp.hour, temp.minute
 
@@ -1271,7 +1286,7 @@
 ^\s+start::\s*
 (?P<startdate>\d{4}[/-]\d{2}[/-]\d{2})
 \s*
-(?P<starttime>\d{2}[:]\d{2})*
+(?P<starttime>\d{1,2}[:]?\d{0,2}([AP][M]?)?)*
 \s*
 $
 """
@@ -1280,7 +1295,7 @@
 ^\s+end::\s*
 (?P<enddate>\d{4}[/-]\d{2}[/-]\d{2})*
 \s*
-(?P<endtime>\d{2}[:]\d{2})*
+(?P<endtime>\d{1,2}[:]?\d{0,2}([AP][M]?)?)*
 \s*
 $
 """
@@ -1380,8 +1395,8 @@
         # ERROR
         return '','','','','','','','','',''
     
-    if (starttime or endtime) and not (starttime and endtime):
-        #debug('no or 2 time field should be specified')
+    if (endtime) and not (starttime):
+        #debug('endtime without starttime')
         # ERROR
         return '','','','','','','','','',''
 
@@ -1420,6 +1435,15 @@
         # format time
         starttime = u'%02d%02d' %(shour, smin)
         endtime = u'%02d%02d' %(ehour, emin)
+    elif (starttime):
+        try:
+            shour, smin = gettimefield(starttime)
+        except (TypeError, ValueError):
+            #debug('invalid time format: %s, %s' % (startdate, enddate))
+            return '','','','','','','','','',''
+
+        starttime = u'%02d%02d' %(shour, smin)
+        endtime = u''
     
     # check recurrent data
     event_len = diffday(startdate, enddate)
@@ -1463,6 +1487,7 @@
                 debug('recur_until should precede enddate')
                 return '','','','','','','','','',''
     
+    
     return startdate, starttime, enddate, endtime, bgcolor, description, recur_freq, recur_type, recur_until
 
 
