Skip to content

Commit

Permalink
revert refactor from old type checker
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorcary committed Aug 15, 2024
1 parent 75bb41b commit ad6cb08
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions truenas_api_client/ejson.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ class JSONEncoder(json.JSONEncoder):
the JSON array is undefined.
"""
def default(self, o: date | datetime | time | set) -> dict[str, str | int | list]:
if type(o) is date:
return {'$type': 'date', '$value': o.isoformat()}
elif type(o) is datetime:
if o.tzinfo is not None:
o = o.astimezone(timezone.utc)
def default(self, obj):
if type(obj) is date:
return {'$type': 'date', '$value': obj.isoformat()}
elif type(obj) is datetime:
if obj.tzinfo is not None:
obj = obj.astimezone(timezone.utc)
# Total milliseconds since EPOCH
return {'$date': int(calendar.timegm(o.timetuple()) * 1000)}
elif type(o) is time:
return {'$time': str(o)}
elif isinstance(o, set):
return {'$set': list(o)}
return super(JSONEncoder, self).default(o)
return {'$date': int(calendar.timegm(obj.timetuple()) * 1000)}
elif type(obj) is time:
return {'$time': str(obj)}
elif isinstance(obj, set):
return {'$set': list(obj)}
return super(JSONEncoder, self).default(obj)


def object_hook(obj: dict):
Expand Down

0 comments on commit ad6cb08

Please sign in to comment.