Back to index

plone3  3.1.7
utils.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 Some utilities.
00021 """
00022 
00023 import datetime
00024 from DateTime import DateTime
00025 
00026 def dt2DT(date):
00027     """Convert Python's datetime to Zope's DateTime
00028     """
00029     return DateTime(*date.timetuple()[:6])
00030 
00031 def DT2dt(date):
00032     """Convert Zope's DateTime to Pythons's datetime
00033     """
00034     # seconds (parts[6]) is a float, so we map to int
00035     args = map(int, date.parts()[:6])
00036     return datetime.datetime(*args)
00037 
00038 def toTime(date):
00039     """get time part of a date
00040     """
00041     if isinstance(date, datetime.datetime):
00042         date = dt2DT(date)
00043     return date.Time()
00044 
00045 def toSeconds(td):
00046     """Converts a timedelta to an integer representing the number of seconds
00047     """
00048     return td.seconds + td.days * 86400