mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 04:12:23 +01:00
85bc250dac
* prune model functions * prune more misc
38 lines
800 B
Python
38 lines
800 B
Python
import json
|
|
from typing import Optional, Union
|
|
|
|
import pytz
|
|
from dateutil.parser import isoparse
|
|
from django.utils import timezone
|
|
|
|
from posthog.models.property import Property
|
|
|
|
|
|
def is_json(val):
|
|
if isinstance(val, int):
|
|
return False
|
|
|
|
try:
|
|
int(val)
|
|
return False
|
|
except:
|
|
pass
|
|
try:
|
|
json.loads(val)
|
|
except (ValueError, TypeError):
|
|
return False
|
|
return True
|
|
|
|
|
|
def cast_timestamp_or_now(timestamp: Optional[Union[timezone.datetime, str]]) -> str:
|
|
if not timestamp:
|
|
timestamp = timezone.now()
|
|
|
|
# clickhouse specific formatting
|
|
if isinstance(timestamp, str):
|
|
timestamp = isoparse(timestamp)
|
|
else:
|
|
timestamp = timestamp.astimezone(pytz.utc)
|
|
|
|
return timestamp.strftime("%Y-%m-%d %H:%M:%S.%f")
|