Commit e5d093be authored by Andreas Jung's avatar Andreas Jung

*** empty log message ***

parent b7259de4
......@@ -84,12 +84,13 @@
##############################################################################
'''Add security system support to Document Templates
$Id: DTML.py,v 1.4 2001/05/23 14:42:04 andreas Exp $'''
__version__='$Revision: 1.4 $'[11:-2]
$Id: DTML.py,v 1.5 2001/06/19 15:33:09 andreas Exp $'''
__version__='$Revision: 1.5 $'[11:-2]
from DocumentTemplate import DT_Util
import SecurityManagement, string, math, whrandom, random
import DocumentTemplate.sequence
import DateTime.newDateTime
# Allow access to unprotected attributes
DT_Util.TemplateDict.__allow_access_to_unprotected_subobjects__=1
......@@ -99,6 +100,7 @@ whrandom.__allow_access_to_unprotected_subobjects__=1
random.__allow_access_to_unprotected_subobjects__=1
DocumentTemplate.sequence.__allow_access_to_unprotected_subobjects__=1
DateTime.newDateTime.__allow_access_to_unprotected_subobjects__=1
# Add security testing capabilities
......
......@@ -84,3 +84,4 @@
##############################################################################
from DateTime import DateTime
from DateTime import Timezones
from newDateTime import DateTime as newDateTime
from mx.DateTime import DateTime as mxDateTime
from mx.DateTime import DateTimeFrom as mxDateTimeFrom
from mx.DateTime import Time as mxTime
from mx.DateTime import DateFromTicks as mxDateFromTicks
from mx.DateTime import TimestampFromTicks as mxTimestampFromTicks
from mx.DateTime import ARPA
from mx.DateTime import now
from mx.DateTime import strptime
from mx.DateTime.Timezone import zonetable
from newDateTimeZone import _TimeZoneMapper
import time,types
from time import localtime
class DateTime:
__roles__=None
__allow_access_to_unprotected_subobjects__=1
def __init__(self,*args):
if len(args) == 0 or (len(args) > 0 and args[0] == None):
self.dt = mxTimestampFromTicks(time.time())
elif ( type(args[0]) is types.FloatType or
type(args[0]) is types.IntType and len(args) == 1):
self.dt = mxTimestampFromTicks(args[0])
elif type(args[0]) is types.StringType and len(args) == 1:
self.dt = mxDateTimeFrom(args[0])
elif ( type(args[0]) is types.StringType and
type(args[0]) is types.StringType and len(args) == 2):
self.dt = strptime(args[0], args[1])
else:
self.dt = apply(mxDateTime,args)
for x in dir(self.dt):
setattr(self,x,getattr(self.dt,x))
def strftime(self,fmt): return self.dt.strftime(fmt)
def ISO(self): return self.dt.strftime('%04Y-%02m-%02d %02H:%02M:%02S')
def HTML4(self): return self.dt.strftime('%04Y-%02m-%02dT%02H:%02M:%02S%Z')
def rfc822(self): return ARPA.strGMT(self.dt)
def dow(self): return self.dt.day_of_week
def dayOfYear(self): return self.dt.day_of_year
def yy(self): return self.strftime('%02y')
def mm(self): return self.strftime('%02m')
def dd(self): return self.strftime('%02d')
def h_24(self): return self.strftime('%02H')
def h_12(self): return self.strftime('%02I')
def ampm(self): return self.strftime('%P')
def hour(self): return self.dt.hour
def minute(self): return self.dt.minute
def second(self): return int(self.dt.second)
def millis(self): return self.dt.second - int(self.dt.second)
def day(self): return self.dt.day
def month(self): return self.dt.month
def year(self): return self.dt.year
def timezone(self): return self.dt.timezone
def Day(self): return self.strftime('%A')
def DayOfWeek(self): return self.Day()
def aDay(self): return self.strftime('%a')
def pDay(self): return self.strftime('%a.')
def Day_(self): return self.pDay()
def dow(self): return self.strftime('%w')
def dow_1(self): return self.dow()+1
def Month(self): return self.strftime('%B')
def aMonth(self): return self.strftime('%b')
def Mon(self): return self.aMonth()
def pMonth(self): return self.strftime('%b.')
def Mon_(self): return self.pMonth()
def isLeapYear(self): return self.dt.is_leapyear
def timeTime(self): return self.dt.gmticks()
def toZone(self, z): return self.dt + mxTime(zonetable[z])
def isFuture(self): return self.dt > now()
def isPast(self): return self.dt < now()
def isCurrentYear(self): return self.dt.year == now().year
def isCurrentMonth(self): return self.isCurrentYear() and self.dt.month == now().month
def isCurrentDay(self): return self.date() and now().date()
def isCurrentHour(self): return self.isCurrentDay() and self.dt.hour == now.hour
def isCurrentMinute(self): return self.isCurrentHour() and self.dt.minute == now.minute
def earliestTime(self): return mxDateTime(self.dt.year, self.dt.month, self.dt.day)
def latestTime(self): return mxDateTime(self.dt.year, self.dt.month, self.dt.day, 23, 59, 59)
def greaterThan(self,t): return self.dt > t.dt
def greaterThanEqualTo(self,t): return self.dt >= t.dt
def equalTo(self,t): return self.dt == t.dt
def notEqualTo(self,t): return self.dt != t.dt
def lessThan(self,t): return self.dt < t.dt
def lessThanEqualTo(self,t): return self.dt <= t.dt
def parts(self): return self.dt.year, self.dt.month, self.dt.day, self.dt.hour, \
self.dt.minute, self.dt.second, self.dt.timezone
def localZone(self, ltm=None): pass
def Date(self): return self.strftime('%Y/%m/%d')
def Time(self): return self.strftime('%H:%M:%S')
def TimeMinutes(self): return self.strftime('%H:%M')
def AMPM(self): return self.strftime('%I:%M:%S %P')
def AMPMMinutes(self): return self.strftime('%I:%M %P')
def PreciseTime(self): return self.strftime('%H:%M:') + '%06.3f' %(self.dt.second)
def PreciseAMPM(self): return self.strftime('%I:%M:') + '%06.3f' %(self.dt.second) + self.strftime(' %P')
def fCommon(self): return self.strftime('%B %d, %Y %l:%M %P')
def fCommonZ(self): return self.strftime('%B %d, %Y %l:%M %P ') + self.dt.timezone
def aCommon(self): return self.strftime('%b %d, %Y %l:%M %P')
def aCommonZ(self): return self.strftime('%b %d, %Y %l:%M %P ') + self.dt.timezone
def pCommon(self): return self.strftime('%b. %d, %Y %l:%M %P')
def pCommonZ(self): return self.strftime('%b. %d, %Y %l:%M %P ') + self.dt.timezone
def __add__(self, other): return self.dt + other
__radd__ = __add__
def __sub__(self, other): return self.dt - other
def __int__(self): return int(self.dt.second)
def __long__(self): return long(self.dt.second)
def __float__(self): return self.dt.second
def __cmp__(self, dateTime):
try: return cmp(self.dt, dateTime.dt)
except AttributeError: return cmp(self.dt.ticks(), dateTime)
def __hash__(self):
return int(((self.dt.year%100*12 + self._month)*31 +
self.dt.day+self.hour)*100)
def __str__(self): return str(self.dt)
def __repr__(self): return self.dt
def __getattr__(self,fmt):
if '%' in fmt: return strftimeFormater(self.dt,fmt)
raise AttributeError,fmt
def Timezones():
"""Return the list of recognized timezone names"""
return _TimeZoneMapper._zoneList
class strftimeFormater:
def __init__(self,dt,fmt):
self.dt = dt
self.fmt = fmt
def __call__(self,*args):
return self.dt.strftime(self.fmt)
This diff is collapsed.
......@@ -84,13 +84,14 @@
##############################################################################
__doc__='''Application support
$Id: Application.py,v 1.152 2001/06/18 21:02:38 chrism Exp $'''
__version__='$Revision: 1.152 $'[11:-2]
$Id: Application.py,v 1.153 2001/06/19 15:33:10 andreas Exp $'''
__version__='$Revision: 1.153 $'[11:-2]
import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_
import time, traceback, os, string, Products
from string import strip, lower, find, rfind, join
from DateTime import DateTime
import DateTime
from AccessControl.User import UserFolder
from App.ApplicationManager import ApplicationManager
from webdav.NullResource import NullResource
......@@ -247,7 +248,8 @@ class Application(Globals.ApplicationDefaultPermissions,
def PrincipiaTime(self, *args):
"""Utility function to return current date/time"""
return apply(DateTime, args)
if len(args)==0: return DateTime.newDateTime()
else: return apply(DateTime.newDateTime, args)
ZopeTime=PrincipiaTime
ZopeAttributionButton__roles__=None
......
......@@ -83,7 +83,7 @@
#
##############################################################################
__version__='$Revision: 1.3 $'[11:-2]
__version__='$Revision: 1.4 $'[11:-2]
import string, math, random, whrandom
import DocumentTemplate.sequence
......@@ -97,8 +97,8 @@ utility_builtins['whrandom'] = whrandom
utility_builtins['sequence'] = DocumentTemplate.sequence
try:
import DateTime
utility_builtins['DateTime']=DateTime.DateTime
import DateTime.newDateTime
utility_builtins['DateTime']= DateTime.newDateTime
except: pass
def same_type(arg1, *args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment