mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-30 03:41:50 -05:00
provide the timezone so that the UI doesn't have to
this will also ensure that UI doesn't use a different front end library that will yield different results than the underlying Python code
This commit is contained in:
committed by
Jared Tabor
parent
e5dd3a9626
commit
fbe2391b86
@@ -4,7 +4,9 @@
|
||||
import logging
|
||||
import datetime
|
||||
import dateutil.rrule
|
||||
from dateutil.tz import datetime_exists
|
||||
from operator import itemgetter
|
||||
import dateutil.parser
|
||||
from dateutil.tz import datetime_exists, tzutc
|
||||
|
||||
# Django
|
||||
from django.db import models
|
||||
@@ -94,6 +96,33 @@ class Schedule(CommonModel, LaunchTimeConfig):
|
||||
help_text=_("The next time that the scheduled action will run.")
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_zoneinfo(self):
|
||||
from dateutil.zoneinfo import get_zonefile_instance
|
||||
return [
|
||||
{'name': zone}
|
||||
for zone in sorted(get_zonefile_instance().zones)
|
||||
]
|
||||
|
||||
@property
|
||||
def timezone(self):
|
||||
utc = tzutc()
|
||||
_rrule = dateutil.rrule.rrulestr(
|
||||
self.rrule,
|
||||
tzinfos={x: utc for x in dateutil.parser.parserinfo().UTCZONE}
|
||||
)
|
||||
tzinfo = _rrule._dtstart.tzinfo
|
||||
if tzinfo == utc:
|
||||
return 'UTC'
|
||||
fname = tzinfo._filename
|
||||
all_zones = map(itemgetter('name'), Schedule.get_zoneinfo())
|
||||
all_zones.sort(key = lambda x: -len(x))
|
||||
for zone in all_zones:
|
||||
if fname.endswith(zone):
|
||||
return zone
|
||||
logger.warn('Could not detect valid zoneinfo for {}'.format(self.rrule))
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
def rrulestr(cls, rrule, **kwargs):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user