Skip to content

Commit 0cbea52

Browse files
authored
Merge pull request #7 from luismedel/feature/add-datetime-property
Add datetime property
2 parents b28f635 + 62876fa commit 0cbea52

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [1.1.4] - 2023-11-09
10+
11+
### Added
12+
13+
- `datetime` property.
14+
15+
## [1.1.3] - 2023-10-09
16+
17+
### Fixed
18+
19+
- Honor Python 3.7 syntax .
20+
921
## [1.1.2] - 2023-09-13
1022

1123
### Fixed
1224

1325
- Properly exported symbols as per https://github.com/microsoft/pylance-release/issues/2953#issuecomment-1168408943.
1426

15-
1627
## [1.1.1] - 2023-08-18
1728

1829
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tsidpy"
7-
version = "1.1.3"
7+
version = "1.1.4"
88
authors = [
99
{ name="Luis Medel", email="luis@luismedel.com" },
1010
]

src/tsidpy/tsid.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def timestamp(self) -> float:
9090
"""
9191
return self._epoch + (self.__number >> RANDOM_BITS)
9292

93+
@property
94+
def datetime(self) -> datetime:
95+
"""Datetime corresponding with the tiimestamp component
96+
of the TSID.
97+
98+
>>> TSID(0).datetime == datetime.fromtimestamp(TSID_EPOCH / 1000)
99+
True
100+
"""
101+
return datetime.fromtimestamp(self.timestamp / 1000)
102+
93103
@property
94104
def random(self) -> int:
95105
"""Returns the random component of the TSID.

tests/generator_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def print_tsid(t: TSID) -> None:
2020

2121

2222
if __name__ == '__main__':
23-
g: TSIDGenerator()
23+
g = TSIDGenerator()
2424
for _ in range(10):
2525
print_tsid(g.create())
2626
time.sleep(0.1)

0 commit comments

Comments
 (0)