Back to index

plone3  3.1.7
extract_date_components.py
Go to the documentation of this file.
00001 ## Script (Python) "extract_date_compnents"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=date=None
00008 ##title=
00009 ##
00010 # this script extracts %Y %m %d %H %M from a given date string
00011 
00012 context.plone_log("The extract_date_components script is deprecated and will "
00013                   "be removed in Plone 4.0.")
00014 
00015 from DateTime import DateTime
00016 from ZODB.POSException import ConflictError
00017 
00018 try:
00019     date = DateTime(date)
00020 except ConflictError:
00021     raise
00022 except: #Combination of string/instances can be raised. catch all.
00023     pass
00024 
00025 try:
00026     day = date.strftime('%d');
00027 except AttributeError:
00028     day = '00'
00029 
00030 try:
00031     month = date.strftime('%m');
00032 except AttributeError:
00033     month = '00'
00034 
00035 try:
00036     year = date.strftime('%Y');
00037 except AttributeError:
00038     year = '00'
00039 
00040 try:
00041     hour = date.strftime('%H');
00042 except AttributeError:
00043     hour = '00'
00044 
00045 try:
00046     minute = date.strftime('%M');
00047 except AttributeError:
00048     minute = '00'
00049 
00050 try:
00051     ampm = date.strftime('%p');
00052 except AttributeError:
00053     ampm = '00'
00054 
00055 return {'year':year, 'month':month,
00056         'day':day, 'hour':hour,
00057         'minute':minute, 'ampm':ampm}