Skip to content

Commit

Permalink
Fix date issues, now always using UTC, but display local time (offset…
Browse files Browse the repository at this point in the history
… applied)
  • Loading branch information
BenSouchet committed Dec 12, 2024
1 parent fbbb5ed commit d95a537
Show file tree
Hide file tree
Showing 55 changed files with 249 additions and 244 deletions.
2 changes: 1 addition & 1 deletion src/quadpype/hosts/blender/api/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class TOPBAR_MT_avalon(bpy.types.Menu):
"""Avalon menu."""

bl_idname = "TOPBAR_MT_avalon"
bl_label = os.getenv("QUADPYPE_LABEL")
bl_label = os.getenv("QUADPYPE_LABEL") or "QuadPype"

def draw(self, context):
"""Draw the menu in the UI."""
Expand Down
9 changes: 5 additions & 4 deletions src/quadpype/hosts/flame/api/scripts/wiretap_com.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import os
import sys
import subprocess
import json

from __future__ import absolute_import
import xml.dom.minidom as minidom
from copy import deepcopy
import datetime
from datetime import datetime, timezone

from libwiretapPythonClientAPI import ( # noqa
WireTapClientInit,
WireTapClientUninit,
Expand Down Expand Up @@ -261,7 +262,7 @@ def _user_prep(self, user_name):
return filtered_users.pop()

# create new user name with date in suffix
now = datetime.datetime.now() # current date and time
now = datetime.now(timezone.utc) # current date and time
date = now.strftime("%Y%m%d")
new_user_name = "{}_{}".format(user_name, date)
print(new_user_name)
Expand Down
20 changes: 11 additions & 9 deletions src/quadpype/hosts/harmony/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import functools
import time
import struct
from datetime import datetime
import threading

from datetime import datetime, timezone

from . import lib


Expand Down Expand Up @@ -170,18 +172,18 @@ def run(self):
Waits for a connection on `self.port` before going into listen mode.
"""
# Wait for a connection
timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
self.log.debug(f"[{timestamp}] Waiting for a connection.")
self.connection, client_address = self.socket.accept()

timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
self.log.debug(f"[{timestamp}] Connection from: {client_address}")

self.receive()

def stop(self):
"""Shutdown socket server gracefully."""
timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
self.log.debug(f"[{timestamp}] Shutting down server.")
if self.connection is None:
self.log.debug("Connect to shutdown.")
Expand All @@ -204,7 +206,7 @@ def _send(self, message):
while not self.connection:
pass

timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
encoded = message.encode("utf-8")
coded_message = b"AH" + struct.pack('>I', len(encoded)) + encoded
pretty = self._pretty(coded_message)
Expand All @@ -225,7 +227,7 @@ def send(self, request):
request["message_id"] = self.message_id
self._send(json.dumps(request))
if request.get("reply"):
timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
self.log.debug(
f"[{timestamp}] sent reply, not waiting for anything.")
return None
Expand All @@ -235,7 +237,7 @@ def send(self, request):
while True:
time.sleep(0.1)
if time.time() > current_time + 30:
timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
self.log.error((f"[{timestamp}][{self.message_id}] "
"No reply from Harmony in 30s. "
f"Retrying {try_index}"))
Expand All @@ -245,7 +247,7 @@ def send(self, request):
break
try:
result = self.queue[request["message_id"]]
timestamp = datetime.now().strftime("%H:%M:%S.%f")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
self.log.debug((f"[{timestamp}] Got request "
f"id {self.message_id}, "
"removing from queue"))
Expand Down Expand Up @@ -276,4 +278,4 @@ def timestamp(self):
str: current timestamp.
"""
return datetime.now().strftime("%H:%M:%S.%f")
return datetime.now(timezone.utc).strftime("%H:%M:%S.%f")
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

import calendar
import collections.abc
import datetime

from datetime import datetime, timezone, timedelta

from google.protobuf.descriptor import FieldDescriptor

Expand Down Expand Up @@ -160,8 +161,8 @@ def FromJsonString(self, value):
raise ValueError(
'time data \'{0}\' does not match format \'%Y-%m-%dT%H:%M:%S\', '
'lowercase \'t\' is not accepted'.format(second_value))
date_object = datetime.datetime.strptime(second_value, _TIMESTAMPFOMAT)
td = date_object - datetime.datetime(1970, 1, 1)
date_object = datetime.strptime(second_value, _TIMESTAMPFOMAT)
td = date_object - datetime(1970, 1, 1)
seconds = td.seconds + td.days * _SECONDS_PER_DAY
if len(nano_value) > 9:
raise ValueError(
Expand Down Expand Up @@ -192,7 +193,7 @@ def FromJsonString(self, value):

def GetCurrentTime(self):
"""Get the current UTC into Timestamp."""
self.FromDatetime(datetime.datetime.utcnow())
self.FromDatetime(datetime.now(timezone.utc))

def ToNanoseconds(self):
"""Converts Timestamp to nanoseconds since epoch."""
Expand Down Expand Up @@ -244,7 +245,7 @@ def ToDatetime(self, tzinfo=None):
Otherwise, returns a timezone-aware datetime in the input timezone.
"""
delta = datetime.timedelta(
delta = timedelta(
seconds=self.seconds,
microseconds=_RoundTowardZero(self.nanos, _NANOS_PER_MICROSECOND))
if tzinfo is None:
Expand Down Expand Up @@ -382,7 +383,7 @@ def FromSeconds(self, seconds):

def ToTimedelta(self):
"""Converts Duration to timedelta."""
return datetime.timedelta(
return timedelta(
seconds=self.seconds, microseconds=_RoundTowardZero(
self.nanos, _NANOS_PER_MICROSECOND))

Expand Down
13 changes: 7 additions & 6 deletions src/quadpype/hosts/webpublisher/lib.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from datetime import datetime
import collections
import json

from datetime import datetime, timezone

from bson.objectid import ObjectId

import pyblish.util
Expand Down Expand Up @@ -125,7 +126,7 @@ def start_webpublish_log(dbcon, batch_id, user):
"""
return dbcon.insert_one({
"batch_id": batch_id,
"start_date": datetime.now(),
"start_date": datetime.now(timezone.utc),
"user": user,
"status": IN_PROGRESS_STATUS,
"progress": 0 # integer 0-100, percentage
Expand Down Expand Up @@ -168,7 +169,7 @@ def publish_and_log(dbcon, _id, log, close_plugin_name=None, batch_id=None):
{"_id": _id},
{"$set":
{
"finish_date": datetime.now(),
"finish_date": datetime.now(timezone.utc),
"status": ERROR_STATUS,
"log": os.linesep.join(log_lines)

Expand Down Expand Up @@ -197,7 +198,7 @@ def publish_and_log(dbcon, _id, log, close_plugin_name=None, batch_id=None):
{
"$set":
{
"finish_date": datetime.now(),
"finish_date": datetime.now(timezone.utc),
"status": FINISHED_REPROCESS_STATUS,
}
}
Expand All @@ -208,7 +209,7 @@ def publish_and_log(dbcon, _id, log, close_plugin_name=None, batch_id=None):
{
"$set":
{
"finish_date": datetime.now(),
"finish_date": datetime.now(timezone.utc),
"status": FINISHED_OK_STATUS,
"progress": 100,
"log": os.linesep.join(log_lines)
Expand All @@ -227,7 +228,7 @@ def fail_batch(_id, dbcon, msg):
{"_id": _id},
{"$set":
{
"finish_date": datetime.now(),
"finish_date": datetime.now(timezone.utc),
"status": ERROR_STATUS,
"log": msg

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Routes and etc. for webpublisher API."""
import os
import json
import datetime
import collections
import subprocess

from datetime import datetime

from bson.objectid import ObjectId
from fastapi import Response, status

Expand Down Expand Up @@ -44,7 +46,7 @@ class JsonApiResource:
"""
@staticmethod
def json_dump_handler(value):
if isinstance(value, datetime.datetime):
if isinstance(value, datetime):
return value.isoformat()
if isinstance(value, ObjectId):
return str(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import collections
import time
import os
from datetime import datetime
from datetime import datetime, timezone
import requests
import json
import subprocess
Expand Down Expand Up @@ -147,7 +147,7 @@ def reprocess_failed(upload_dir, webserver_url):
{"_id": batch["_id"]},
{"$set":
{
"finish_date": datetime.now(),
"finish_date": datetime.now(timezone.utc),
"status": ERROR_STATUS,
"progress": 100,
"log": batch.get("log") + msg
Expand All @@ -166,7 +166,7 @@ def reprocess_failed(upload_dir, webserver_url):
},
{
"$set": {
"finish_date": datetime.now(),
"finish_date": datetime.now(timezone.utc),
"status": SENT_REPROCESSING_STATUS,
"progress": 100
}
Expand Down
7 changes: 4 additions & 3 deletions src/quadpype/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""Module storing class for caching values, used for settings."""
import json
import copy
import datetime

from datetime import datetime, timezone


class CacheValues:
Expand All @@ -21,7 +22,7 @@ def data_copy(self):

def update_data(self, data, version):
self.data = data
self.creation_time = datetime.datetime.now()
self.creation_time = datetime.now(timezone.utc)
self.version = version

def update_last_saved_info(self, last_saved_info):
Expand All @@ -47,7 +48,7 @@ def to_json_string(self):
def is_outdated(self):
if self.creation_time is None:
return True
delta = (datetime.datetime.now() - self.creation_time).seconds
delta = (datetime.now(timezone.utc) - self.creation_time).seconds
return delta > self.cache_lifetime

def set_outdated(self):
Expand Down
4 changes: 2 additions & 2 deletions src/quadpype/lib/dateutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_datetime_data(datetime_obj=None):
"""

if not datetime_obj:
datetime_obj = datetime.now()
datetime_obj = datetime.now(timezone.utc)

year = datetime_obj.strftime("%Y")

Expand Down Expand Up @@ -80,7 +80,7 @@ def get_timestamp_str(datetime_obj=None, local_timezone=False):
"""Get standardized timestamp string from a datetime object.
Args:
datetime_obj (datetime.datetime): Object of datetime. Current time
datetime_obj (datetime): Object of datetime. Current time
is used if not passed.
"""

Expand Down
7 changes: 3 additions & 4 deletions src/quadpype/lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
Best place for it is in ``repos/pype-config/environments/global.json``
"""


import datetime
import getpass
import logging
import os
Expand All @@ -24,6 +21,8 @@
import threading
import copy

from datetime import datetime, timezone

from quadpype.client.mongo import (
MongoEnvNotSet,
get_default_components,
Expand Down Expand Up @@ -131,7 +130,7 @@ def format(self, record):
"""Formats LogRecord into python dictionary."""
# Standard document
document = {
'timestamp': datetime.datetime.now(),
'timestamp': datetime.now(timezone.utc),
'level': record.levelname,
'thread': record.thread,
'threadName': record.threadName,
Expand Down
7 changes: 4 additions & 3 deletions src/quadpype/lib/project_backpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import platform
import tempfile
import shutil
import datetime

import zipfile

from datetime import datetime, timezone

from quadpype.client.mongo import (
load_json_file,
get_project_connection,
Expand All @@ -37,7 +38,7 @@
def add_timestamp(filepath):
"""Add timestamp string to a file."""
base, ext = os.path.splitext(filepath)
timestamp = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
timestamp = datetime.now(timezone.utc).strftime("%y%m%d_%H%M%S")
new_base = "{}_{}".format(base, timestamp)
return new_base + ext

Expand Down
4 changes: 2 additions & 2 deletions src/quadpype/lib/pype_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import json
import datetime
from datetime import datetime, timezone

from .execute import get_quadpype_execute_args
from .user import get_user_id, get_user_profile
Expand Down Expand Up @@ -58,7 +58,7 @@ def extract_pype_info_to_file(dir_path):
filename = "{}_{}_{}.json".format(
get_quadpype_version(),
get_user_id(),
datetime.datetime.now().strftime("%y%m%d%H%M%S")
datetime.now(timezone.utc).strftime("%y%m%d%H%M%S")
)
filepath = os.path.join(dir_path, filename)
data = get_all_current_info()
Expand Down
Loading

0 comments on commit d95a537

Please sign in to comment.