Back to index

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

List of all members.

Public Member Functions

def __init__
def ical
def from_ical
def __str__

Public Attributes

 td
 params

Static Public Attributes

tuple from_ical = staticmethod(from_ical)

Detailed Description

Renders itself as a utc offset

>>> u = vUTCOffset(timedelta(hours=2))
>>> u.ical()
'+0200'

>>> u = vUTCOffset(timedelta(hours=-5))
>>> u.ical()
'-0500'

>>> u = vUTCOffset(timedelta())
>>> u.ical()
'0000'

>>> u = vUTCOffset(timedelta(minutes=-30))
>>> u.ical()
'-0030'

>>> u = vUTCOffset(timedelta(hours=2, minutes=-30))
>>> u.ical()
'+0130'

>>> u = vUTCOffset(timedelta(hours=1, minutes=30))
>>> u.ical()
'+0130'

Parsing

>>> vUTCOffset.from_ical('0000')
datetime.timedelta(0)

>>> vUTCOffset.from_ical('-0030')
datetime.timedelta(-1, 84600)

>>> vUTCOffset.from_ical('+0200')
datetime.timedelta(0, 7200)

>>> o = vUTCOffset.from_ical('+0230')
>>> vUTCOffset(o).ical()
'+0230'

And a few failures
>>> vUTCOffset.from_ical('+323k')
Traceback (most recent call last):
    ...
ValueError: Expected utc offset, got: +323k

>>> vUTCOffset.from_ical('+2400')
Traceback (most recent call last):
    ...
ValueError: Offset must be less than 24 hours, was +2400

Definition at line 1138 of file prop.py.


Constructor & Destructor Documentation

def icalendar.prop.vUTCOffset.__init__ (   self,
  td 
)

Definition at line 1193 of file prop.py.

01193 
01194     def __init__(self, td):
01195         if not isinstance(td, timedelta):
01196             raise ValueError('Offset value MUST be a timedelta instance')
01197         self.td = td
01198         self.params = Parameters()


Member Function Documentation

Definition at line 1229 of file prop.py.

01229 
01230     def __str__(self):
01231         return self.ical()
01232 
01233 

Here is the call graph for this function:

Definition at line 1215 of file prop.py.

01215 
01216     def from_ical(ical):
01217         "Parses the data format from ical text format"
01218         try:
01219             sign, hours, minutes = (ical[-5:-4], int(ical[-4:-2]), int(ical[-2:]))
01220             offset = timedelta(hours=hours, minutes=minutes)
01221         except:
01222             raise ValueError, 'Expected utc offset, got: %s' % ical
01223         if offset >= timedelta(hours=24):
01224             raise ValueError, 'Offset must be less than 24 hours, was %s' % ical
01225         if sign == '-':
01226             return -offset
        return offset

Definition at line 1199 of file prop.py.

01199 
01200     def ical(self):
01201         td = self.td
01202         day_in_minutes = (td.days * 24 * 60)
01203         seconds_in_minutes = td.seconds // 60
01204         total_minutes = day_in_minutes + seconds_in_minutes
01205         if total_minutes == 0:
01206             sign = '%s'
01207         elif total_minutes < 0:
01208             sign = '-%s'
01209         else:
01210             sign = '+%s'
01211         hours = abs(total_minutes) // 60
01212         minutes = total_minutes % 60
01213         duration = '%02i%02i' % (hours, minutes)
01214         return sign % duration

Here is the caller graph for this function:


Member Data Documentation

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

Definition at line 1227 of file prop.py.

Definition at line 1197 of file prop.py.

Definition at line 1196 of file prop.py.


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