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


Python tzinfo.__new__方法代码示例

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


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

示例1: __new__

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def __new__(cls, offset, name=_Omitted):
            if not isinstance(offset, timedelta):
                raise TypeError("offset must be a timedelta")
            if name is cls._Omitted:
                if not offset:
                    return cls.utc
                name = None
            elif not isinstance(name, str):
                raise TypeError("name must be a string")
            if not cls._minoffset <= offset <= cls._maxoffset:
                raise ValueError(
                    "offset must be a timedelta "
                    "strictly between -timedelta(hours=24) and "
                    "timedelta(hours=24)."
                )
            return cls._create(offset, name) 
开发者ID:sdispater,项目名称:tomlkit,代码行数:18,代码来源:_compat.py

示例2: test_subclass_date

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def test_subclass_date(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.year + self.month

        args = 2003, 4, 14

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.toordinal(), dt2.toordinal())
        self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_datetime.py

示例3: test_subclass_time

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def test_subclass_time(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.hour + self.second

        args = 4, 5, 6

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.isoformat(), dt2.isoformat())
        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_datetime.py

示例4: _create

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def _create(cls, offset, name=None):
            self = tzinfo.__new__(cls)
            self._offset = offset
            self._name = name
            return self 
开发者ID:sdispater,项目名称:tomlkit,代码行数:7,代码来源:_compat.py

示例5: test_pickling_base

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def test_pickling_base(self):
        # There's no point to pickling tzinfo objects on their own (they
        # carry no data), but they need to be picklable anyway else
        # concrete subclasses can't be pickled.
        orig = tzinfo.__new__(tzinfo)
        self.assertIs(type(orig), tzinfo)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertIs(type(derived), tzinfo) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_datetime.py

示例6: test_subclass_datetime

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def test_subclass_datetime(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.year + self.month + self.second

        args = 2003, 4, 14, 12, 13, 41

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.toordinal(), dt2.toordinal())
        self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month +
                                          dt1.second - 7) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_datetime.py

示例7: test_subclass_timetz

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def test_subclass_timetz(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.hour + self.second

        args = 4, 5, 6, 500, FixedOffset(-300, "EST", 1)

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.utcoffset(), dt2.utcoffset())
        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7)


# Testing datetime objects with a non-None tzinfo. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:test_datetime.py

示例8: test_pickling_base

# 需要导入模块: from datetime import tzinfo [as 别名]
# 或者: from datetime.tzinfo import __new__ [as 别名]
def test_pickling_base(self):
        # There's no point to pickling tzinfo objects on their own (they
        # carry no data), but they need to be picklable anyway else
        # concrete subclasses can't be pickled.
        orig = tzinfo.__new__(tzinfo)
        self.assertTrue(type(orig) is tzinfo)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertTrue(type(derived) is tzinfo) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:12,代码来源:test_datetime.py


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