本文整理汇总了Python中DateTime.DateTime.month方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.month方法的具体用法?Python DateTime.month怎么用?Python DateTime.month使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime.DateTime
的用法示例。
在下文中一共展示了DateTime.month方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: showTimeFrame
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [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: getMonthGrid
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def getMonthGrid(self, month):
'''Creates a list of lists of DateTime objects representing the calendar
grid to render for a given p_month.'''
# Month is a string "YYYY/mm".
currentDay = DateTime('%s/01 12:00' % month)
currentMonth = currentDay.month()
res = [[]]
dayOneNb = currentDay.dow() or 7 # This way, Sunday is 7 and not 0.
if dayOneNb != 1:
previousDate = DateTime(currentDay)
# If the 1st day of the month is not a Monday, start the row with
# the last days of the previous month.
for i in range(1, dayOneNb):
previousDate = previousDate - 1
res[0].insert(0, previousDate)
finished = False
while not finished:
# Insert currentDay in the grid
if len(res[-1]) == 7:
# Create a new row
res.append([currentDay])
else:
res[-1].append(currentDay)
currentDay = currentDay + 1
if currentDay.month() != currentMonth:
finished = True
# Complete, if needed, the last row with the first days of the next
# month.
if len(res[-1]) != 7:
while len(res[-1]) != 7:
res[-1].append(currentDay)
currentDay = currentDay + 1
return res
示例3: results
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [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_query
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def get_query(self):
query = {
'object_provides': 'ftw.news.interfaces.INews',
'sort_on': 'start',
'sort_order': 'reverse',
'path': '/'.join(self.context.getPhysicalPath())
}
datestring = self.request.get('archive')
if datestring:
try:
start = DateTime(datestring)
except DateTime.interfaces.SyntaxError:
raise
end = DateTime('{0}/{1}/{2}'.format(
start.year() + start.month() / 12,
start.month() % 12 + 1,
1)
) - 1
query['start'] = {
'query': (start.earliestTime(), end.latestTime()),
'range': 'minmax',
}
return query
示例5: issueInvoice
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def issueInvoice(self, REQUEST=None, RESPONSE=None):
""" issue invoice
"""
# check for an adhoc invoice batch for this month
now = DateTime()
batch_month = now.strftime("%b %Y")
batch_title = "%s - %s" % (batch_month, "ad hoc")
invoice_batch = None
for b_proxy in self.portal_catalog(portal_type="InvoiceBatch", Title=batch_title):
invoice_batch = b_proxy.getObject()
if not invoice_batch:
first_day = DateTime(now.year(), now.month(), 1)
start_of_month = first_day.earliestTime()
last_day = first_day + 31
while last_day.month() != now.month():
last_day = last_day - 1
end_of_month = last_day.latestTime()
invoices = self.invoices
batch_id = invoices.generateUniqueId("InvoiceBatch")
invoices.invokeFactory(id=batch_id, type_name="InvoiceBatch")
invoice_batch = invoices._getOb(batch_id)
invoice_batch.edit(title=batch_title, BatchStartDate=start_of_month, BatchEndDate=end_of_month)
invoice_batch.processForm()
client_uid = self.getClientUID()
invoice_batch.createInvoice(client_uid, [self])
RESPONSE.redirect("%s/analysisrequest_invoice" % self.absolute_url())
示例6: get_events
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [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
示例7: getAge
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def getAge(self):
"""age"""
birth = self.getPersonal_birthdate()
if birth is None:
return ""
now = DateTime()
year = now.year() - birth.year()
if now.month() < birth.month() or (now.month() == birth.month() and now.day() < birth.day()):
year = year -1
return str(year)+" años"
示例8: extend_query_by_date
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def extend_query_by_date(query, datestring, date_field):
try:
start = DateTime(datestring)
except dtSytaxError:
return query
end = DateTime('%s/%s/%s' % (start.year() + start.month() / 12,
start.month() % 12 + 1, 1))
end = end - 1
query[date_field] = {'query': (start.earliestTime(),
end.latestTime()),
'range': 'minmax'}
return query
示例9: getAntiquity
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def getAntiquity(self):
"""antiquity"""
antiquit = self.getCompany_employee_startdate()
if antiquit is None:
return ""
now = DateTime()
year = now.year() - antiquit.year()
if now.month() < antiquit.month() or (now.month() == antiquit.month() and now.day() < antiquit.day()):
year = year -1
return str(year)+" años"
示例10: getAge
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def getAge(self):
"""Return the age of the team member."""
birthdate = self.context.getBirthdate()
if birthdate is None:
return None
today = DateTime()
age = today.year() - birthdate.year()
# Apply correction when before birthday.
if (today.month() < birthdate.month() or
(today.month() == birthdate.month() and
today.day() < birthdate.day())):
age = age - 1
return age
示例11: __init__
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [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
示例12: purge_now
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def purge_now(self):
last_purge = self.last_purge()
now = DateTime()
if (not last_purge) or now - last_purge > 30 or now.month() != last_purge.month():
return True
else:
return False
示例13: render_view
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [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
示例14: getDateRangeFromWeek
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [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)
示例15: findXthDayOfMonth
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import month [as 别名]
def findXthDayOfMonth(self, date, day_name, pos):
"""
Return: date of the Xth day (day_name) of given date month.
date: DateTime
day_name: string
pos: int
return: DateTime (%y/%m/%d)
"""
month_number = date.month()
ref_date = DateTime('%s/%s/01'%(date.year(), date.month()))
while pos >= 0:
# decrease pos when the day name is found
if ref_date.Day() == day_name:
pos = pos - 1
#verify that we do not change the month
if ref_date.month() != month_number:
return 0
#cool, we find the day
if ref_date.Day() == day_name and pos == 0:
return ref_date
ref_date = ref_date + 1
return 0