-
Notifications
You must be signed in to change notification settings - Fork 14
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
42-normalize-timestamp #46
Conversation
@@ -58,7 +58,7 @@ class UserAleSchema(BaseModel): | |||
page_title: str | |||
page_referrer: str | |||
browser: Browser | |||
client_time: int | |||
client_time: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the trailing space?
@@ -19,8 +19,9 @@ | |||
|
|||
from pydantic import ValidationError | |||
|
|||
from distill.core.log import Log | |||
from distill.core.log import Log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: trailing ws
|
||
@field_validator("client_time") | ||
def validate_ct(cls, ct: float): | ||
return datetime.fromtimestamp(ct / 1000) | ||
|
||
@field_serializer("client_time") | ||
def serialize_ct(self, ct: datetime): | ||
return int(ct.timestamp() * 1000) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so simple and clean.
Added timestamp normalization function for use in log ID creation. The function can accept arbitrary timestamps and timezones and will attempt to normalize to a python date time object (defaults to +0000 timezone). The function can also accept POSIX timestamps (seconds or milliseconds since the epoch).
Closes #42