Implement read for DateTime
This commit is contained in:
parent
4b76aeabb9
commit
6980156e48
@ -14,6 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import io
|
import io
|
||||||
import struct
|
import struct
|
||||||
@ -126,6 +127,10 @@ class CslaBinaryReader:
|
|||||||
# BinaryReader.ReadInt32
|
# BinaryReader.ReadInt32
|
||||||
return struct.unpack('<i', self.stream.read(4))[0]
|
return struct.unpack('<i', self.stream.read(4))[0]
|
||||||
|
|
||||||
|
def read_int64(self):
|
||||||
|
# BinaryReader.ReadInt64
|
||||||
|
return struct.unpack('<q', self.stream.read(8))[0]
|
||||||
|
|
||||||
def read_object(self):
|
def read_object(self):
|
||||||
# CslaBinaryReader.ReadObject
|
# CslaBinaryReader.ReadObject
|
||||||
known_type = self.stream.read(1)[0]
|
known_type = self.stream.read(1)[0]
|
||||||
@ -171,7 +176,10 @@ class CslaBinaryReader:
|
|||||||
return self.read_decimal()
|
return self.read_decimal()
|
||||||
|
|
||||||
if known_type == CslaKnownTypes.DateTime.value:
|
if known_type == CslaKnownTypes.DateTime.value:
|
||||||
raise NotImplementedError()
|
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)
|
||||||
|
|
||||||
if known_type == CslaKnownTypes.String.value:
|
if known_type == CslaKnownTypes.String.value:
|
||||||
return self.read_string()
|
return self.read_string()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user