mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-10-31 00:37:54 +00:00
Calendar fix
This commit is contained in:
parent
d15813630f
commit
144856d30a
2 changed files with 22 additions and 21 deletions
|
@ -1,6 +1,8 @@
|
||||||
from toontown.toonbase import ToontownGlobals, TTLocalizer
|
from toontown.toonbase import ToontownGlobals, TTLocalizer
|
||||||
|
from toontown.parties import ToontownTimeZone
|
||||||
import calendar, datetime
|
import calendar, datetime
|
||||||
|
|
||||||
|
TIME_ZONE = ToontownTimeZone.ToontownTimeZone()
|
||||||
TRICK_OR_TREAT = 0
|
TRICK_OR_TREAT = 0
|
||||||
WINTER_CAROLING = 1
|
WINTER_CAROLING = 1
|
||||||
CAROLING_REWARD = 100
|
CAROLING_REWARD = 100
|
||||||
|
@ -92,36 +94,32 @@ def getHoliday(id):
|
||||||
return Holidays.get(id, {})
|
return Holidays.get(id, {})
|
||||||
|
|
||||||
def getServerTime(date):
|
def getServerTime(date):
|
||||||
epoch = datetime.datetime.fromtimestamp(0, base.cr.toontownTimeManager.serverTimeZone)
|
epoch = datetime.datetime.fromtimestamp(0, TIME_ZONE)
|
||||||
delta = date - epoch
|
delta = date - epoch
|
||||||
|
|
||||||
return delta.total_seconds()
|
return delta.total_seconds()
|
||||||
|
|
||||||
def getStartDate(holiday, year=None):
|
def getStartDate(holiday, rightNow=None):
|
||||||
if 'startDate' in holiday:
|
if not rightNow:
|
||||||
return holiday['startDate']
|
rightNow = datetime.datetime.now()
|
||||||
|
|
||||||
rightNow = datetime.datetime.now()
|
startMonth = holiday['startMonth'] if 'startMonth' in holiday else rightNow.month
|
||||||
startMonth = holiday['startMonth'] if 'startMonth' in holiday else (rightNow.month if 'weekDay' in holiday else 1)
|
|
||||||
startDay = holiday['startDay'] if 'startDay' in holiday else (rightNow.day if 'weekDay' in holiday else calendar.monthrange(rightNow.year, startMonth)[0])
|
startDay = holiday['startDay'] if 'startDay' in holiday else (rightNow.day if 'weekDay' in holiday else calendar.monthrange(rightNow.year, startMonth)[0])
|
||||||
startDate = datetime.datetime(year if year else rightNow.year, startMonth, startDay, tzinfo=base.cr.toontownTimeManager.serverTimeZone)
|
startDate = datetime.datetime(rightNow.year, startMonth, startDay, tzinfo=TIME_ZONE)
|
||||||
holiday['startDate'] = startDate
|
|
||||||
|
|
||||||
return startDate
|
return startDate
|
||||||
|
|
||||||
def getEndDate(holiday, year=None):
|
def getEndDate(holiday, rightNow=None):
|
||||||
if 'endDate' in holiday:
|
if not rightNow:
|
||||||
return holiday['endDate']
|
rightNow = datetime.datetime.now()
|
||||||
|
|
||||||
rightNow = datetime.datetime.now()
|
endMonth = holiday['endMonth'] if 'endMonth' in holiday else rightNow.month
|
||||||
endMonth = holiday['endMonth'] if 'endMonth' in holiday else (rightNow.month if 'weekDay' in holiday else 12)
|
|
||||||
endDay = holiday['endDay'] if 'endDay' in holiday else (rightNow.day if 'weekDay' in holiday else calendar.monthrange(rightNow.year, endMonth)[1])
|
endDay = holiday['endDay'] if 'endDay' in holiday else (rightNow.day if 'weekDay' in holiday else calendar.monthrange(rightNow.year, endMonth)[1])
|
||||||
endYear = year if year else rightNow.year
|
endYear = rightNow.year
|
||||||
|
|
||||||
if 'startMonth' in holiday and holiday['startMonth'] > endMonth:
|
if 'startMonth' in holiday and holiday['startMonth'] > endMonth:
|
||||||
endYear += 1
|
endYear += 1
|
||||||
|
|
||||||
endDate = datetime.datetime(endYear, endMonth, endDay, tzinfo=base.cr.toontownTimeManager.serverTimeZone)
|
endDate = datetime.datetime(endYear, endMonth, endDay, tzinfo=TIME_ZONE)
|
||||||
holiday['endDate'] = endDate
|
|
||||||
|
|
||||||
return endDate
|
return endDate
|
|
@ -161,22 +161,25 @@ class CalendarGuiDay(DirectFrame):
|
||||||
if self.myDate.weekday() == holiday['weekDay']:
|
if self.myDate.weekday() == holiday['weekDay']:
|
||||||
self.addTitleAndDescToScrollList(title, description)
|
self.addTitleAndDescToScrollList(title, description)
|
||||||
elif 'startMonth' in holiday or 'startDay' in holiday:
|
elif 'startMonth' in holiday or 'startDay' in holiday:
|
||||||
startDate = HolidayGlobals.getStartDate(holiday, self.myDate.year)
|
startDate = HolidayGlobals.getStartDate(holiday, self.myDate)
|
||||||
endDate = HolidayGlobals.getEndDate(holiday, self.myDate.year)
|
endDate = HolidayGlobals.getEndDate(holiday, self.myDate)
|
||||||
|
|
||||||
if self.myDate.date() == startDate.date():
|
if self.isDateMatch(self.myDate, startDate):
|
||||||
if startDate.date() == endDate.date():
|
if self.isDateMatch(startDate, endDate):
|
||||||
description = '%s. %s' % (title, description)
|
description = '%s. %s' % (title, description)
|
||||||
else:
|
else:
|
||||||
description = '%s. %s %s %s' % (title, description, TTLocalizer.CalendarEndsAt, endDate.strftime('%b %d'))
|
description = '%s. %s %s %s' % (title, description, TTLocalizer.CalendarEndsAt, endDate.strftime('%b %d'))
|
||||||
|
|
||||||
self.addTitleAndDescToScrollList(title, description)
|
self.addTitleAndDescToScrollList(title, description)
|
||||||
elif self.myDate.date() == endDate.date():
|
elif self.isDateMatch(self.myDate, endDate):
|
||||||
title = '%s %s' % (TTLocalizer.CalendarEndOf, title)
|
title = '%s %s' % (TTLocalizer.CalendarEndOf, title)
|
||||||
description = '%s. %s %s' % (title, TTLocalizer.CalendarStartedOn, startDate.strftime('%b %d'))
|
description = '%s. %s %s' % (title, TTLocalizer.CalendarStartedOn, startDate.strftime('%b %d'))
|
||||||
|
|
||||||
self.addTitleAndDescToScrollList(title, description)
|
self.addTitleAndDescToScrollList(title, description)
|
||||||
|
|
||||||
|
def isDateMatch(self, date1, date2):
|
||||||
|
return date1.day == date2.day and date1.month == date2.month
|
||||||
|
|
||||||
def addTitleAndDescToScrollList(self, title, desc):
|
def addTitleAndDescToScrollList(self, title, desc):
|
||||||
textSize = self.ScrollListTextSize
|
textSize = self.ScrollListTextSize
|
||||||
descTextSize = 0.05
|
descTextSize = 0.05
|
||||||
|
|
Loading…
Reference in a new issue