Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
autodoc_mock_imports = [
'cairocffi',
'flask',
'pytz',
'pyparsing',
'structlog',
'tzlocal',
Expand Down
8 changes: 4 additions & 4 deletions graphite_render/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from collections import defaultdict
from datetime import datetime
from io import BytesIO, StringIO
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

import pytz
from flask import Flask
from structlog import get_logger
from werkzeug.http import http_date
Expand Down Expand Up @@ -309,12 +309,12 @@ def render():
continue
graph_options[opt] = value

tzinfo = pytz.timezone(app.config['TIME_ZONE'])
tzinfo = ZoneInfo(app.config['TIME_ZONE'])
tz = RequestParams.get('tz')
if tz:
try:
tzinfo = pytz.timezone(tz)
except pytz.UnknownTimeZoneError:
tzinfo = ZoneInfo(tz)
except ZoneInfoNotFoundError:
errors['tz'] = "Unknown timezone: '{0}'.".format(tz)
request_options['tzinfo'] = tzinfo

Expand Down
13 changes: 6 additions & 7 deletions graphite_render/render/attime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from time import daylight

import pytz
from zoneinfo import ZoneInfo

months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
Expand All @@ -24,7 +23,7 @@
def parseATTime(s, tzinfo=None, now=None):
if tzinfo is None:
from ..app import app
tzinfo = pytz.timezone(app.config['TIME_ZONE'])
tzinfo = ZoneInfo(app.config['TIME_ZONE'])
s = s.strip().lower().replace('_', '').replace(',', '').replace(' ', '')
if s.isdigit():
if (
Expand All @@ -37,7 +36,7 @@ def parseATTime(s, tzinfo=None, now=None):
else:
return datetime.fromtimestamp(int(s), tzinfo)
elif ':' in s and len(s) == 13:
return tzinfo.localize(datetime.strptime(s, '%H:%M%Y%m%d'), daylight)
return datetime.strptime(s, '%H:%M%Y%m%d').replace(tzinfo=tzinfo)
if '+' in s:
ref, offset = s.split('+', 1)
offset = '+' + offset
Expand All @@ -54,7 +53,7 @@ def parseTimeReference(ref):
if isinstance(ref, datetime):
return ref
if not ref or ref == 'now':
return datetime.now(pytz.utc)
return datetime.now(timezone.utc)

# Time-of-day reference
i = ref.find(':')
Expand All @@ -78,7 +77,7 @@ def parseTimeReference(ref):
hour, min = 16, 0
ref = ref[7:]

refDate = datetime.now(pytz.utc).replace(hour=hour, minute=min, second=0)
refDate = datetime.now(timezone.utc).replace(hour=hour, minute=min, second=0)

# Day reference
if ref in ('yesterday', 'today', 'tomorrow'): # yesterday, today, tomorrow
Expand Down
6 changes: 3 additions & 3 deletions graphite_render/render/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from datetime import datetime, timedelta
from io import BytesIO
from urllib.parse import unquote_plus
from zoneinfo import ZoneInfo

import cairocffi as cairo
import pytz

from .datalib import TimeSeries
from ..utils import to_seconds
Expand Down Expand Up @@ -1815,9 +1815,9 @@ def setupTwoYAxes(self):
def setupXAxis(self):
from ..app import app
if self.userTimeZone:
tzinfo = pytz.timezone(self.userTimeZone)
tzinfo = ZoneInfo(self.userTimeZone)
else:
tzinfo = pytz.timezone(app.config['TIME_ZONE'])
tzinfo = ZoneInfo(app.config['TIME_ZONE'])

self.start_dt = datetime.fromtimestamp(self.startTime, tzinfo)
self.end_dt = datetime.fromtimestamp(self.endTime, tzinfo)
Expand Down
5 changes: 2 additions & 3 deletions graphite_render/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
limitations under the License."""
import calendar
import hashlib

import pytz
from datetime import timezone

from flask import request

Expand Down Expand Up @@ -111,4 +110,4 @@ def epoch(dt):
"""
Returns the epoch timestamp of a timezone-aware datetime object.
"""
return calendar.timegm(dt.astimezone(pytz.utc).timetuple())
return calendar.timegm(dt.astimezone(timezone.utc).timetuple())
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ dependencies = [
"PyYAML",
"cairocffi",
"pyparsing>2.0.0",
"pytz",
"structlog",
"tzlocal",
]
Expand Down
15 changes: 8 additions & 7 deletions tests/test_attime.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import datetime
import time
import pytz
from datetime import timezone
from zoneinfo import ZoneInfo

from graphite_render.render.attime import parseATTime

from . import TestCase


class AtTestCase(TestCase):
default_tz = pytz.utc
specified_tz = pytz.timezone('America/Los_Angeles')
default_tz = timezone.utc
specified_tz = ZoneInfo('America/Los_Angeles')

def test_absolute_time(self):
time_string = '12:0020150308'
expected_time = self.default_tz.localize(
datetime.datetime.strptime(time_string, '%H:%M%Y%m%d'))
expected_time = datetime.datetime.strptime(
time_string, '%H:%M%Y%m%d').replace(tzinfo=self.default_tz)
actual_time = parseATTime(time_string)
self.assertEqual(actual_time, expected_time)

expected_time = self.specified_tz.localize(
datetime.datetime.strptime(time_string, '%H:%M%Y%m%d'))
expected_time = datetime.datetime.strptime(
time_string, '%H:%M%Y%m%d').replace(tzinfo=self.specified_tz)
actual_time = parseATTime(time_string, self.specified_tz)
self.assertEqual(actual_time, expected_time)

Expand Down
Loading