xtquant.xtbson.bson36.tz_util
Timezone related utilities for BSON.
1# Copyright 2010-2015 MongoDB, Inc. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Timezone related utilities for BSON.""" 16 17from datetime import timedelta, tzinfo 18 19ZERO = timedelta(0) 20 21 22class FixedOffset(tzinfo): 23 """Fixed offset timezone, in minutes east from UTC. 24 25 Implementation based from the Python `standard library documentation 26 <http://docs.python.org/library/datetime.html#tzinfo-objects>`_. 27 Defining __getinitargs__ enables pickling / copying. 28 """ 29 30 def __init__(self, offset, name): 31 if isinstance(offset, timedelta): 32 self.__offset = offset 33 else: 34 self.__offset = timedelta(minutes=offset) 35 self.__name = name 36 37 def __getinitargs__(self): 38 return self.__offset, self.__name 39 40 def utcoffset(self, dt): 41 return self.__offset 42 43 def tzname(self, dt): 44 return self.__name 45 46 def dst(self, dt): 47 return ZERO 48 49 50utc = FixedOffset(0, "UTC") 51"""Fixed offset timezone representing UTC."""
ZERO =
datetime.timedelta(0)
class
FixedOffset(datetime.tzinfo):
23class FixedOffset(tzinfo): 24 """Fixed offset timezone, in minutes east from UTC. 25 26 Implementation based from the Python `standard library documentation 27 <http://docs.python.org/library/datetime.html#tzinfo-objects>`_. 28 Defining __getinitargs__ enables pickling / copying. 29 """ 30 31 def __init__(self, offset, name): 32 if isinstance(offset, timedelta): 33 self.__offset = offset 34 else: 35 self.__offset = timedelta(minutes=offset) 36 self.__name = name 37 38 def __getinitargs__(self): 39 return self.__offset, self.__name 40 41 def utcoffset(self, dt): 42 return self.__offset 43 44 def tzname(self, dt): 45 return self.__name 46 47 def dst(self, dt): 48 return ZERO
Fixed offset timezone, in minutes east from UTC.
Implementation based from the Python standard library documentation . Defining __getinitargs__ enables pickling / copying.
def
utcoffset(self, dt):
datetime -> timedelta showing offset from UTC, negative values indicating West of UTC
Inherited Members
- datetime.tzinfo
- fromutc
utc =
<xtquant.xtbson.bson36.tz_util.FixedOffset object>
Fixed offset timezone representing UTC.