Skip to content

Commit

Permalink
Fix timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jan 28, 2024
1 parent 0dcaebb commit 56ac168
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"""Minecraft中文标准译名查询网页,使用Flask编写的后端框架"""

from os import getenv
from datetime import date
from datetime import datetime

from flask import Flask, session, render_template, request, send_from_directory
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField

from flask_babel import Babel, format_date
from flask_babel import Babel
from flask_babel import lazy_gettext as _l
from babel.dates import get_timezone_name
from babel.dates import format_date, get_timezone, get_timezone_name
import geoip2.database
import geoip2.errors

Expand Down Expand Up @@ -42,8 +42,9 @@ def get_timezone_from_ip():


@flask_app.before_request
def determine_timezone():
def determine_locale_and_timezone():
"""根据IP获取时区"""
session["locale"] = get_locale()
session["timezone"] = get_timezone_from_ip()


Expand All @@ -59,7 +60,10 @@ def index():
"""主页面"""

# 时区
timezone_str = get_timezone_name(session["timezone"], locale=get_locale())
tzinfo = get_timezone(session["timezone"])
timezone_str = get_timezone_name(session["timezone"], locale=session["locale"])
date_tz = datetime.now(tz=tzinfo).date()
date_str_t = format_date(date_tz, "long", locale=session["locale"])

form = QueryForm()

Expand All @@ -86,8 +90,8 @@ def index():
input_value=query_str,
keys=keys,
translation=selected_translation,
date_str=date.today(),
date_str_t=format_date(date.today(), "long"),
date_str=date_tz,
date_str_t=date_str_t,
timezone_str=timezone_str,
)

Expand Down

0 comments on commit 56ac168

Please sign in to comment.