我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用datetime.time.max()。
def test_can_issue_daily(self): """ Tests can_issue_daily method Decides if the daily report surveys can be sent out or not """ self.assertTrue(self.report.can_issue_daily()) # if daily report isn't issued, should be True self.report.survey_send_time = time.max self.assertFalse(self.report.can_issue_daily()) # if hour is later than current time, don't issue self.report.survey_send_time = time.min self.report.get_daily() # create daily report self.assertFalse(self.report.can_issue_daily(), "Assumed after daily report is created the daily report has already been sent")
def limit_remaining(self): limit = self.profile('limit_post') # If False is returned, no post limit is assumed. if limit == 0: return False today_min = timezone.datetime.combine(timezone.datetime.today(), time.min) today_max = timezone.datetime.combine(timezone.datetime.today(), time.max) # recent_posts = # Posts made by the user today + posts made by the IP today + # same thing except with comments recent_posts = Post.real.filter(Q(creator=self.id, created__range=(today_min, today_max)) | Q(creator__addr=self.addr, created__range=(today_min, today_max))).count() + Comment.real.filter(Q(creator=self.id, created__range=(today_min, today_max)) | Q(creator__addr=self.addr, created__range=(today_min, today_max))).count() # Posts remaining return int(limit) - recent_posts
def _daysplitinterval(starttime, endtime): """ Splits an interval into a list of dates, start times and end times Parameters ---------- starttime : datetime Start date/time of interval endtime : datetime End date/time of interval Returns ------- intervals : list A list of lists. Each item in the sublists consists of the date, start time, and end time for the particular date. """ assert starttime < endtime, 'Start datetime must be before end datetime' out = [] starttime_orig = starttime while starttime.date() <= endtime.date(): if starttime.date() == starttime_orig.date(): stime = starttime.time() else: stime = time.min if starttime.date() == endtime.date(): etime = endtime.time() else: etime = time.max out.append([starttime.date(), stime, etime]) starttime += timedelta(days=1) return out
def _load(probe, starttime, endtime, instrument, product_id, cdfkeys): daylist = helper._daysplitinterval(starttime, endtime) data = [] for day in daylist: date = day[0] year = str(date.year) month = str(date.month).zfill(2) day = str(date.day).zfill(2) local_dir = os.path.join(cluster_dir, 'c' + probe, instrument, year) local_fname = 'C' + probe + '_' + product_id + '__' +\ year + month + day + '.cdf' # If we don't have local file download it if not os.path.exists(os.path.join(local_dir, local_fname)): thisstart = datetime.combine(date, time.min) thisend = datetime.combine(date, time.max) try: _download(probe, thisstart, thisend, instrument, product_id) except Exception as err: print(str(err), '\n') continue from pycdf import pycdf cdf = pycdf.CDF(os.path.join(local_dir, local_fname)) for key, value in cdfkeys.items(): if value == 'Time': index_key = key break data.append(helper.cdf2df(cdf, index_key, cdfkeys)) if len(data) == 0: raise RuntimeError('No data available to download during requested ' 'times') return helper.timefilter(data, starttime, endtime)
def get_govuk_capture_time(self, govuk_payment): try: capture_submit_time = parse_datetime( govuk_payment['settlement_summary'].get('capture_submit_time', '') ) captured_date = parse_date( govuk_payment['settlement_summary'].get('captured_date', '') ) if captured_date is not None: capture_submit_time = ( capture_submit_time or timezone.now() ).astimezone(timezone.utc) if capture_submit_time.date() < captured_date: return datetime.combine( captured_date, time.min ).replace(tzinfo=timezone.utc) elif capture_submit_time.date() > captured_date: return datetime.combine( captured_date, time.max ).replace(tzinfo=timezone.utc) else: return capture_submit_time except (KeyError, TypeError): pass raise GovUkPaymentStatusException( 'Capture date not yet available for payment %s' % govuk_payment['reference'] )
def get_queryset(self): """returns actions""" start_date = self.request.GET.get('start') end_date = self.request.GET.get('end') if not start_date or not end_date: raise ParseError("Period frame missing") queryset = self.model.objects.all() queryset = self._apply_in_action_type_lookup(queryset) queryset = self._apply_in_charge_lookup(queryset) try: start_date = self._parse_date(start_date) end_date = self._parse_date(end_date) except ValueError: raise ParseError("Invalid period frame") start_datetime = datetime.combine(start_date, time.min) end_datetime = datetime.combine(end_date, time.max) if end_datetime < start_datetime: return self.model.objects.none() queryset = queryset.filter( Q(planned_date__lte=start_datetime, end_datetime__gte=end_datetime) | # starts before, ends after period Q(planned_date__gte=start_datetime, end_datetime__lte=end_datetime) | # starts and ends during period Q(planned_date__lte=start_datetime, end_datetime__gte=start_datetime) | # starts before, ends during Q(planned_date__lte=end_datetime, end_datetime__gte=end_datetime) | # starts during period, ends after Q( planned_date__gte=start_datetime, end_datetime__isnull=True, planned_date__lte=end_datetime ) # no end, starts during period ) return queryset
def _get_datetimes(self): """return selected date times""" start_date, end_date = get_date_bounds(self.value) return datetime.combine(start_date, time.min), datetime.combine(end_date, time.max)
def queryset(self, request, queryset): daystart = timezone.make_aware(datetime.combine(timezone.localdate(), time.min)) dayend = timezone.make_aware(datetime.combine(timezone.localdate(), time.max)) # using daystart and dayend because I can't directly filter using start_date.day if self.value() == 'today': return queryset.filter(start_date__gte=daystart, start_date__lte=dayend) if self.value() == 'tomorrow': daystart += timedelta(days=1) dayend += timedelta(days=1) return queryset.filter(start_date__gte=daystart, start_date__lte=dayend) if self.value() == 'week': dayend += timedelta(days=7) return queryset.filter(start_date__gte=daystart, start_date__lte=dayend) if self.value() == 'month': dayend += timedelta(days=30) return queryset.filter(start_date__gte=daystart, start_date__lte=dayend) if self.value() == 'last_week': daystart -= timedelta(days=7) return queryset.filter(start_date__gte=daystart, start_date__lte=dayend) # no else to allow fall through to return all
def end_time(self, time_part=time.max): return datetime.combine(self.end_date, time_part).replace(tzinfo=timezone.utc)