Attachment 'EventCalendar-easytime2.patch'

Download

   1 --- EventCalendar-094.py	2006-02-25 00:41:43.000000000 -0800
   2 +++ EventCalendar-easytime.py	2006-02-25 01:27:20.000000000 -0800
   3 @@ -510,21 +510,37 @@
   4      str_hour = ''
   5      str_min = ''
   6      
   7 -    if len(str_time) == 4:
   8 -        # hour+minute
   9 -        str_hour = str_time[:2]
  10 -        str_min = str_time[2:]
  11 -    
  12 -    elif len(str_time) == 5:
  13 -        # hour+?+minute
  14 -        str_hour = str_time[:2]
  15 -        str_min = str_time[3:]
  16 +    regex_time = '(?P<hour>\\d{1,2})[:]?(?P<minute>\\d{0,2})(?P<pm>[pP][mM]?)?(?P<am>[aA][mM]?)?'
  17 +    pattern = re.compile(regex_time)    
  18 +    match = pattern.search(str_time)
  19 +    
  20 +    if match:
  21 +        str_hour = match.group('hour')
  22 +        str_min  = match.group('minute')
  23 +        str_pm = match.group('pm')
  24 +        str_am = match.group('am')
  25          
  26      else:
  27          raise ValueError
  28      
  29 +    int_hour = int(str_hour)
  30 +    
  31 +    # convert to 24 hour format
  32 +    if int_hour == 12 and (str_am or str_pm):
  33 +        int_hour = 0
  34 +	
  35 +    # check for pm
  36 +    if str_pm:
  37 +        int_hour = int_hour + 12
  38 +    
  39 +    #handle null minutes
  40 +    try:
  41 +        int_min = int(str_min)
  42 +    except (TypeError, ValueError):
  43 +        int_min = 0
  44 +    
  45      # It raises exception if the input date is incorrect
  46 -    temp = datetime.time(int(str_hour), int(str_min))
  47 +    temp = datetime.time(int_hour, int_min)
  48  
  49      return temp.hour, temp.minute
  50  
  51 @@ -1271,7 +1287,7 @@
  52  ^\s+start::\s*
  53  (?P<startdate>\d{4}[/-]\d{2}[/-]\d{2})
  54  \s*
  55 -(?P<starttime>\d{2}[:]\d{2})*
  56 +(?P<starttime>\d{1,2}[:]?\d{0,2}([AP][M]?)?)*
  57  \s*
  58  $
  59  """
  60 @@ -1280,7 +1296,7 @@
  61  ^\s+end::\s*
  62  (?P<enddate>\d{4}[/-]\d{2}[/-]\d{2})*
  63  \s*
  64 -(?P<endtime>\d{2}[:]\d{2})*
  65 +(?P<endtime>\d{1,2}[:]?\d{0,2}([AP][M]?)?)*
  66  \s*
  67  $
  68  """
  69 @@ -1380,8 +1396,8 @@
  70          # ERROR
  71          return '','','','','','','','','',''
  72      
  73 -    if (starttime or endtime) and not (starttime and endtime):
  74 -        #debug('no or 2 time field should be specified')
  75 +    if (endtime) and not (starttime):
  76 +        #debug('endtime without starttime')
  77          # ERROR
  78          return '','','','','','','','','',''
  79  
  80 @@ -1420,6 +1436,15 @@
  81          # format time
  82          starttime = u'%02d%02d' %(shour, smin)
  83          endtime = u'%02d%02d' %(ehour, emin)
  84 +    elif (starttime):
  85 +        try:
  86 +            shour, smin = gettimefield(starttime)
  87 +        except (TypeError, ValueError):
  88 +            #debug('invalid time format: %s, %s' % (startdate, enddate))
  89 +            return '','','','','','','','','',''
  90 +
  91 +        starttime = u'%02d%02d' %(shour, smin)
  92 +        endtime = u''
  93      
  94      # check recurrent data
  95      event_len = diffday(startdate, enddate)
  96 @@ -1463,6 +1488,7 @@
  97                  debug('recur_until should precede enddate')
  98                  return '','','','','','','','','',''
  99      
 100 +    
 101      return startdate, starttime, enddate, endtime, bgcolor, description, recur_freq, recur_type, recur_until
 102  
 103  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-02-25 08:59:09, 2.8 KB) [[attachment:EventCalendar-easytime.patch]]
  • [get | view] (2006-02-25 09:30:01, 2.9 KB) [[attachment:EventCalendar-easytime2.patch]]
  • [get | view] (2006-02-25 09:30:39, 74.9 KB) [[attachment:EventCalendar-easytime2.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.