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


Python Delorean.naive方法代码示例

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


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

示例1: test_naive

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import naive [as 别名]
 def test_naive(self):
     dt1 = Delorean()
     dt_naive = dt1.naive()
     self.assertEqual(dt_naive.tzinfo, None)
开发者ID:shussain,项目名称:delorean,代码行数:6,代码来源:test_data.py

示例2: UtcDatetime

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

#.........这里部分代码省略.........
        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

    def __sub__(self, other):
        """Returns a timedelta"""
        return self._delorean.datetime - other._delorean.datetime

    def _get_timezone_parameter(self, the_timezone):
        """Gets a valid timezone parameter or raise"""
        if the_timezone == "PST":  # Very common
            return "PST8PDT"
        if the_timezone not in self.get_all_timezones():
            raise ValueError("%s is not a valid timezone" % the_timezone)
        return the_timezone

    def __repr__(self):
        return "%s %s" % (self._delorean.naive(), self._delorean.timezone())
开发者ID:biicode,项目名称:bii-server,代码行数:104,代码来源:utc_datetime.py

示例3: DeloreanTests

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import naive [as 别名]
class DeloreanTests(TestCase):

    def setUp(self):
        date1 = datetime(2013, 1, 3, 4, 31, 14, 148546)
        self.do = Delorean(datetime=date1, timezone="UTC")

    def test_truncation_hour(self):
        """
        Tests that truncate always works
        """
        self.do.truncate('hour')
        self.assertEqual(self.do.naive(), datetime(2013, 1, 3, 4, 0))

    def test_truncation_second(self):
        """
        Tests that truncate always works
        """
        self.do.truncate('second')
        self.assertEqual(self.do.naive(), datetime(2013, 1, 3, 4, 31, 14, 0))

    def test_truncation_minute(self):
        """
        Tests that truncate always works
        """
        self.do.truncate('minute')
        self.assertEqual(self.do.naive(), datetime(2013, 1, 3, 4, 31, 0, 0))

    def test_truncation_day(self):
        """
        Tests that truncate always works
        """
        self.do.truncate('day')
        self.assertEqual(self.do.naive(), datetime(2013, 1, 3, 0, 0, 0, 0))

    def test_truncation_month(self):
        """
        Tests that truncate always works
        """
        self.do.truncate('month')
        self.assertEqual(self.do.naive(), datetime(2013, 1, 1, 0, 0, 0, 0))

    def test_truncation_year(self):
        """
        Tests that truncate always works
        """
        self.do.truncate('year')
        self.assertEqual(self.do.naive(), datetime(2013, 1, 1, 0, 0, 0, 0))

    def test_date(self):
        self.assertEqual(self.do.date, date(2013, 1, 3))

    def test_datetime(self):
        self.assertEqual(self.do.naive(), datetime(2013, 1, 3, 4, 31, 14, 148546))

    def test_naive(self):
        dt1 = Delorean()
        dt_naive = dt1.naive()
        self.assertEqual(dt_naive.tzinfo, None)

    def test_naive_timezone(self):
        dt1 = Delorean(timezone="US/Eastern").truncate('second').naive()
        dt2 = Delorean().truncate('second').naive()
        self.assertEqual(dt2, dt1)
        self.assertEqual(dt1.tzinfo, None)

    def test_localize(self):
        dt = datetime.today()
        utc = timezone("UTC")
        dt = localize(dt, "UTC")
        self.assertEqual(dt.tzinfo, utc)

    def test_failure_truncation(self):
        self.assertRaises(ValueError, self.do.truncate, "century")

    def test_normalize(self):
        dt1 = Delorean()
        dt2 = Delorean(timezone="US/Eastern")
        dt1.truncate('minute')
        dt2.truncate('minute')
        dt_normalized = normalize(dt1.datetime, "US/Eastern")
        self.assertEqual(dt2.datetime, dt_normalized)

    def test_normalize_failure(self):
        naive_datetime = datetime.today()
        self.assertRaises(ValueError, normalize, naive_datetime, "US/Eastern")

    def test_localize_failure(self):
        dt1 = localize(datetime.utcnow(), "UTC")
        self.assertRaises(ValueError, localize, dt1, "UTC")

    def test_timezone(self):
        utc = timezone('UTC')
        do_timezone = Delorean().timezone()
        self.assertEqual(utc, do_timezone)

    def test_datetime_timezone_default(self):
        do = Delorean()
        do.truncate('minute')
        dt1 = datetime_timezone(UTC)
        self.assertEqual(dt1.replace(second=0, microsecond=0), do.datetime)
#.........这里部分代码省略.........
开发者ID:shussain,项目名称:delorean,代码行数:103,代码来源:test_data.py


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