[Zope3-checkins] CVS: Zope3/src/zope/app - datetimeutils.py:1.1.2.1 datetime.py:NONE

Tim Peters tim.one@comcast.net
Mon, 23 Dec 2002 16:05:59 -0500


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv7386/src/zope/app

Added Files:
      Tag: NameGeddon-branch
	datetimeutils.py 
Removed Files:
      Tag: NameGeddon-branch
	datetime.py 
Log Message:
Renamed zope.app.datetime to zope.app.datetimeutils.  This tries to
import "the standard" datetime, but ended up thereby importing itself.


=== Added File Zope3/src/zope/app/datetimeutils.py === (889/989 lines abridged)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""Commonly used utility functions.

$Id: datetimeutils.py,v 1.1.2.1 2002/12/23 21:05:58 tim_one Exp $
"""

__version__='$Revision: 1.1.2.1 $'[11:-2]

import time

# These are needed because the various date formats below must
# be in english per the RFCs. That means we can't use strftime,
# which is affected by different locale settings.
weekday_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
weekday_full = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
                'Friday', 'Saturday', 'Sunday']
monthname    = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']


def iso8601_date(ts=None):
    # Return an ISO 8601 formatted date string, required
    # for certain DAV properties.
    # '2000-11-10T16:21:09-08:00
    if ts is None: ts=time.time()
    return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(ts))

def rfc850_date(ts=None):
    # Return an HTTP-date formatted date string.
    # 'Friday, 10-Nov-00 16:21:09 GMT'
    if ts is None: ts=time.time()
    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
    return "%s, %02d-%3s-%2s %02d:%02d:%02d GMT" % (
            weekday_full[wd],
            day, monthname[month],
            str(year)[2:],
            hh, mm, ss)


[-=- -=- -=- 889 lines omitted -=- -=- -=-]


        if s.find('T')>-1:
            fields = timereg.split(s[s.find('T')+1:])

            if fields[1]:   hour     = int(fields[1])
            if fields[3]:   minute   = int(fields[3])
            if fields[5]:   seconds  = int(fields[5])
            if fields[6]:   seconds  = seconds+float(fields[6])

            if fields[8]:   tzsign   = fields[8]
            if fields[9]:   hour_off = int(fields[9])
            if fields[11]:  min_off  = int(fields[11])

        return (year,month,day,hour,minute,seconds,
                '%s%02d%02d' % (tzsign,hour_off,min_off))

parser = DateTimeParser()
parse = parser.parse
time = parser.time

from datetime import tzinfo as _tzinfo
class tzinfo(_tzinfo):

    __slots__ = ('offset', )

    def __init__(self, offset):
        self.offset = offset

    def utcoffset(self, dt=None):
        return self.offset

    __getstate__ = utcoffset
    __setstate__ = __init__

    def dst(self, dt): return 0
    def tzname(self, dt): return ''

    def __repr__(self):
        return 'tzinfo(%d)' % self.offset


from datetime import datetimetz as _datetimetz
def parseDatetimetz(string):
    y, mo, d, h, m, s, tz = parse(string)
    s, micro = divmod(s, 1.0)
    micro = round(micro * 1000000)
    offset = _tzoffset(tz, None) / 60
    return _datetimetz(y, mo, d, h, m, s, micro, tzinfo(offset))

_iso_tz_re = re.compile("[-+]\d\d:\d\d$")

=== Removed File Zope3/src/zope/app/datetime.py ===