Skip to content

Commit 251dae1

Browse files
update: uses UTC for timestamps (supertokens#557)
- Makes timestamps consistent, uses UTC timezone Ref: supertokens#554 Co-authored-by: Viraj Kanwade <viraj.kanwade@forgeahead.io>
1 parent f1b9103 commit 251dae1

File tree

9 files changed

+28
-33
lines changed

9 files changed

+28
-33
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [unreleased]
1010

11+
## [0.28.0]
12+
- Updates timestamps to use UTC instead of GMT as the timezone
13+
1114
## [0.27.0] - 2024-12-30
1215

1316
- Added OAuth2Provider recipe

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
setup(
8585
name="supertokens_python",
86-
version="0.27.0",
86+
version="0.28.0",
8787
author="SuperTokens",
8888
license="Apache 2.0",
8989
author_email="team@supertokens.com",

supertokens_python/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
SUPPORTED_CDI_VERSIONS = ["5.2"]
18-
VERSION = "0.27.0"
18+
VERSION = "0.28.0"
1919
TELEMETRY = "/telemetry"
2020
USER_COUNT = "/users/count"
2121
USER_DELETE = "/user/remove"

supertokens_python/framework/django/django_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_cookie(
5151
key=key,
5252
value=value,
5353
expires=datetime.fromtimestamp(ceil(expires / 1000)).strftime(
54-
"%a, %d %b %Y %H:%M:%S GMT"
54+
"%a, %d %b %Y %H:%M:%S UTC"
5555
),
5656
path=path,
5757
domain=domain,

tests/Django/test_django.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ async def test_login_handle(self):
296296

297297
try:
298298
datetime.strptime(
299-
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S GMT"
299+
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S UTC"
300300
)
301301
except ValueError:
302302
assert False, "cookies expiry time doesn't have the correct format"

tests/test_logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import os
55
import sys
6-
from datetime import datetime as real_datetime
6+
from datetime import datetime as real_datetime, timezone
77
from unittest import TestCase
88
from unittest.mock import MagicMock, patch
99

@@ -43,7 +43,7 @@ def teardown_method(self, _):
4343
@patch("supertokens_python.logger.datetime", wraps=real_datetime)
4444
def test_1_json_msg_format(self, datetime_mock: MagicMock):
4545
enable_debug_logging()
46-
datetime_mock.now.return_value = real_datetime(2000, 1, 1)
46+
datetime_mock.now.return_value = real_datetime(2000, 1, 1, tzinfo=timezone.utc)
4747

4848
with self.assertLogs(level="DEBUG") as captured:
4949
log_debug_message("API replied with status 200")
@@ -52,7 +52,7 @@ def test_1_json_msg_format(self, datetime_mock: MagicMock):
5252
out = json.loads(record.msg)
5353

5454
assert out == {
55-
"t": "2000-01-01T00:00Z",
55+
"t": "2000-01-01T00:00:00+00Z",
5656
"sdkVer": VERSION,
5757
"message": "API replied with status 200",
5858
"file": "../tests/test_logger.py:49",

tests/test_session.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414

1515
import asyncio
16-
from datetime import datetime, timedelta
16+
from datetime import datetime, timedelta, timezone
1717
from typing import Any, Dict, List, Optional
1818
from unittest.mock import MagicMock
1919

@@ -663,15 +663,13 @@ async def test_token_cookie_expires(
663663
for c in response.cookies.jar:
664664
if c.name == "sAccessToken": # 100 years (set by the SDK)
665665
# some time must have elasped since the cookie was set. So less than current time
666-
assert (
667-
datetime.fromtimestamp(c.expires or 0) - timedelta(days=365.25 * 100)
668-
< datetime.now()
669-
)
666+
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
667+
days=365.25 * 100
668+
) < datetime.now(tz=timezone.utc)
670669
if c.name == "sRefreshToken": # 100 days (set by the core)
671-
assert (
672-
datetime.fromtimestamp(c.expires or 0) - timedelta(days=100)
673-
< datetime.now()
674-
)
670+
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
671+
days=100
672+
) < datetime.now(tz=timezone.utc)
675673

676674
assert response.headers["anti-csrf"] != ""
677675
assert response.headers["front-token"] != ""
@@ -693,15 +691,13 @@ async def test_token_cookie_expires(
693691
for c in response.cookies.jar:
694692
if c.name == "sAccessToken": # 100 years (set by the SDK)
695693
# some time must have elasped since the cookie was set. So less than current time
696-
assert (
697-
datetime.fromtimestamp(c.expires or 0) - timedelta(days=365.25 * 100)
698-
< datetime.now()
699-
)
694+
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
695+
days=365.25 * 100
696+
) < datetime.now(tz=timezone.utc)
700697
if c.name == "sRefreshToken": # 100 days (set by the core)
701-
assert (
702-
datetime.fromtimestamp(c.expires or 0) - timedelta(days=100)
703-
< datetime.now()
704-
)
698+
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
699+
days=100
700+
) < datetime.now(tz=timezone.utc)
705701

706702
assert response.headers["anti-csrf"] != ""
707703
assert response.headers["front-token"] != ""

tests/thirdparty/test_thirdparty.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import datetime
1+
from datetime import datetime, timezone
22
import json
33
from base64 import b64encode
44
from typing import Dict, Any, Optional
@@ -208,7 +208,7 @@ async def test_signinup_when_validate_access_token_throws(fastapi_client: TestCl
208208
async def test_signinup_works_when_validate_access_token_does_not_throw(
209209
fastapi_client: TestClient, mocker: MockerFixture
210210
):
211-
time = str(datetime.datetime.now())
211+
time = str(datetime.now(tz=timezone.utc))
212212
mocker.patch(
213213
"supertokens_python.recipe.thirdparty.providers.custom.get_supertokens_user_info_result_from_raw_user_info",
214214
return_value=UserInfo(
@@ -276,7 +276,7 @@ async def test_signinup_works_when_validate_access_token_does_not_throw(
276276
async def test_signinup_android_without_redirect_uri(
277277
fastapi_client: TestClient, mocker: MockerFixture
278278
):
279-
time = str(datetime.datetime.now())
279+
time = str(datetime.now(tz=timezone.utc))
280280
mocker.patch(
281281
"supertokens_python.recipe.thirdparty.providers.custom.get_supertokens_user_info_result_from_raw_user_info",
282282
return_value=UserInfo(

tests/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414
import asyncio
1515
import json
16-
from datetime import datetime, timezone
16+
from datetime import datetime
1717
from http.cookies import SimpleCookie
1818
from os import environ, kill, remove, scandir
1919
from pathlib import Path
@@ -313,11 +313,7 @@ def assert_info_clears_tokens(info: Dict[str, Any], token_transfer_method: str):
313313

314314

315315
def get_unix_timestamp(expiry: str):
316-
return int(
317-
datetime.strptime(expiry, "%a, %d %b %Y %H:%M:%S GMT")
318-
.replace(tzinfo=timezone.utc)
319-
.timestamp()
320-
)
316+
return int(datetime.strptime(expiry, "%a, %d %b %Y %H:%M:%S UTC").timestamp())
321317

322318

323319
def verify_within_5_second_diff(n1: int, n2: int):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy