Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
icalendar.prop.vPeriod Class Reference

List of all members.

Public Member Functions

def __init__
def __cmp__
def overlaps
def ical
def from_ical
def __str__
def __repr__

Public Attributes

 start
 end_or_duration
 by_duration
 duration
 end
 params

Static Public Attributes

tuple from_ical = staticmethod(from_ical)

Detailed Description

A precise period of time.
One day in exact datetimes
>>> per = (datetime(2000,1,1), datetime(2000,1,2))
>>> p = vPeriod(per)
>>> p.ical()
'20000101T000000/20000102T000000'

>>> per = (datetime(2000,1,1), timedelta(days=31))
>>> p = vPeriod(per)
>>> p.ical()
'20000101T000000/P31D'

Roundtrip
>>> p = vPeriod.from_ical('20000101T000000/20000102T000000')
>>> p
(datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2000, 1, 2, 0, 0))
>>> vPeriod(p).ical()
'20000101T000000/20000102T000000'

>>> vPeriod.from_ical('20000101T000000/P31D')
(datetime.datetime(2000, 1, 1, 0, 0), datetime.timedelta(31))

Roundtrip with absolute time
>>> p = vPeriod.from_ical('20000101T000000Z/20000102T000000Z')
>>> vPeriod(p).ical()
'20000101T000000Z/20000102T000000Z'

And an error
>>> vPeriod.from_ical('20000101T000000/Psd31D')
Traceback (most recent call last):
    ...
ValueError: Expected period format, got: 20000101T000000/Psd31D

Utc datetime
>>> da_tz = FixedOffset(+1.0, 'da_DK')
>>> start = datetime(2000,1,1, tzinfo=da_tz)
>>> end = datetime(2000,1,2, tzinfo=da_tz)
>>> per = (start, end)
>>> vPeriod(per).ical()
'19991231T235900Z/20000101T235900Z'

>>> p = vPeriod((datetime(2000,1,1, tzinfo=da_tz), timedelta(days=31)))
>>> p.ical()
'19991231T235900Z/P31D'

Definition at line 598 of file prop.py.


Constructor & Destructor Documentation

def icalendar.prop.vPeriod.__init__ (   self,
  per 
)

Definition at line 646 of file prop.py.

00646 
00647     def __init__(self, per):
00648         start, end_or_duration = per
00649         if not (isinstance(start, datetime) or isinstance(start, date)):
00650             raise ValueError('Start value MUST be a datetime or date instance')
00651         if not (isinstance(end_or_duration, datetime) or
00652                 isinstance(end_or_duration, date) or
00653                 isinstance(end_or_duration, timedelta)):
00654             raise ValueError('end_or_duration MUST be a datetime, date or timedelta instance')
00655         self.start = start
00656         self.end_or_duration = end_or_duration
00657         self.by_duration = 0
00658         if isinstance(end_or_duration, timedelta):
00659             self.by_duration = 1
00660             self.duration = end_or_duration
00661             self.end = self.start + self.duration
00662         else:
00663             self.end = end_or_duration
00664             self.duration = self.end - self.start
00665         if self.start > self.end:
00666             raise ValueError("Start time is greater than end time")
00667         self.params = Parameters()


Member Function Documentation

def icalendar.prop.vPeriod.__cmp__ (   self,
  other 
)

Definition at line 668 of file prop.py.

00668 
00669     def __cmp__(self, other):
00670         if not isinstance(other, vPeriod):
00671             raise NotImplementedError(
00672                 'Cannot compare vPeriod with %s' % repr(other))
00673         return cmp((self.start, self.end), (other.start, other.end))

Definition at line 700 of file prop.py.

00700 
00701     def __repr__(self):
00702         if self.by_duration:
00703             p = (self.start, self.duration)
00704         else:
00705             p = (self.start, self.end)
00706         return 'vPeriod(%s)' % repr(p)

Definition at line 697 of file prop.py.

00697 
00698     def __str__(self):
00699         return self.ical()

Here is the call graph for this function:

Definition at line 686 of file prop.py.

00686 
00687     def from_ical(ical):
00688         "Parses the data format from ical text format"
00689         try:
00690             start, end_or_duration = ical.split('/')
00691             start = vDDDTypes.from_ical(start)
00692             end_or_duration = vDDDTypes.from_ical(end_or_duration)
00693             return (start, end_or_duration)
00694         except:
            raise ValueError, 'Expected period format, got: %s' % ical

Definition at line 681 of file prop.py.

00681 
00682     def ical(self):
00683         if self.by_duration:
00684             return '%s/%s' % (vDatetime(self.start).ical(), vDuration(self.duration).ical())
00685         return '%s/%s' % (vDatetime(self.start).ical(), vDatetime(self.end).ical())

Here is the caller graph for this function:

def icalendar.prop.vPeriod.overlaps (   self,
  other 
)

Definition at line 674 of file prop.py.

00674 
00675     def overlaps(self, other):
00676         if self.start > other.start:
00677             return other.overlaps(self)
00678         if self.start <= other.start < self.end:
00679             return True
00680         return False


Member Data Documentation

Definition at line 656 of file prop.py.

Definition at line 659 of file prop.py.

Definition at line 660 of file prop.py.

Definition at line 655 of file prop.py.

tuple icalendar.prop.vPeriod.from_ical = staticmethod(from_ical) [static]

Definition at line 695 of file prop.py.

Definition at line 666 of file prop.py.

Definition at line 654 of file prop.py.


The documentation for this class was generated from the following file: