Atomstrom/ddate.py

61 lines
2.7 KiB
Python
Raw Permalink Normal View History

# This file is part of Atomstrom
# Copyright (C) 2013 Ronald Schaten <ronald@schatenseite.de>
#
# Atomstrom is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from calendar import isleap
class ddate(object):
def __init__(self, aDate = datetime.now()):
self.dSeasonNum = 0
self.dDayOfWeek = 0
self.dDayOfSeason = 0
self.dYOLD = 0
self.dSeasonHoliday = False
self.dApostleHoliday = False
self.dStTibs = False
dayOfYear = aDate.timetuple().tm_yday - 1
self.dStTibs = isleap(aDate.year) and (aDate.month == 2) and (aDate.day == 29)
if(isleap(aDate.year) and (dayOfYear >= 60)):
dayOfYear -= 1
self.dDayOfWeek = (dayOfYear % 5)
self.dSeasonNum, self.dDayOfSeason = divmod(dayOfYear, 73)
self.dDayOfSeason += 1
self.dYOLD = aDate.year + 1166
if(self.dDayOfSeason==5):
self.dApostleHoliday = True
if(self.dDayOfSeason==50):
self.dSeasonHoliday = True
def __str__(self):
strWeekday = ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"][self.dDayOfWeek]
suffixes = ["th", "st", "nd", "rd", ] + ["th"] * 16 + (["th", "st", "nd", "rd", ] + ["th"] * 6) * 10
strDaynum = '%d%s' % (self.dDayOfSeason, suffixes[self.dDayOfSeason % 100])
strSeason = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"][self.dSeasonNum]
strHolidayApostle = ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"][self.dSeasonNum]
strHolidaySeason= ["Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"][self.dSeasonNum]
if(self.dStTibs):
return 'St. Tib\'s Day, YOLD %d!' % self.dYOLD
else:
msg = u'Today is %s, the %s day of %s in the YOLD %d.' % (strWeekday, strDaynum, strSeason, self.dYOLD)
if(self.dSeasonHoliday):
msg = u'%s\nCelebrate %s!' % (msg, strHolidaySeason)
if(self.dApostleHoliday):
msg = u'%s\nCelebrate %s!' % (msg, strHolidayApostle)
return msg
2013-04-09 21:39:02 +00:00
# -*- coding: utf-8 -*-