Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.parsedatetime.parsedatetime Namespace Reference

Classes

class  Calendar

Functions

def _extract_date
def _extract_time
def _parse_date_w3dtf
def _parse_date_rfc822

Variables

string __license__
 _debug = False
dictionary _additional_timezones

Function Documentation

Definition at line 39 of file parsedatetime.py.

00039 
00040 def _extract_date(m):
00041     year = int(m.group('year'))
00042     if year < 100:
00043         year = 100 * int(time.gmtime()[0] / 100) + int(year)
00044     if year < 1000:
00045         return 0, 0, 0
00046     julian = m.group('julian')
00047     if julian:
00048         julian = int(julian)
00049         month = julian / 30 + 1
00050         day = julian % 30 + 1
00051         jday = None
00052         while jday != julian:
00053             t = time.mktime((year, month, day, 0, 0, 0, 0, 0, 0))
00054             jday = time.gmtime(t)[-2]
00055             diff = abs(jday - julian)
00056             if jday > julian:
00057                 if diff < day:
00058                     day = day - diff
00059                 else:
00060                     month = month - 1
00061                     day = 31
00062             elif jday < julian:
00063                 if day + diff < 28:
00064                     day = day + diff
00065                 else:
00066                     month = month + 1
00067         return year, month, day
00068     month = m.group('month')
00069     day = 1
00070     if month is None:
00071         month = 1
00072     else:
00073         month = int(month)
00074         day = m.group('day')
00075         if day:
00076             day = int(day)
00077         else:
00078             day = 1
00079     return year, month, day
00080 
00081 # Copied from feedparser.py
00082 # Universal Feedparser
00083 # Copyright (c) 2002-2006, Mark Pilgrim, All rights reserved.
# Originally a def inside of _parse_date_w3dtf()

Here is the caller graph for this function:

Definition at line 84 of file parsedatetime.py.

00084 
00085 def _extract_time(m):
00086     if not m:
00087         return 0, 0, 0
00088     hours = m.group('hours')
00089     if not hours:
00090         return 0, 0, 0
00091     hours = int(hours)
00092     minutes = int(m.group('minutes'))
00093     seconds = m.group('seconds')
00094     if seconds:
00095         seconds = int(seconds)
00096     else:
00097         seconds = 0
00098     return hours, minutes, seconds
00099 
00100 
00101 # Copied from feedparser.py
00102 # Universal Feedparser
00103 # Copyright (c) 2002-2006, Mark Pilgrim, All rights reserved.
00104 # Modified to return a tuple instead of mktime
00105 #
00106 # Original comment:
00107 #   W3DTF-style date parsing adapted from PyXML xml.utils.iso8601, written by
00108 #   Drake and licensed under the Python license.  Removed all range checking
00109 #   for month, day, hour, minute, and second, since mktime will normalize
#   these later

Here is the caller graph for this function:

Parse an RFC822, RFC1123, RFC2822, or asctime-style date

Definition at line 154 of file parsedatetime.py.

00154 
00155 def _parse_date_rfc822(dateString):
00156     '''Parse an RFC822, RFC1123, RFC2822, or asctime-style date'''
00157     data = dateString.split()
00158     if data[0][-1] in (',', '.') or data[0].lower() in rfc822._daynames:
00159         del data[0]
00160     if len(data) == 4:
00161         s = data[3]
00162         i = s.find('+')
00163         if i > 0:
00164             data[3:] = [s[:i], s[i+1:]]
00165         else:
00166             data.append('')
00167         dateString = " ".join(data)
00168     if len(data) < 5:
00169         dateString += ' 00:00:00 GMT'
00170     return rfc822.parsedate_tz(dateString)
00171 
00172 # rfc822.py defines several time zones, but we define some extra ones.
# 'ET' is equivalent to 'EST', etc.

Here is the caller graph for this function:

Definition at line 110 of file parsedatetime.py.

00110 
00111 def _parse_date_w3dtf(dateString):
00112     # the __extract_date and __extract_time methods were
00113     # copied-out so they could be used by my code --bear
00114     def __extract_tzd(m):
00115         '''Return the Time Zone Designator as an offset in seconds from UTC.'''
00116         if not m:
00117             return 0
00118         tzd = m.group('tzd')
00119         if not tzd:
00120             return 0
00121         if tzd == 'Z':
00122             return 0
00123         hours = int(m.group('tzdhours'))
00124         minutes = m.group('tzdminutes')
00125         if minutes:
00126             minutes = int(minutes)
00127         else:
00128             minutes = 0
00129         offset = (hours*60 + minutes) * 60
00130         if tzd[0] == '+':
00131             return -offset
00132         return offset
00133 
00134     __date_re = ('(?P<year>\d\d\d\d)'
00135                  '(?:(?P<dsep>-|)'
00136                  '(?:(?P<julian>\d\d\d)'
00137                  '|(?P<month>\d\d)(?:(?P=dsep)(?P<day>\d\d))?))?')
00138     __tzd_re = '(?P<tzd>[-+](?P<tzdhours>\d\d)(?::?(?P<tzdminutes>\d\d))|Z)'
00139     __tzd_rx = re.compile(__tzd_re)
00140     __time_re = ('(?P<hours>\d\d)(?P<tsep>:|)(?P<minutes>\d\d)'
00141                  '(?:(?P=tsep)(?P<seconds>\d\d(?:[.,]\d+)?))?'
00142                  + __tzd_re)
00143     __datetime_re = '%s(?:T%s)?' % (__date_re, __time_re)
00144     __datetime_rx = re.compile(__datetime_re)
00145     m = __datetime_rx.match(dateString)
00146     if (m is None) or (m.group() != dateString): return
00147     return _extract_date(m) + _extract_time(m) + (0, 0, 0)
00148 
00149 
00150 # Copied from feedparser.py
00151 # Universal Feedparser
00152 # Copyright (c) 2002-2006, Mark Pilgrim, All rights reserved.
00153 # Modified to return a tuple instead of mktime
#

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 """
00002 Copyright (c) 2004-2008 Mike Taylor
00003 Copyright (c) 2006-2008 Darshana Chhajed
00004 All rights reserved.
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010    http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017 """

Definition at line 7 of file parsedatetime.py.

Initial value:
00001 {'AT': -400, 'ET': -500,
00002                          'CT': -600, 'MT': -700,
00003                          'PT': -800}

Definition at line 173 of file parsedatetime.py.

Definition at line 25 of file parsedatetime.py.