本文整理汇总了Python中delorean.Delorean.next_year方法的典型用法代码示例。如果您正苦于以下问题:Python Delorean.next_year方法的具体用法?Python Delorean.next_year怎么用?Python Delorean.next_year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类delorean.Delorean
的用法示例。
在下文中一共展示了Delorean.next_year方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UtcDatetime
# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import next_year [as 别名]
class UtcDatetime(object):
"""Class for manage datetimes. The timezone is always internally in UTC. Its used for unify serialization
and ease complexity of manage datetimes with timezones. Always use this class for datetime management"""
def __init__(self, the_datetime, the_timezone):
"""the_datetime must be a datetime.datetime
the_timezone is a String identifing timezone: EX: 'Europe/Madrid' 'UTC' See: all_timezones"""
the_timezone = self._get_timezone_parameter(the_timezone)
self._delorean = Delorean(datetime=the_datetime, timezone=the_timezone).shift("UTC")
self._delorean.truncate('second') # Truncate to second, its the precission of serialize
@staticmethod
def get_all_timezones():
"""All timezones available"""
return all_timezones
@staticmethod
def get_current_utc_datetime():
"""Always call this method to get the current datetime.
Return UrcDateTime"""
delorean = Delorean()
return UtcDatetime(delorean.datetime, "UTC")
def datetime_in_timezone(self, the_timezone):
"""Gets the UTC timezone """
the_timezone = self._get_timezone_parameter(the_timezone)
tmp_delorean = Delorean(datetime=self._delorean.datetime)
return tmp_delorean.shift(the_timezone).datetime
def advance_in_time(self, periodicity):
"""Give us the future UtcDatetime traveling in time adding periodicity to self date"""
if periodicity.period == "YEAR":
return UtcDatetime(self._delorean.next_year(periodicity.frequency).datetime, "UTC")
elif periodicity.period == "MONTH":
return UtcDatetime(self._delorean.next_month(periodicity.frequency).datetime, "UTC")
elif periodicity.period == "DAY":
return UtcDatetime(self._delorean.next_day(periodicity.frequency).datetime, "UTC")
def back_in_time(self, periodicity):
"""Give us the past UtcDatetime traveling in time substracting periodicity to self date"""
if periodicity.period == "YEAR":
return UtcDatetime(self._delorean.last_year(periodicity.frequency).datetime, "UTC")
elif periodicity.period == "MONTH":
return UtcDatetime(self._delorean.last_month(periodicity.frequency).datetime, "UTC")
elif periodicity.period == "DAY":
return UtcDatetime(self._delorean.last_day(periodicity.frequency).datetime, "UTC")
@property
def to_iso8601(self):
return self.datetime_utc.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
@property
def datetime_utc(self):
"""datetime object in UTC"""
return self._delorean.datetime
@property
def date_utc(self):
"""date object in UTC"""
return self._delorean.date
@staticmethod
def deserialize(data):
"""deserialize model"""
if data is None:
return None
return UtcDatetime(data, "UTC")
def serialize(self):
"""serialize model
NOTE: It serialize for pymongo datetime compatibility not for a string based interface like REST"""
return self._delorean.datetime
def __eq__(self, other):
"""equal method"""
if self is other:
return True
return isinstance(other, self.__class__) \
and self._delorean == other._delorean
def __ne__(self, other):
"""not equal method"""
return not self.__eq__(other)
def __lt__(self, other):
"""< operation"""
return self._delorean.datetime < other._delorean.datetime
def __le__(self, other):
"""<= operation"""
return self._delorean.datetime <= other._delorean.datetime
def __gt__(self, other):
"""> operation"""
return self._delorean.datetime > other._delorean.datetime
def __ge__(self, other):
""">= operation"""
return self._delorean.datetime >= other._delorean.datetime
#.........这里部分代码省略.........
示例2: DeloreanTests
# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import next_year [as 别名]
#.........这里部分代码省略.........
def test_move_month(self):
dt_next = datetime(2013, 2, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_next_2 = datetime(2013, 3, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_last = datetime(2012, 12, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_last_2 = datetime(2012, 11, 3, 4, 31, 14, 148546, tzinfo=utc)
d_obj_next = self.do.next_month()
d_obj_next_2 = self.do.next_month(2)
d_obj_last = self.do.last_month()
d_obj_last_2 = self.do.last_month(2)
self.assertEqual(dt_next, d_obj_next.datetime)
self.assertEqual(dt_last, d_obj_last.datetime)
self.assertEqual(dt_next_2, d_obj_next_2.datetime)
self.assertEqual(dt_last_2, d_obj_last_2.datetime)
def test_move_month_function(self):
dt_next = datetime(2013, 2, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_last = datetime(2012, 12, 3, 4, 31, 14, 148546, tzinfo=utc)
d_obj_next = move_datetime_month(self.do.datetime, 'next', 1)
d_obj_last = move_datetime_month(self.do.datetime, 'last', 1)
self.assertEqual(dt_next, d_obj_next)
self.assertEqual(dt_last, d_obj_last)
def test_move_year(self):
dt_next = datetime(2014, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_next_2 = datetime(2015, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_last = datetime(2012, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_last_2 = datetime(2011, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
d_obj_next = self.do.next_year()
d_obj_next_2 = self.do.next_year(2)
d_obj_last = self.do.last_year()
d_obj_last_2 = self.do.last_year(2)
self.assertEqual(dt_next, d_obj_next.datetime)
self.assertEqual(dt_last, d_obj_last.datetime)
self.assertEqual(dt_next_2, d_obj_next_2.datetime)
self.assertEqual(dt_last_2, d_obj_last_2.datetime)
def test_move_year_function(self):
dt_next = datetime(2014, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
dt_last = datetime(2012, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
d_obj_next = move_datetime_year(self.do.datetime, 'next', 1)
d_obj_last = move_datetime_year(self.do.datetime, 'last', 1)
self.assertEqual(dt_next, d_obj_next)
self.assertEqual(dt_last, d_obj_last)
def test_range_count(self):
"""
tests the range method with count used
"""
count = list(stops(DAILY, count=5))
self.assertEqual(len(count), 5)
def test_range_with_start(self):
dates1 = []
for do in stops(DAILY, count=5, start=datetime.utcnow()):
do.truncate('minute')
dates1.append(do)
do = Delorean().truncate('minute')