Skip to content

Commit

Permalink
Merge pull request #291 from XePeleato/dtfix
Browse files Browse the repository at this point in the history
net: Make datetime objects timezone aware
  • Loading branch information
dstndstn authored Jan 30, 2024
2 parents 38fb300 + 9ff7992 commit 673394b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions net/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import print_function
from __future__ import absolute_import
import os
from datetime import datetime
import itertools

from urllib.request import urlopen
Expand All @@ -11,6 +10,7 @@
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.urls import reverse
from django.utils import timezone

from astrometry.net import settings
from astrometry.net.settings import *
Expand Down Expand Up @@ -182,7 +182,7 @@ class ProcessSubmissions(models.Model):
# jobs

def set_watchdog(self):
self.watchdog = datetime.now()
self.watchdog = timezone.now()

def count_queued_subs(self):
return self.subs.filter(finished=False,
Expand All @@ -201,7 +201,7 @@ def count_running_jobs(self):
job__start_time__isnull=False).count()

def watchdog_ago(self):
return datetime.now() - self.watchdog
return timezone.now() - self.watchdog
def watchdog_sec_ago(self):
dt = self.watchdog_ago()
sec = dtsec(dt)
Expand All @@ -219,7 +219,7 @@ def get_time_string(self, t):
if t is None:
return '-'
t = t.replace(microsecond=0)
return t.isoformat() + ' (%i sec ago)' % dtsec(datetime.now() - t)
return t.isoformat() + ' (%i sec ago)' % dtsec(timezone.now() - t)

class QueuedSubmission(QueuedThing):
procsub = models.ForeignKey('ProcessSubmissions', models.CASCADE, related_name='subs')
Expand Down Expand Up @@ -826,13 +826,13 @@ def __str__(self):
return s

def set_queued_time(self):
self.queued_time = datetime.now()
self.queued_time = timezone.now()

def set_start_time(self):
self.start_time = datetime.now()
self.start_time = timezone.now()

def set_end_time(self):
self.end_time = datetime.now()
self.end_time = timezone.now()

def OLD_get_dir(self):
if self.id < 10000:
Expand Down Expand Up @@ -1245,9 +1245,9 @@ def get_scale_bounds(self):
return None

def set_processing_started(self):
self.processing_started = datetime.now()
self.processing_started = timezone.now()
def set_processing_finished(self):
self.processing_finished = datetime.now()
self.processing_finished = timezone.now()

def save(self, *args, **kwargs):
pro = get_user_profile(self.user)
Expand All @@ -1270,7 +1270,7 @@ def save(self, *args, **kwargs):
#logmsg('saving submission: license id = %d' % self.license.id)
#logmsg('saving submission: commentreceiver id = %d' % self.comment_receiver.id)

now = datetime.now()
now = timezone.now()
return super(Submission, self).save(*args, **kwargs)


Expand Down

0 comments on commit 673394b

Please sign in to comment.