From b5bc0ec50cd96540ffd96c4abf13b485942235ce Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Wed, 8 Mar 2023 21:58:58 +0000 Subject: [PATCH] Switched to keeping time with UTC for easier timezones Removed useless JS --- gallery/api.py | 2 +- gallery/auth.py | 4 +- gallery/routing.py | 1 - gallery/static/js/main.js | 40 ++++++++----------- .../components/image-view/info-tab.sass | 1 + 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/gallery/api.py b/gallery/api.py index f20ee23..ede80c7 100644 --- a/gallery/api.py +++ b/gallery/api.py @@ -143,7 +143,7 @@ def upload(): # Save to database try: query = db.Posts(author_id = g.user.id, - created_at = dt.now(), + created_at = dt.utcnow(), file_name = img_name+'.'+img_ext, file_type = img_ext, image_exif = img_exif, diff --git a/gallery/auth.py b/gallery/auth.py index c0ba7be..adce6f5 100644 --- a/gallery/auth.py +++ b/gallery/auth.py @@ -100,7 +100,7 @@ def register(): register_user = db.Users(username=username, email=email, password=generate_password_hash(password), - created_at=dt.now()) + created_at=dt.utcnow()) db_session.add(register_user) db_session.commit() except exc.IntegrityError: @@ -148,7 +148,7 @@ def login(): ip_address=request.remote_addr, user_agent=request.user_agent.string, active=True, - created_at=dt.now()) + created_at=dt.utcnow()) db_session.add(session_query) db_session.commit() diff --git a/gallery/routing.py b/gallery/routing.py index 693ac17..9766f0c 100644 --- a/gallery/routing.py +++ b/gallery/routing.py @@ -1,7 +1,6 @@ """ Onlylegs Gallery - Routing """ -import os from datetime import datetime as dt from flask import Blueprint, render_template, current_app, request, g diff --git a/gallery/static/js/main.js b/gallery/static/js/main.js index e98f3df..d8cdaa0 100644 --- a/gallery/static/js/main.js +++ b/gallery/static/js/main.js @@ -1,24 +1,6 @@ let navToggle = true; document.onscroll = function() { - try { - document.querySelector('.background-decoration').style.opacity = `${1 - window.scrollY / 621}`; - document.querySelector('.background-decoration').style.top = `-${window.scrollY / 5}px`; - } catch (e) { - // Do nothing if banner not found - } - - try { - if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) { - document.querySelector('.banner').classList = 'banner banner-scrolled'; - } else { - document.querySelector('.banner').classList = 'banner'; - } - } - catch (e) { - // Do nothing if banner not found - } - if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) { document.querySelector('.jumpUp').classList = 'jumpUp jumpUp--show'; } else { @@ -35,9 +17,21 @@ function imgFade(obj) { $(obj).animate({opacity: 1}, 250); } -var times = document.getElementsByClassName('time'); -for (var i = 0; i < times.length; i++) { - var time = times[i].innerHTML; - var date = new Date(time); - times[i].innerHTML = date.toLocaleString('en-GB'); +let times = document.getElementsByClassName('time'); +for (let i = 0; i < times.length; i++) { + // Remove milliseconds + const raw = times[i].innerHTML.split('.')[0]; + + // Parse YYYY-MM-DD HH:MM:SS to Date object + const time = raw.split(' ')[1] + const date = raw.split(' ')[0].split('-'); + + // Format to YYYY/MM/DD HH:MM:SS + let formatted = date[0] + '/' + date[1] + '/' + date[2] + ' ' + time + ' UTC'; + + // Convert to UTC Date object + let dateTime = new Date(formatted); + + // Convert to local time + times[i].innerHTML = dateTime.toLocaleDateString() + ' ' + dateTime.toLocaleTimeString(); } diff --git a/gallery/themes/default/components/image-view/info-tab.sass b/gallery/themes/default/components/image-view/info-tab.sass index 31306e1..c6bea14 100644 --- a/gallery/themes/default/components/image-view/info-tab.sass +++ b/gallery/themes/default/components/image-view/info-tab.sass @@ -183,3 +183,4 @@ align-items: center border-radius: $rad + border: 1px solid $white