Skip to content

Commit

Permalink
replace utc import with datetime one
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdtp committed Apr 11, 2024
1 parent 8de10c4 commit e42796c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions gisserver/output/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from __future__ import annotations

import csv
from datetime import datetime
from datetime import datetime, timezone

from django.conf import settings
from django.db import models
from django.utils.timezone import utc

from gisserver import conf
from gisserver.db import (
Expand Down Expand Up @@ -137,7 +136,7 @@ def get_row(self, instance: models.Model, fields: list[XsdElement]):
# Array field
append(",".join(map(str, value)))
elif isinstance(value, datetime):
append(str(value.astimezone(utc)))
append(str(value.astimezone(timezone.utc)))
else:
append(value)
return values
Expand Down
5 changes: 2 additions & 3 deletions gisserver/output/geojson.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Output rendering logic for GeoJSON."""
from datetime import datetime
from datetime import datetime, timezone
from decimal import Decimal
from typing import cast

Expand All @@ -8,7 +8,6 @@
from django.contrib.gis.db.models.functions import AsGeoJSON
from django.db import models
from django.utils.functional import Promise
from django.utils.timezone import utc

from gisserver import conf
from gisserver.db import get_db_geometry_target
Expand Down Expand Up @@ -147,7 +146,7 @@ def render_feature(

def _format_geojson_value(self, value):
if isinstance(value, datetime):
return value.astimezone(utc)
return value.astimezone(timezone.utc)
elif isinstance(value, models.Model):
# ForeignKey, not defined as complex type.
return str(value)
Expand Down
5 changes: 2 additions & 3 deletions gisserver/output/gml32.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

import itertools
import re
from datetime import date, datetime, time
from datetime import date, datetime, time, timezone
from html import escape
from typing import cast

from django.contrib.gis import geos
from django.db import models
from django.http import HttpResponse
from django.utils.timezone import utc

from gisserver.db import (
AsGML,
Expand Down Expand Up @@ -306,7 +305,7 @@ def _render_xml_field(
# Expanded foreign relation / dictionary
return self.render_xml_complex_type(feature_type, xsd_element, value)
elif isinstance(value, datetime):
value = value.astimezone(utc).isoformat()
value = value.astimezone(timezone.utc).isoformat()
elif isinstance(value, (date, time)):
value = value.isoformat()
elif isinstance(value, bool):
Expand Down
6 changes: 4 additions & 2 deletions gisserver/output/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import django
from django.db import models
from django.utils.functional import cached_property
from django.utils.timezone import now, utc
from django.utils.timezone import now

from datetime import timezone

from gisserver.features import FeatureType
from gisserver.geometries import BoundingBox
Expand Down Expand Up @@ -218,7 +220,7 @@ def __init__(
self.next = next
self.previous = previous
self.date = now()
self.timestamp = self.date.astimezone(utc).isoformat()
self.timestamp = self.date.astimezone(timezone.utc).isoformat()

def get_bounding_box(self) -> BoundingBox:
"""Determine bounding box of all items."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gisserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from django.contrib.gis.db.models import PointField
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.utils.timezone import utc

from datetime import timezone

def current_datetime():
return datetime(2020, 4, 5, 12, 11, 10, 0, tzinfo=utc)
return datetime(2020, 4, 5, 12, 11, 10, 0, tzinfo=timezone.utc)


class City(models.Model):
Expand Down

0 comments on commit e42796c

Please sign in to comment.