当前位置: 首页>>代码示例>>Python>>正文


Python Delorean.last_month方法代码示例

本文整理汇总了Python中delorean.Delorean.last_month方法的典型用法代码示例。如果您正苦于以下问题:Python Delorean.last_month方法的具体用法?Python Delorean.last_month怎么用?Python Delorean.last_month使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在delorean.Delorean的用法示例。


在下文中一共展示了Delorean.last_month方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UtcDatetime

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import last_month [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

#.........这里部分代码省略.........
开发者ID:biicode,项目名称:bii-server,代码行数:103,代码来源:utc_datetime.py

示例2: DeloreanTests

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import last_month [as 别名]

#.........这里部分代码省略.........
        dt_next = datetime(2013, 1, 10, 4, 31, 14, 148546, tzinfo=utc)
        dt_next_2 = datetime(2013, 1, 17, 4, 31, 14, 148546, tzinfo=utc)
        dt_last = datetime(2012, 12, 27, 4, 31, 14, 148546, tzinfo=utc)
        dt_last_2 = datetime(2012, 12, 20, 4, 31, 14, 148546, tzinfo=utc)

        d_obj_next = self.do.next_week()
        d_obj_next_2 = self.do.next_week(2)
        d_obj_last = self.do.last_week()
        d_obj_last_2 = self.do.last_week(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_week_function(self):
        dt_next = datetime(2013, 1, 10, 4, 31, 14, 148546, tzinfo=utc)
        dt_last = datetime(2012, 12, 27, 4, 31, 14, 148546, tzinfo=utc)

        d_obj_next = move_datetime_week(self.do.datetime, 'next', 1)
        d_obj_last = move_datetime_week(self.do.datetime, 'last', 1)

        self.assertEqual(dt_next, d_obj_next)
        self.assertEqual(dt_last, d_obj_last)

    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)
开发者ID:shussain,项目名称:delorean,代码行数:70,代码来源:test_data.py


注:本文中的delorean.Delorean.last_month方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。