Skip to content

Commit 46db5d9

Browse files
committed
Enable timezone support and set timezone to UTC
1 parent 70181a3 commit 46db5d9

File tree

11 files changed

+93
-82
lines changed

11 files changed

+93
-82
lines changed

readthedocs/core/fixtures/eric.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"is_active": true,
1010
"is_superuser": false,
1111
"is_staff": true,
12-
"last_login": "2010-08-14 01:51:05",
12+
"last_login": "2010-08-14T01:51:05+00:00",
1313
"groups": [],
1414
"user_permissions": [],
1515
"password": "sha1$035cb$156ad6cb44332fb4f24bcb634142a67435be0b37",
1616
"email": "[email protected]",
17-
"date_joined": "2010-08-14 01:50:58"
17+
"date_joined": "2010-08-14T01:50:58+00:00"
1818
}
1919
},
2020
{
@@ -27,12 +27,12 @@
2727
"is_active": true,
2828
"is_superuser": false,
2929
"is_staff": true,
30-
"last_login": "2010-08-14 01:51:05",
30+
"last_login": "2010-08-14T01:51:05+00:00",
3131
"groups": [],
3232
"user_permissions": [],
3333
"password": "sha1$035cb$156ad6cb44332fb4f24bcb634142a67435be0b37",
3434
"email": "[email protected]",
35-
"date_joined": "2010-08-14 01:50:58"
35+
"date_joined": "2010-08-14T01:50:58+00:00"
3636
}
3737
},
3838
{
@@ -45,12 +45,12 @@
4545
"is_active": true,
4646
"is_superuser": true,
4747
"is_staff": true,
48-
"last_login": "2010-08-14 01:51:05",
48+
"last_login": "2010-08-14T01:51:05+00:00",
4949
"groups": [],
5050
"user_permissions": [],
5151
"password": "sha1$035cb$156ad6cb44332fb4f24bcb634142a67435be0b37",
5252
"email": "[email protected]",
53-
"date_joined": "2010-08-14 01:50:58"
53+
"date_joined": "2010-08-14T01:50:58+00:00"
5454
}
5555
}
5656
]

readthedocs/core/management/commands/clean_builds.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Clean up stable build paths per project version"""
22

33
from __future__ import absolute_import
4-
from datetime import datetime, timedelta
4+
from datetime import timedelta
55
import logging
66
from optparse import make_option
77

88
from django.core.management.base import BaseCommand
99
from django.db.models import Max
10+
from django.utils import timezone
1011

1112
from readthedocs.builds.models import Build, Version
1213

@@ -35,7 +36,7 @@ def add_arguments(self, parser):
3536

3637
def handle(self, *args, **options):
3738
"""Find stale builds and remove build paths"""
38-
max_date = datetime.now() - timedelta(days=options['days'])
39+
max_date = timezone.now() - timedelta(days=options['days'])
3940
queryset = (Build.objects
4041
.values('project', 'version')
4142
.annotate(max_date=Max('date'))

readthedocs/oauth/services/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from allauth.socialaccount.providers import registry
1212
from builtins import object
1313
from django.conf import settings
14+
from django.utils import timezone
1415
from oauthlib.oauth2.rfc6749.errors import InvalidClientIdError
1516
from requests.exceptions import RequestException
1617
from requests_oauthlib import OAuth2Session
@@ -83,7 +84,7 @@ def create_session(self):
8384
'token_type': 'bearer',
8485
}
8586
if token.expires_at is not None:
86-
token_expires = (token.expires_at - datetime.now()).total_seconds()
87+
token_expires = (token.expires_at - timezone.now()).total_seconds()
8788
token_config.update({
8889
'refresh_token': token.token_secret,
8990
'expires_in': token_expires,
@@ -119,7 +120,9 @@ def token_updater(self, token):
119120
"""
120121
def _updater(data):
121122
token.token = data['access_token']
122-
token.expires_at = datetime.fromtimestamp(data['expires_at'])
123+
token.expires_at = timezone.make_aware(
124+
datetime.fromtimestamp(data['expires_at'])
125+
)
123126
token.save()
124127
log.info('Updated token %s:', token)
125128

readthedocs/projects/fixtures/test_auth.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,12 @@
675675
"is_active": true,
676676
"is_superuser": false,
677677
"is_staff": false,
678-
"last_login": "2014-02-09T19:47:26.625",
678+
"last_login": "2014-02-09T19:47:26.625+00:00",
679679
"groups": [],
680680
"user_permissions": [],
681681
"password": "",
682682
"email": "",
683-
"date_joined": "2014-02-09T19:47:26.625"
683+
"date_joined": "2014-02-09T19:47:26.625+00:00"
684684
}
685685
},
686686
{
@@ -693,12 +693,12 @@
693693
"is_active": true,
694694
"is_superuser": true,
695695
"is_staff": true,
696-
"last_login": "2014-02-09T19:48:39.934",
696+
"last_login": "2014-02-09T19:48:39.934+00:00",
697697
"groups": [],
698698
"user_permissions": [],
699699
"password": "pbkdf2_sha256$10000$FgAANNnclCS5$ElbS6laaFoh+nyHbEb96ICxS3xK1LioUS+CMQK+KdYM=",
700700
"email": "[email protected]",
701-
"date_joined": "2014-02-09T19:48:39.934"
701+
"date_joined": "2014-02-09T19:48:39.934+00:00"
702702
}
703703
}
704704
]

0 commit comments

Comments
 (0)