Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datetime property #7

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.1.4] - 2023-11-09

### Added

- `datetime` property.

## [1.1.3] - 2023-10-09

### Fixed

- Honor Python 3.7 syntax .

## [1.1.2] - 2023-09-13

### Fixed

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


## [1.1.1] - 2023-08-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "tsidpy"
version = "1.1.3"
version = "1.1.4"
authors = [
{ name="Luis Medel", email="luis@luismedel.com" },
]
Expand Down
10 changes: 10 additions & 0 deletions src/tsidpy/tsid.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ def timestamp(self) -> float:
"""
return self._epoch + (self.__number >> RANDOM_BITS)

@property
def datetime(self) -> datetime:
"""Datetime corresponding with the tiimestamp component
of the TSID.

>>> TSID(0).datetime == datetime.fromtimestamp(TSID_EPOCH / 1000)
True
"""
return datetime.fromtimestamp(self.timestamp / 1000)

@property
def random(self) -> int:
"""Returns the random component of the TSID.
Expand Down
2 changes: 1 addition & 1 deletion tests/generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def print_tsid(t: TSID) -> None:


if __name__ == '__main__':
g: TSIDGenerator()
g = TSIDGenerator()
for _ in range(10):
print_tsid(g.create())
time.sleep(0.1)
Expand Down