本文整理汇总了Python中DateTime.DateTime.year方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.year方法的具体用法?Python DateTime.year怎么用?Python DateTime.year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime.DateTime
的用法示例。
在下文中一共展示了DateTime.year方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: showTimeFrame
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def showTimeFrame(self,obj):
s = DateTime(obj.getValue('start-date'))
e = DateTime(obj.getValue('end-date'))
if s.year() == e.year() and s.month() == e.month() and \
s.day() == e.day() and s.hour() == e.hour() and s.minute() == e.minute():
return False
return True
示例2: __init__
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def __init__(self, context, request):
super(TimeReports, self).__init__(context, request)
self.ettool = getToolByName(self.context, 'extropy_timetracker_tool')
start = self.request.get('startdate', None)
if not start:
now = DateTime()
# Default to showing the current year. During January we still
# include the last year, as we usually still write bills for that
# period.
if now.month() > 1:
start = '%s-01-01' % now.year()
else:
start = '%s-01-01' % (now.year() - 1)
start = DateTime(start)
self.start = start.earliestTime()
end = self.request.get('enddate', None)
end = end and DateTime(end) or DateTime()
self.end = end.latestTime()
self.query_string = make_query(*(
{key: self.request[key]}
for key in ('Creator', 'getBudgetCategory', 'startdate', 'enddate')
if key in self.request))
self.query_string = self.query_string and '?' + self.query_string
示例3: results
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def results(self, start, until=None):
today = DateTime()
today = DateTime(today.year(), today.month(), today.day())
start = DateTime(start)
start = DateTime(start.year(), start.month(), start.day())
query = Indexed('chimpfeeds') & \
In('review_state', ('published', )) & \
Ge('feedSchedule', start)
if until:
try:
until = DateTime(until)
except DateTime.SyntaxError:
pass
else:
query = query & Le('feedSchedule', until)
site = getToolByName(self.context, "portal_url").getPortalObject()
settings = IFeedSettings(site)
if settings.use_moderation:
query = query & Eq('feedModerate', True)
catalog = getToolByName(self.context, "portal_catalog")
extras = []
utilities = getUtilitiesFor(IGroupExtras)
groups = InterestGroupVocabulary()(self.context)
for name, util in utilities:
for group in groups:
extras.extend(util.items(group.title, start, until))
return list(catalog.evalAdvancedQuery(
query, (('feedSchedule', 'desc'), ))) + extras
示例4: get_events
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def get_events(self, year=None, month=None, day=None):
""" search in objects with meta_type='RDF Summary' and return events
list with events going on in given 'month' and 'year'
"""
# Retrieve the value from the cache.
keyset = None
if self.ZCacheable_isCachingEnabled():
# Strange; I can't just use args
keyset = { 'year':year, 'month':month, 'day':day }
# Prepare a cache key.
results = self.ZCacheable_get(view_name='get_events',
keywords=keyset, default=_marker)
if results is not _marker:
return results
events = []
for object in self.objectValues('RDF Summary'):
for item in object.items():
if not item.has_key('startdate') or item['startdate'] == '':
continue
try:
startdate=DateTime(item['startdate'])
except:
continue
if item.has_key('enddate') and item.get('enddate', '').strip() != '':
enddate=DateTime(item['enddate'])
else:
enddate=startdate
if not year:
year1=startdate.year()
year2=enddate.year()
else:
year1=year2=year
if not month:
month1=startdate.month()
month2=enddate.month()
else:
month1=month2=month
if not day:
day1=1
day2=calendar.monthrange(year2,month2)[-1]
else:
day1=day2=day
enddate=enddate.Date()
startdate=startdate.Date()
date1=DateTime("%s/%s/%s" % (str(year1), str(month1), str(day1))).Date()
date2=DateTime("%s/%s/%s" % (str(year2), str(month2), str(day2))).Date()
if (startdate<=date1 and enddate>=date1) or \
(startdate>=date1 and enddate<=date2) or \
(startdate<=date2 and enddate>=date2) or \
(startdate<=date1 and enddate>=date2):
events.append(item)
if keyset is not None:
if events is not None:
self.ZCacheable_set(events,view_name='get_events', keywords=keyset)
return events
示例5: _dt_setter
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def _dt_setter(self, fieldtoset, value, **kwargs):
# Always set the date in UTC, saving the timezone in another field.
# But since the timezone value isn't known at the time of saving the
# form, we have to save it timezone-naive first and let
# timezone_handler convert it to the target zone afterwards.
# Note: The name of the first parameter shouldn't be field, because
# it's already in kwargs in some case.
if not isinstance(value, DateTime): value = DateTime(value)
# Get microseconds from seconds, which is a floating value. Round it
# up, to bypass precision errors.
micro = int(round(value.second()%1 * 1000000))
value = DateTime('%04d-%02d-%02dT%02d:%02d:%02d%sZ' % (
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second(),
micro and '.%s' % micro or ''
)
)
self.getField(fieldtoset).set(self, value, **kwargs)
示例6: getMonthCal
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def getMonthCal(self, index=0):
now = DateTime()
year, month = now.year(), now.month()
year = year + (month + index - 1)/12
month = (month + index -1) % 12 + 1
return {'name': month, 'month':month, 'days':calendar.monthcalendar(year, month)}
示例7: specialActivities
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def specialActivities(self):
sactivities = []
ftoday = DateTime()
today = DateTime('/'.join([str(ftoday.year()), str(ftoday.month()), str(ftoday.day())]))
start_date = today
end_date = today + 0.9
folderS = getSite().unrestrictedTraverse('actividades/actividades-especiales')
brainscuerS = {'Cuernavaca': self.criteriaActivities(start_date, end_date, ['/'.join(folderS.getPhysicalPath())+'/cuernavaca'])}
brainsjurS = {'Juriquilla': self.criteriaActivities(start_date, end_date, ['/'.join(folderS.getPhysicalPath())+'/juriquilla'])}
brainsoaxS = {'Oaxaca': self.criteriaActivities(start_date, end_date, ['/'.join(folderS.getPhysicalPath())+'/oaxaca'])}
for items in [brainscuerS, brainsjurS, brainsoaxS]:
campus = items.keys()[0]
brains = items[campus]
for item in brains:
data = {}
data['startf'] = self.date_speller(item.start)
data['date'] = item.start
data['expositor'] = item.getSpeaker
data['title'] = item.pretty_title_or_id()
data['location'] = item.location
data['hour'] = str(data['startf']['hour']) + ':' + str(data['startf']['minute']) + ' hrs.'
value = ''
if item.Subject:
value = item.Subject[0]
data['seminarytitle'] = value
data['campus'] = campus
sactivities.append(data)
return sactivities
示例8: tvActivities
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def tvActivities(self):
ftoday = DateTime()
today = DateTime('/'.join([str(ftoday.year()), str(ftoday.month()), str(ftoday.day())]))
start_date = today
end_date = today + 0.9
foldercu = self.pathcu()
brainscu = self.criteriaActivities(start_date, end_date, foldercu)
folderjur = self.pathjur()
brainsjur = self.criteriaActivities(start_date, end_date, folderjur)
iso_start = start_date.ISO().split('-')
day_start = iso_start[2].split('T')
iso_end = end_date.ISO().split('-')
day_end = iso_end[2].split('T')
return {
'brainscu': brainscu,
'start_date': '/'.join([day_start[0], iso_start[1], iso_start[0]]),
'end_date': '/'.join([day_end[0], iso_end[1], iso_end[0]]),
'matcuerrss': self.semanaryRSS(self.matcuerfeed, start_date, end_date),
'oaxrss': self.semanaryRSS(self.oaxfeed, start_date, end_date),
'brainsjur': brainsjur,
}
示例9: getDateRangeFromWeek
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def getDateRangeFromWeek(self, start_week, start_year, end_week=None, end_year=None):
"""Returns tuple of DateTime. Compute this tuple from weeks. A week
begins monday and ends sunday.
"""
if end_week is None:
end_week = start_week
if end_year is None:
end_year = start_year
# Get first day of start year
date_first_day = DateTime(start_year, 1, 1)
day_minus = (date_first_day.dow() - 1) % 7
day_plus = 0
start_day = (start_week * 7) - 6 - day_minus
start_date = DateTime(start_year, start_day)
if start_date.week() != start_week:
day_plus = 7
start_date = start_date + day_plus
# Get first day of end year
date_first_day = DateTime(end_year, 1, 1)
day_minus = (date_first_day.dow() - 1) % 7
end_day = (end_week * 7) - day_minus + day_plus
end_date = DateTime(end_year, end_day)
# Finished at 23:59:59
end_date = DateTime(end_date.year(),
end_date.month(),
end_date.day(),
23, 59, 59)
return (start_date, end_date)
示例10: _calculate_two_weeks
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def _calculate_two_weeks():
two_weeks = [[None] * 7, [None] * 7]
brains = portal_catalog.searchResults(
{'path' : path,
'portal_type': 'Milestone',
'end': {"query": [today, today+14], "range": "minmax"},
},
)
_upcoming = {}
for b in brains:
end = b.end
end = DateTime(end.year(), end.month(), end.day())
_upcoming.setdefault(end, []).append(b)
day = today
for i in range(2):
for j in range(7):
two_weeks[i][j] = {}
two_weeks[i][j]["day"] = day.day()
if _upcoming.has_key(day):
two_weeks[i][j]["its"] = _upcoming[day]
day += 1
nextday = today+1
two_weeks[0][0]["day"] = "TODAY"
two_weeks[0][0]["is_today"] = True
two_weeks[0][1]["day"] = "%s %d" % (nextday.aMonth(), nextday.day())
return two_weeks
示例11: render_view
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def render_view(self, field, value):
if value is None:
return ''
use_ampm = field.get_value('ampm_time_style')
if not isinstance(value, DateTime):
value = DateTime(value)
year = "%04d" % value.year()
month = "%02d" % value.month()
day = "%02d" % value.day()
if use_ampm:
hour = "%02d" % value.h_12()
else:
hour = "%02d" % value.hour()
minute = "%02d" % value.minute()
ampm = value.ampm()
order = field.get_value('input_order')
if order == 'ymd':
output = [year, month, day]
elif order == 'dmy':
output = [day, month, year]
elif order == 'mdy':
output = [month, day, year]
date_result = string.join(output, field.get_value('date_separator'))
if not field.get_value('date_only'):
time_result = hour + field.get_value('time_separator') + minute
if use_ampm:
time_result += ' ' + ampm
return date_result + ' ' + time_result
else:
return date_result
示例12: getBlogItemsForMonth
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def getBlogItemsForMonth(self, year = None, month = None):
"""
Return blog objects with given year and month. Month can
be 'Jan' or 1
"""
result = []
now = DateTime()
objects = self.objectValues(METATYPE_BLOGITEM)
if year:
year = int(year)
if not year and month:
year = now.year()
if month: #name to int
try:
month = DateTime("1 %s 2008" % month).month()
except:
raise ValueError("Invalid month %r" % month)
for object in objects:
publish_date = object.getPublishDate()
if year and month:
if publish_date.year() == year and publish_date.month() == month:
result.append(object)
if year and not month:
if publish_date.year() == year:
result.append(object)
return result
示例13: post_validate
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def post_validate(self, REQUEST=None, errors=None):
"""Validates start and end date
End date must be after start date
"""
if 'startDate' in errors or 'endDate' in errors:
# No point in validating bad input
return
rstartDate = REQUEST.get('startDate', None)
rendDate = REQUEST.get('endDate', None)
if rstartDate:
try:
start = DateTime(rstartDate)
except:
errors['startDate'] = _(u'error_invalid_start_date',
default=u'Start date is not valid.')
# set end > start
# TODO: add duration selection
endHour = start.h_24()
endMinute = start.minute() + config.DURATION
while endMinute > 59:
endHour = endHour+1
endMinute = endMinute-60
if endHour > 23:
endHour = 23
endMinute = 55
end = DateTime(start.year(),start.month(),start.day(),endHour,endMinute)
self.getField('endDate').set(self, end)
示例14: now_no_seconds
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def now_no_seconds(self):
""" return current date and time with the seconds truncated
"""
now = DateTime()
return DateTime(str(now.year())+'/'+str(now.month())+'/'+\
str(now.day())+' '+str(now.hour())+':'+str(now.minute())+' '+\
str(now.timezone()))
示例15: create_invoices
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import year [as 别名]
def create_invoices(self):
invoicedate = DateTime(self.request.get('recurring_invoices_date'))
ledger = self.context.getLedger()
templates = ledger.invoicetemplates
for template in templates.objectValues('InvoiceTemplate'):
invoice_id = str(ledger.getNextInvoiceNumber())
self.context.invokeFactory(id=invoice_id, type_name='Invoice')
invoice = getattr(self.context, invoice_id)
invoice.edit(
CustomerAccount=template.getCustomerAccount(),
title='%s (%s, %s)' % (
invoice_id, invoicedate.Month(), invoicedate.year()),
InvoiceDate=invoicedate,
CalculateTax=template.getCalculateTax(),
InvoiceCurrency=template.getInvoiceCurrency(),
ExchangeRate=template.getExchangeRate(),
Notes=template.getNotes(),
)
cp = template.manage_copyObjects(ids=template.objectIds(
'InvoiceItem'))
invoice.manage_pasteObjects(cp)
# update the id counter
invoice._id_counter = template._id_counter
return self.request.RESPONSE.redirect(self.context.absolute_url())