Skip to content

Commit

Permalink
Remove utcnow() deprecation warning in test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicozanf committed Nov 24, 2024
1 parent 7f5fd21 commit c82e0e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Thumbs.db
.DS_Store
pyDAL.egg-info/*
venv/*
test-venv/*
dist/*
build/*
.project
Expand Down
4 changes: 2 additions & 2 deletions pydal/restapi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import collections
import copy
import datetime
import fnmatch
import functools
import re
import traceback
from .utils import utcnow

__version__ = "0.1"

Expand Down Expand Up @@ -67,7 +67,7 @@ def wrapper(*args, **kwargs):
data["message"] = str(e)
data["code"] = 400
finally:
data["timestamp"] = datetime.datetime.utcnow().isoformat()
data["timestamp"] = utcnow().isoformat()
data["api_version"] = __version__
return data

Expand Down
3 changes: 2 additions & 1 deletion pydal/tools/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

from pydal import DAL, Field
from pydal.validators import IS_IN_SET
from utils import utcnow


def now():
"""Returns the current datetime in UTC"""
return datetime.datetime.utcnow()
return utcnow()


def delta(t_secs):
Expand Down
5 changes: 4 additions & 1 deletion pydal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

import re
import warnings

import datetime

class RemovedInNextVersionWarning(DeprecationWarning):
pass


warnings.simplefilter("always", RemovedInNextVersionWarning)

def utcnow():
"""returns the current time in utc"""
return datetime.datetime.now(datetime.timezone.utc)

def warn_of_deprecation(old_name, new_name, prefix=None, stack=2):
msg = "%(old)s is deprecated, use %(new)s instead."
Expand Down

0 comments on commit c82e0e7

Please sign in to comment.