本文整理汇总了Python中delorean.Delorean.last_day方法的典型用法代码示例。如果您正苦于以下问题:Python Delorean.last_day方法的具体用法?Python Delorean.last_day怎么用?Python Delorean.last_day使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类delorean.Delorean
的用法示例。
在下文中一共展示了Delorean.last_day方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UtcDatetime
# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import last_day [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
#.........这里部分代码省略.........