def __add__(self,o): other = Duration(o,"DURATION") if not other.valid(): return Duration(0,"DURATION") seconds = self.utc_seconds() + other.seconds() new = Time(seconds,self.name(),self.timezone()) return new
def __add__(self,o): other = Duration(o,"DURATION") if not other.valid(): return Duration(0,"DURATION") seconds = self.utc_seconds() + other.seconds() new = Time(seconds,self.name()) new.timezone(self.timezone()) new.is_utc(self.is_utc()) return new
def __sub__(self, o): if isinstance(o, Time): # Subtract a time from this time and return a duration seconds = self.utc_seconds() - o.utc_seconds() return Duration(seconds) elif isinstance(o, Duration): # Subtract a duration from this time and return a time other = Duration(o) if (not other.valid()): return Time() seconds = self.utc_seconds() - other.seconds() return Time(seconds) else: raise TypeError, "subtraction with Time reqires Time or Duration"
def _prop_from_ref(self, p): if (p == None or p == WrapperNULL): return None d_string = icallangbind_property_eval_string(p, ":") d = eval(d_string) d['ref'] = p if not self.cached_props.has_key(p): if d['value_type'] == 'DATE-TIME' or d['value_type'] == 'DATE': prop = Time(d, ) elif d['value_type'] == 'PERIOD': prop = Period(d) elif d['value_type'] == 'DURATION': prop = Duration(d) elif d['name'] == 'ATTACH': prop = Attach(d) elif d['name'] == 'ATTENDEE': prop = Attendee(d) elif d['name'] == 'ORGANIZER': prop = Organizer(d) else: prop = Property(ref=p) self.cached_props[p] = prop
def _prop_from_ref(self, p): if (p == None or p == WrapperNULL): return None d = {} d['value'] = icalproperty_get_value_as_string(p) d['name'] = icalproperty_get_property_name(p) propkind = icalproperty_string_to_kind(d['name']) kind = icalproperty_kind_to_value_kind(propkind) d['value_type'] = icalvalue_kind_to_string(kind) d['ref'] = p #~ print p, Property(ref=p).name() if not self.cached_props.has_key(p): if d['value_type'] == 'DATE-TIME' or d['value_type'] == 'DATE': prop = Time(d, ) elif d['value_type'] == 'PERIOD': prop = Period(d) elif d['value_type'] == 'DURATION': prop = Duration(d) elif d['name'] == 'ATTACH': prop = Attach(d) elif d['name'] == 'ATTENDEE': prop = Attendee(d) elif d['name'] == 'ORGANIZER': prop = Organizer(d) else: prop = Property(ref=p) self.cached_props[p] = prop
def __sub__(self, other): hours, minutes = tuple([int(x) for x in self.hour.split(':')]) other_hours, other_minutes = tuple( [int(x) for x in other.hour.split(':')]) minute_difference = minutes - other_minutes if minute_difference < 0: hours -= 1 minute_difference = 60 - abs(minute_difference) hour_difference = hours - other_hours day = self.day if hour_difference < 0: day -= 1 hour_difference = 24 - abs(hour_difference) day_difference = day - other.day month = self.month if day_difference < 0: month -= 1 day_difference = 31 - abs(day_difference) month_difference = month - other.month year = self.year if month_difference < 0: year -= 1 month_difference = 12 - abs(month_difference) year_difference = year - other.year return Duration(years=year_difference, months=month_difference, days=day_difference, hours=hour_difference, minutes=minute_difference)
def __sub__(self,o): if isinstance(o,Time): # Subtract a time from this time and return a duration seconds = self.utc_seconds() - other.utc_seconds() return Duration(seconds) elif isinstance(o,Duration): # Subtract a duration from this time and return a time other = Duration(o) if(not other.valid()): return Time() seconds = self.utc_seconds() - other.seconds() return Time(seconds) else: raise TypeError, "subtraction with Time reqires Time or Duration"
def duration(self,v=None): """ Return or set the duration of the period. The duration may be expressed as an RFC2445 format string or an instance of Duration. The return value is an instance of Duration. If the period has an end time set, but not a duration, this method will calculate the duration from the end time. """ if(v != None): if isinstance(t,Duration): d = v elif isinstance(t,StringType) or isinstance(t,IntType): d = Duration(v) else: raise TypeError if(self._end_is_time()): start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) end = start + d.seconds() icalperiodtype_end_set(self.pt,icaltime_from_timet(end,0)) else: icalperiodtype_duration_set(self.pt,d.dur) if(self._end_is_time()): start =icaltime_as_timet(icalperiodtype_start_get(self.pt)) end = icaltime_as_timet(icalperiodtype_end_get(self.pt)) print "End is time " + str(end-start) return Duration(end-start,"DURATION") elif(self._end_is_duration()): dur = icaldurationtype_as_int( icalperiodtype_duration_get(self.pt)) return Duration(dur,"DURATION") else: return Duration(0,"DURATION")
def __init__(self, arg): Duration.__init__(self, arg, "TRIGGER")
def cells_to_strings(df, decimals=3): print_df = df.copy() for col in get_numeric_cols(df): print_df[col] = print_df[col].apply( lambda ms: Duration(ms).to_string_rounded(decimals)) return print_df
#!/usr/bin/env python
def _singular_property(self, name, value_type, value=None, property_obj=None, enumerated_values=None): """Sets or gets the value of a method which exists once per Component. This is a constructor method for properties without a strictly defined object.""" # Depending on the property name, this routine will either # operate on the VCALENDAR container or on the inner VEVENT, # VTODO, or VJOURNAL if name in ['METHOD', 'PRODID', 'CALSCALE', 'VERSION']: comp = self else: comp = self.inner_component() curr_properties = comp.properties(name) # Get the value if value == None: if not curr_properties: return None elif len(curr_properties) == 1: return curr_properties[0] else: raise ValueError, "too many properties of type %s" % propType # Set the value else: # Check if value is in enumerated_values if enumerated_values: value = string.upper(value) if value not in enumerated_values: raise ValueError, "%s is not one of %s" \ % (value, enumerated_values) # Create the new property if property_obj: if not isinstance(value, property_obj): # Create a special property_obj property if property_obj == Time: p = Time(value, name) ## p.value_type(value_type) elif property_obj == Duration: p = Duration(value) else: p = property_obj() ## p.value_type(value_type) p.value(value) else: p = value # value is already a property_obj else: # Create a generic property p = Property(name) ## p.value_type(value_type) p.value(value) if len(curr_properties) == 1: comp.remove_property(curr_properties[0]) elif curr_properties: raise ValueError, "too many properties of type %s" % propType comp.add_property(p)
def __init__(self,arg): Duration.__init__(self,arg,"TRIGGER") p = None
def readClients(fileName): """ Opens a client file in read mode. Requires: fileName as str (must be a client file) Ensures: inClients is ClientsCollection """ fileIn = open(fileName, 'r') filetwo = open(fileName, 'r') lenfile = len(filetwo.readlines()) outputList = [] inClients = ClientsCollection() # header always has 7 lines for i in range(7): fileIn.readline() # eliminating all the uselesss characters in the file for i in range(lenfile - 7): outputList.append(fileIn.readline().replace("*", "").replace("\n", "").split(",")) # This cycle runs through each of the entries, one at a time for i in outputList: # The first conditionals make sure the program # can understand the dates, even when the number # starts with 0 #Calculate month if i[2][6] == '0': month = int(i[2][7]) else: month = int(i[2][6:8]) # Calculate day if i[2][9] == '0': day = int([2][10]) else: day = int(i[2][-2:]) # Calculate hour if i[3][1] == '0': hour = int(i[3][2]) else: hour = int(i[3][1:3]) # Calculate minute if i[3][4] == '0': minute = int(i[3][5]) else: minute = int(i[3][4:6]) # A temporary Client object is created with all the information clientTemp = Client(i[0], i[1][1:], DateTime(int(i[2][1:5]), month, day, hour, minute), int(i[4][1:]), int(i[5][1:]), i[6][1:], Duration(i[7][1:])) # The Client object is then added to the inClients Collection inClients.addClient(clientTemp) fileIn.close() filetwo.close() return inClients