Set tz when reading DateTime
This commit is contained in:
parent
ef2580feba
commit
da65539d16
@ -14,7 +14,7 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from decimal import Decimal
|
||||
import io
|
||||
import struct
|
||||
@ -115,6 +115,12 @@ class CslaBinaryReader:
|
||||
|
||||
shift += 7
|
||||
|
||||
def read_datetime(self):
|
||||
timestamp = self.read_int64() # Number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000
|
||||
timestamp_unix = timestamp - 621355968000000000 # Subtract unix epoch in .NET ticks - https://gist.github.com/kristopherjohnson/397d0f74213a0087f1a1
|
||||
timestamp_unix /= 10000000 # Convert ticks to seconds (10^9 / 100)
|
||||
return datetime.fromtimestamp(timestamp_unix, timezone.utc)
|
||||
|
||||
def read_decimal(self):
|
||||
length = self.read_int32()
|
||||
if length != 4:
|
||||
@ -176,10 +182,7 @@ class CslaBinaryReader:
|
||||
return self.read_decimal()
|
||||
|
||||
if known_type == CslaKnownTypes.DateTime.value:
|
||||
timestamp = self.read_int64() # Number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000
|
||||
timestamp_unix = timestamp - 621355968000000000 # Subtract unix epoch in .NET ticks - https://gist.github.com/kristopherjohnson/397d0f74213a0087f1a1
|
||||
timestamp_unix /= 10000000 # Convert ticks to seconds (10^9 / 100)
|
||||
return datetime.fromtimestamp(timestamp_unix)
|
||||
return self.read_datetime()
|
||||
|
||||
if known_type == CslaKnownTypes.String.value:
|
||||
return self.read_string()
|
||||
|
Loading…
x
Reference in New Issue
Block a user