本文整理汇总了Python中arrow.Arrow.fromdate方法的典型用法代码示例。如果您正苦于以下问题:Python Arrow.fromdate方法的具体用法?Python Arrow.fromdate怎么用?Python Arrow.fromdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow.Arrow
的用法示例。
在下文中一共展示了Arrow.fromdate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_stop_datetime
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import fromdate [as 别名]
def clean_stop_datetime(self):
start = self.cleaned_data.get('start_datetime')
stop = self.cleaned_data['stop_datetime']
# Day entry can't stop before the start
if start and stop and stop <= start:
raise forms.ValidationError(_("Stop time can't be less or equal to start time"))
# Day entry can't stop in more than one futur day from the targeted day date
if stop and stop.date() > Arrow.fromdate(self.daydate).replace(days=1).date():
raise forms.ValidationError(_("Stop time can't be more than the next day"))
return stop
示例2: span
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import fromdate [as 别名]
def span(self, frame):
now = self._gen_now()
now_date = self._get_day_start()
this_n_days = self._get_n_unit(frame, 'this', 'days')
this_n_weeks = self._get_n_unit(frame, 'this', 'weeks')
this_n_months = self._get_n_unit(frame, 'this', 'months')
this_n_years = self._get_n_unit(frame, 'this', 'years')
previous_n_days = self._get_n_unit(frame, 'previous', 'days')
previous_n_weeks = self._get_n_unit(frame, 'previous', 'weeks')
previous_n_months = self._get_n_unit(frame, 'previous', 'months')
previous_n_years = self._get_n_unit(frame, 'previous', 'years')
if frame == 'today' or frame == 'this_day':
return self.span('this_1_days')
elif frame == 'this_week':
start = self._get_week_start()
return start, now
elif frame == 'this_month':
start = self._get_month_start()
return start, now
elif frame == 'this_year':
start = now_date.replace(month=1, day=1)
return start, now
elif len(this_n_days) == 1:
day = int(this_n_days[0])
start = now_date - datetime.timedelta(days=day - 1)
return start, now
elif len(this_n_weeks) == 1:
week = int(this_n_weeks[0])
start = self._get_week_start() - datetime.timedelta(weeks=week - 1)
return start, now
elif len(this_n_months) == 1:
s = self._get_month_start()
ar = Arrow.fromdate(s, s.tzinfo)
start = ar.replace(months=-(int(this_n_months[0]) - 1)).datetime
return start, now
elif len(this_n_years) == 1:
years = self._get_month_start().year - (int(this_n_years[0]) - 1)
start = self._get_month_start().replace(month=1, year=years)
return start, now
elif frame == 'yesterday' or frame == 'previous_day':
return self.span('previous_1_days')
elif frame == 'previous_week':
return self.span('previous_1_weeks')
elif frame == 'previous_month':
return self.span('previous_1_months')
elif frame == 'previous_year':
return self.span('previous_1_years')
elif len(previous_n_days) == 1:
days = previous_n_days[0]
start = now_date - datetime.timedelta(days=days)
end = now_date - datetime.timedelta(seconds=1)
return start, end
elif len(previous_n_weeks) == 1:
weeks = previous_n_weeks[0]
start = self._get_week_start() - datetime.timedelta(weeks=weeks)
end = self._get_week_start() - datetime.timedelta(seconds=1)
return start, end
elif len(previous_n_months) == 1:
s = self._get_month_start()
ar = Arrow.fromdate(s, s.tzinfo)
start = ar.replace(months=-previous_n_months[0]).datetime
end = s - datetime.timedelta(seconds=1)
return start, end
elif len(previous_n_years) == 1:
years = self._get_month_start().year - previous_n_years[0]
start = self._get_month_start().replace(year=years, month=1)
end = self._get_month_start().replace(month=1) - datetime.timedelta(seconds=1)
return start, end
示例3: arrow_parse
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import fromdate [as 别名]
def arrow_parse(t):
return Arrow.fromdate(parse(t))
示例4: _get_week_start
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import fromdate [as 别名]
def _get_week_start(self):
s = self.day_start
ar = Arrow.fromdate(s, s.tzinfo)
return ar.floor('week').datetime