-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
cbor2==5.6.5 | ||
certifi==2024.12.14 | ||
charset-normalizer==3.4.0 | ||
docker==7.1.0 | ||
Requests==2.32.3 | ||
idna==3.10 | ||
mypy==1.13.0 | ||
mypy-extensions==1.0.0 | ||
pytz==2024.2 | ||
requests==2.32.3 | ||
semantic-version==2.10.0 | ||
setuptools>=70.0.0 | ||
setuptools_rust==1.6.0 | ||
setuptools-rust==1.6.0 | ||
tomli==2.2.1 | ||
types-pytz==2024.2.0.20241003 | ||
types-requests==2.32.0.20241016 | ||
typing_extensions==4.12.2 | ||
urllib3==2.2.3 | ||
websockets==14.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytz # type: ignore | ||
|
||
from dataclasses import dataclass | ||
from datetime import datetime | ||
from math import floor | ||
from typing import Tuple | ||
|
||
|
||
@dataclass | ||
class DateTimeCompact: | ||
timestamp: int = 0 # nanoseconds | ||
|
||
@staticmethod | ||
def parse(seconds: int, nanoseconds: int): | ||
return DateTimeCompact(nanoseconds + (seconds * pow(10, 9))) | ||
|
||
def get_seconds_and_nano(self) -> Tuple[int, int]: | ||
sec = floor(self.timestamp / pow(10, 9)) | ||
nsec = self.timestamp - (sec * pow(10, 9)) | ||
|
||
return sec, nsec | ||
|
||
def get_date_time(self, fmt: str = "%Y-%m-%dT%H:%M:%S.%fZ"): | ||
return datetime.fromtimestamp(self.timestamp / pow(10, 9), pytz.UTC).strftime( | ||
fmt | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from unittest import TestCase | ||
|
||
from surrealdb.data.types.datetime import DateTimeCompact | ||
from surrealdb.data.cbor import encode, decode | ||
|
||
|
||
class TestCBOR(TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_datetime(self): | ||
compact_date_time_array = [1733994058, 83988472] # December 12, 2024 9:00:58.083 AM | ||
|
||
compact_date_time = DateTimeCompact.parse(compact_date_time_array[0], compact_date_time_array[1]) | ||
encoded = encode(compact_date_time) | ||
decoded = decode(encoded) | ||
|
||
self.assertEqual(decoded.get_date_time(), '2024-12-12T09:00:58.083988Z') | ||
|
||
|