server/general: use UTC time stamps

This commit is contained in:
rr- 2016-07-03 14:46:15 +02:00
parent 1f413763bd
commit ac23067fdf
17 changed files with 31 additions and 31 deletions

View File

@ -42,7 +42,7 @@ class CommentDetailApi(BaseApi):
infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
text = ctx.get_param_as_string('text', required=True)
auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
comment.last_edit_time = datetime.datetime.now()
comment.last_edit_time = datetime.datetime.utcnow()
comments.update_comment_text(comment, text)
ctx.session.commit()
return _serialize(ctx, comment)

View File

@ -20,7 +20,7 @@ class InfoApi(BaseApi):
'featuringTime': post_feature.time if post_feature else None,
'featuringUser': users.serialize_user(post_feature.user, ctx.user) \
if post_feature else None,
'serverTime': datetime.datetime.now(),
'serverTime': datetime.datetime.utcnow(),
'config': {
'userNameRegex': config.config['user_name_regex'],
'passwordRegex': config.config['password_regex'],
@ -34,7 +34,7 @@ class InfoApi(BaseApi):
def _get_disk_usage(self):
threshold = datetime.timedelta(hours=1)
now = datetime.datetime.now()
now = datetime.datetime.utcnow()
if self._cache_time and self._cache_time > now - threshold:
return self._cache_result
total_size = 0

View File

@ -86,7 +86,7 @@ class PostDetailApi(BaseApi):
if ctx.has_file('thumbnail'):
auth.verify_privilege(ctx.user, 'posts:edit:thumbnail')
posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
post.last_edit_time = datetime.datetime.now()
post.last_edit_time = datetime.datetime.utcnow()
ctx.session.flush()
snapshots.save_entity_modification(post, ctx.user)
ctx.session.commit()

View File

@ -81,7 +81,7 @@ class TagDetailApi(BaseApi):
implications = ctx.get_param_as_list('implications')
_create_if_needed(implications, ctx.user)
tags.update_tag_implications(tag, implications)
tag.last_edit_time = datetime.datetime.now()
tag.last_edit_time = datetime.datetime.utcnow()
ctx.session.flush()
snapshots.save_entity_modification(tag, ctx.user)
ctx.session.commit()

View File

@ -4,7 +4,7 @@ class LruCacheItem(object):
def __init__(self, key, value):
self.key = key
self.value = value
self.timestamp = datetime.now()
self.timestamp = datetime.utcnow()
class LruCache(object):
def __init__(self, length, delta=None):

View File

@ -37,7 +37,7 @@ def create_comment(user, post, text):
comment.user = user
comment.post = post
update_comment_text(comment, text)
comment.creation_time = datetime.datetime.now()
comment.creation_time = datetime.datetime.utcnow()
return comment
def update_comment_text(comment, text):

View File

@ -32,5 +32,5 @@ def set_favorite(entity, user):
fav_entity = table()
setattr(fav_entity, get_column(table).name, get_column(entity))
fav_entity.user = user
fav_entity.time = datetime.datetime.now()
fav_entity.time = datetime.datetime.utcnow()
db.session.add(fav_entity)

View File

@ -153,7 +153,7 @@ def create_post(content, tag_names, user):
post = db.Post()
post.safety = db.Post.SAFETY_SAFE
post.user = user
post.creation_time = datetime.datetime.now()
post.creation_time = datetime.datetime.utcnow()
post.flags = []
# we'll need post ID
@ -293,7 +293,7 @@ def update_post_flags(post, flags):
def feature_post(post, user):
post_feature = db.PostFeature()
post_feature.time = datetime.datetime.now()
post_feature.time = datetime.datetime.utcnow()
post_feature.post = post
post_feature.user = user
db.session.add(post_feature)

View File

@ -55,5 +55,5 @@ def set_score(entity, user, score):
setattr(score_entity, get_column(table).name, get_column(entity))
score_entity.score = score
score_entity.user = user
score_entity.time = datetime.datetime.now()
score_entity.time = datetime.datetime.utcnow()
db.session.add(score_entity)

View File

@ -82,7 +82,7 @@ def get_serialized_history(entity):
def _save(operation, entity, auth_user):
resource_type, resource_id, resource_repr = db.util.get_resource_info(entity)
now = datetime.datetime.now()
now = datetime.datetime.utcnow()
snapshot = db.Snapshot()
snapshot.creation_time = now

View File

@ -165,7 +165,7 @@ def merge_tags(source_tag, target_tag):
def create_tag(names, category_name, suggestions, implications):
tag = db.Tag()
tag.creation_time = datetime.datetime.now()
tag.creation_time = datetime.datetime.utcnow()
update_tag_names(tag, names)
update_tag_category_name(tag, category_name)
update_tag_suggestions(tag, suggestions)

View File

@ -107,7 +107,7 @@ def create_user(name, password, email):
user.rank = util.flip(auth.RANK_MAP)[config.config['default_rank']]
else:
user.rank = db.User.RANK_ADMINISTRATOR
user.creation_time = datetime.datetime.now()
user.creation_time = datetime.datetime.utcnow()
user.avatar_style = db.User.AVATAR_GRAVATAR
return user
@ -185,7 +185,7 @@ def update_user_avatar(user, avatar_style, avatar_content):
avatar_style, ['gravatar', 'manual']))
def bump_user_login_time(user):
user.last_login_time = datetime.datetime.now()
user.last_login_time = datetime.datetime.utcnow()
def reset_user_password(user):
password = auth.create_password()

View File

@ -74,7 +74,7 @@ class dotdict(dict): # pylint: disable=invalid-name
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
def parse_time_range(value, timezone=datetime.timezone(datetime.timedelta())):
def parse_time_range(value):
''' Return tuple containing min/max time for given text representation. '''
one_day = datetime.timedelta(days=1)
one_second = datetime.timedelta(seconds=1)
@ -84,14 +84,14 @@ def parse_time_range(value, timezone=datetime.timezone(datetime.timedelta())):
raise errors.ValidationError('Empty date format.')
if value == 'today':
now = datetime.datetime.now(tz=timezone)
now = datetime.datetime.utcnow()
return (
datetime.datetime(now.year, now.month, now.day, 0, 0, 0),
datetime.datetime(now.year, now.month, now.day, 0, 0, 0) \
+ one_day - one_second)
if value == 'yesterday':
now = datetime.datetime.now(tz=timezone)
now = datetime.datetime.utcnow()
return (
datetime.datetime(now.year, now.month, now.day, 0, 0, 0) - one_day,
datetime.datetime(now.year, now.month, now.day, 0, 0, 0) \

View File

@ -6,7 +6,7 @@ import falcon
def json_serializer(obj):
''' JSON serializer for objects not serializable by default JSON code '''
if isinstance(obj, datetime.datetime):
serial = obj.isoformat()
serial = obj.isoformat('T') + 'Z'
return serial
raise TypeError('Type not serializable')

View File

@ -43,7 +43,7 @@ def test_using_special_tokens(
post1 = test_ctx.post_factory(id=1)
post2 = test_ctx.post_factory(id=2)
post1.favorited_by = [db.PostFavorite(
user=auth_user, time=datetime.datetime.now())]
user=auth_user, time=datetime.datetime.utcnow())]
db.session.add_all([post1, post2, auth_user])
db.session.flush()
result = test_ctx.list_api.get(

View File

@ -56,8 +56,8 @@ def test_favorite_count(user_factory, post_factory):
post1 = post_factory()
post2 = post_factory()
db.session.add_all([
db.PostFavorite(post=post1, time=datetime.now(), user=user),
db.PostFavorite(post=post2, time=datetime.now(), user=user_factory()),
db.PostFavorite(post=post1, time=datetime.utcnow(), user=user),
db.PostFavorite(post=post2, time=datetime.utcnow(), user=user_factory()),
])
db.session.flush()
db.session.refresh(user)
@ -72,8 +72,8 @@ def test_liked_post_count(user_factory, post_factory):
post1 = post_factory()
post2 = post_factory()
db.session.add_all([
db.PostScore(post=post1, time=datetime.now(), user=user, score=1),
db.PostScore(post=post2, time=datetime.now(), user=user_factory(), score=1),
db.PostScore(post=post1, time=datetime.utcnow(), user=user, score=1),
db.PostScore(post=post2, time=datetime.utcnow(), user=user_factory(), score=1),
])
db.session.flush()
db.session.refresh(user)
@ -89,8 +89,8 @@ def test_disliked_post_count(user_factory, post_factory):
post1 = post_factory()
post2 = post_factory()
db.session.add_all([
db.PostScore(post=post1, time=datetime.now(), user=user, score=-1),
db.PostScore(post=post2, time=datetime.now(), user=user_factory(), score=1),
db.PostScore(post=post1, time=datetime.utcnow(), user=user, score=-1),
db.PostScore(post=post2, time=datetime.utcnow(), user=user_factory(), score=1),
])
db.session.flush()
db.session.refresh(user)

View File

@ -6,7 +6,7 @@ from szurubooru import db, errors, search
def fav_factory(user_factory):
def factory(post, user=None):
return db.PostFavorite(
post=post, user=user or user_factory(), time=datetime.datetime.now())
post=post, user=user or user_factory(), time=datetime.datetime.utcnow())
return factory
@pytest.fixture
@ -15,7 +15,7 @@ def score_factory(user_factory):
return db.PostScore(
post=post,
user=user or user_factory(),
time=datetime.datetime.now(),
time=datetime.datetime.utcnow(),
score=score)
return factory
@ -32,8 +32,8 @@ def feature_factory(user_factory):
def factory(post=None):
if post:
return db.PostFeature(
time=datetime.datetime.now(), user=user_factory(), post=post)
return db.PostFeature(time=datetime.datetime.now(), user=user_factory())
time=datetime.datetime.utcnow(), user=user_factory(), post=post)
return db.PostFeature(time=datetime.datetime.utcnow(), user=user_factory())
return factory
@pytest.fixture
@ -109,7 +109,7 @@ def test_filter_by_score(
db.session.add(
db.PostScore(
score=post.post_id,
time=datetime.datetime.now(),
time=datetime.datetime.utcnow(),
post=post,
user=user_factory()))
db.session.add_all([post1, post2, post3])