def __init__(self, per): start, end_or_duration = per if not (isinstance(start, datetime) or isinstance(start, date)): raise ValueError('Start value MUST be a datetime or date instance') if not (isinstance(end_or_duration, datetime) or isinstance(end_or_duration, date) or isinstance(end_or_duration, timedelta)): raise ValueError('end_or_duration MUST be a datetime, ' 'date or timedelta instance') by_duration = 0 if isinstance(end_or_duration, timedelta): by_duration = 1 duration = end_or_duration end = start + duration else: end = end_or_duration duration = end - start if start > end: raise ValueError("Start time is greater than end time") self.params = Parameters() # set the timezone identifier # does not support different timezones for start and end tzid = tzinfo_from_dt(start) if tzid: self.params['TZID'] = tzid self.start = start self.end = end self.by_duration = by_duration self.duration = duration
def to_ical(self): dt = self.dt tzid = tzinfo_from_dt(dt) s = "%04d%02d%02dT%02d%02d%02d" % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) if tzid == "UTC": s += "Z" elif tzid: self.params.update({"TZID": tzid}) return s
def to_ical(self): dt = self.dt tzid = tzinfo_from_dt(dt) s = "%04d%02d%02dT%02d%02d%02d" % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) if tzid == 'UTC': s += "Z" elif tzid: self.params.update({'TZID': tzid}) return s
def __init__(self, dt): "Returns vDate from" if type(dt) not in (datetime, date, timedelta, time): raise ValueError("You must use datetime, date, timedelta or time") if isinstance(dt, datetime): self.params = Parameters(dict(value="DATE-TIME")) elif isinstance(dt, date): self.params = Parameters(dict(value="DATE")) elif isinstance(dt, time): self.params = Parameters(dict(value="TIME")) if (isinstance(dt, datetime) or isinstance(dt, time)) and getattr(dt, "tzinfo", False): tzinfo = dt.tzinfo if tzinfo is not pytz.utc and not isinstance(tzinfo, tzutc): # set the timezone as a parameter to the property tzid = tzinfo_from_dt(dt) if tzid: self.params.update({"TZID": tzid}) self.dt = dt