/
posical.py
477 lines (429 loc) · 19.7 KB
/
posical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#! usr/bin/env python #
# -*- coding: utf-8 -*-
"""
Posical is a Python 3 module that models a generalized calendar reform with regularly-sized weeks and months and an intercalary period, based on August Comte's Positivist Calendar.
"""
import datetime,operator
from calendar import isleap as std_isleap
from nonzero import nz
POSIMONTHS = ('Moses', 'Homer', 'Aristotle', 'Archimedes', 'Caesar',
'Saint Paul', 'Charlemagne', 'Dante', 'Gutenberg',
'Shakespeare', 'Descartes', 'Frederick', 'Bichat',
'Complementary')
REGMONTHS = ('January', 'February', 'March', 'April', 'May', 'June', 'July',
'October', 'November', 'December', 'Intercalary')
# Ordinal code stolen from stack overflow.
def ordinal(n):
return "%d%s" % (n,"tsnrhtdd"[(n/10%10!=1)*(n%10<4)*n%10::4])
def horicat(strings):
lines = ["".join(line) for line in list(zip(*strings))]
return "\n".join(lines)
def design_calendar():
"""
A simple interactive function that asks the user for input in creating a
calendar reform. If no input is given it defaults to the settings for
Comte's Positivist Calendar.
"""
d_i_week = int(input("How many days in a week? ") or 7)
w_i_month = int(input("How many weeks in a month? ") or 4)
year_1 = int(input("When is year 1? ") or 1789)
name = input("What is the calendar's name? ")
return AlternateCal(w_i_month, d_i_week, year_1, name)
class AlternateCal(object):
"""
A class to generate Alternate Date objects. An AlternateDate object
Represents a date (day, month, year) in an idealized calendar, extending
Without disruption in both directions, with the following property: it
Consists of n months, all of the same size, with 365 % n epagomenal days
At the end of the year that are not days of the week and belong to no month.
>>> cal = AlternateCal()
>>> cal.from_gregorian(1789, 1, 1)
positivist date(1, 1, 1)
>>> cal.from_gregorian(1788, 1, 1)
positivist date(-1, 1, 1)
>>> cal.from_gregorian(1, 1, 1)
positivist date(-1788, 1, 1)
>>> cal.from_gregorian(1788, 12, 31)
positivist date(-1, 14, 2)
>>> cal.from_gregorian(1789, 12, 31)
positivist date(1, 14, 1)
>>> print(cal.from_gregorian(1788, 6, 1))
Saturday, 13rd of Saint Paul, -1: St. Gregory the Great
>>> print(cal.from_gregorian(1789, 6, 1))
Friday, 12nd of Saint Paul, 1: St. Pulcheria
>>> import datetime
>>> cal.date(1, 1, 1) - datetime.timedelta(days=1)
positivist date(-1, 14, 2)
>>> cal.from_gregorian(1, 12, 31) + datetime.timedelta(days=1)
positivist date(-1787, 1, 1)
>>> print(cal.date(1800, 1, 1))
Monday, 1st of Moses, 1800: Cadmus
>>> print(cal.date(1801, 1, 1))
Monday, 1st of Moses, 1801: Prometheus
"""
def __init__(calendar, w_i_month=4, d_i_week=7, year_1=1789, input_name=""):
calendar.days_in_a_month = d_i_week * w_i_month
calendar.days_in_a_week = d_i_week
calendar.weeks_in_a_month = w_i_month
calendar.months_in_a_year = 365 // calendar.days_in_a_month
calendar.epagomenal_days = 365 % calendar.days_in_a_month
name_choices = ('New Adjusted', 'Utilitarian', 'Lycurgian',
'Multi-Manifold', 'Positivist', 'Crepuscular',
'Urquhart', 'Adamantine', 'Organic Non-Repeating',
'Antediluvian', 'Re-Corresponding')
if input_name:
calendar.name = input_name
else:
calendar.name = name_choices[hash((w_i_month, d_i_week, year_1)) % 11]
calendar.year_offset = year_1 - 1
calendar.MINYEAR = nz(1) - calendar.year_offset
if calendar.name == 'Positivist':
calendar.MONTHS = POSIMONTHS
else:
calendar.MONTHS = REGMONTHS
calendar.DAYS = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')
calendar.SAINTS = ('Prometheus', 'Hercules', 'Orpheus', 'Ulysses',
'Lycurgus', 'Romulus', 'NUMA', 'Belus', 'Sesostris', 'Menu',
'Cyrus', 'Zoroaster', 'The Druids', 'BUDDHA', 'Fo-Hi', 'Lao-Tseu',
'Meng-Tseu', 'Theocrats of Tibet', 'Theocrats of Japan',
'Mano-Capac', 'CONFUCIUS', 'Abraham', 'Samuel', 'Solomon',
'Isaiah', 'St. John the Baptist', 'Haroun-al-Raschid',
'MUHAMMAD', 'Hesiod', 'Tyrt\u00E6us', 'Anacreon', 'Pindar',
'Sophocles', 'Theocritus', '\u00C6SCHYLUS', 'Scopas', 'Zeuxis',
'Ictinus', 'Praxiteles', 'Lysippus', 'Apelles', 'PHIDIAS',
'\u00C6sop', 'Plautus', 'Terence', 'Phaedrus', 'Juvenal',
'Lucian', 'ARISTOPHANES', 'Ennius', 'Lucretius', 'Horace',
'Tibullus', 'Ovid', 'Lucan', 'VIRGIL', 'Anaximander',
'Anaximenes', 'Heraclitus', 'Anaxagoras', 'Democritus',
'Herodotus', 'THALES', 'Solon', 'Xenophanes', 'Empedocles',
'Thucydides', 'Archytas', 'Apollonius of Tyana', 'PYTHAGORAS',
'Aristippus', 'Antisthenes', 'Zeno', 'Cicero', 'Epictetus',
'Tacitus', 'SOCRATES', 'Xenocrates', 'Philo of Alexandria',
'St. John the Evangelist', 'St. Justin',
'St.Clement of Alexandria', 'Origen', 'PLATO', 'Theophrastus',
'Herophilus', 'Erasistratus', 'Celsus', 'Galen', 'Avicenna',
'HIPPOCRATES', 'Euclid', 'Aristeus', 'Theodisius of Bithynia',
'Hero', 'Pappus', 'Diophantus', 'APOLLONIUS', 'Eudoxus',
'Pytheas', 'Aristarchus', 'Eratosthenes', 'Ptolemy',
'Albategnius', 'HIPPARCHUS', 'Varro', 'Columella', 'Vitruvius',
'Strabo', 'Frontinus', 'Plutarch', 'PLINY THE ELDER', 'Miltiades',
'Leonidas', 'Aristides', 'Cimon', 'Xenophon', 'Phocion',
'THEMISTOCLES', 'Pericles', 'Philip', 'Demosthenes',
'Ptolemy Lagus', 'Philopoemen', 'Polybius', 'ALEXANDER',
'Junius Brutus', 'Camillus', 'Fabricius', 'Hannibal',
'Paulus Aemilius', 'Marius', 'SCIPIO', 'Augustus', 'Vespasian',
'Hadrian', 'Antonius', 'Papinian', 'Alexander Severus', 'TRAJAN',
'St. Luke', 'St. Cyprian', ' St.Athanasius', 'St. Jerome',
'St. Ambrose', 'St. Monica', ' St.AUGUSTINE', 'Constantine',
'Theodosius', 'St. Chrysostom', ' St.Genevieve of Paris',
'St. Pulcheria', 'St. Gregory the Great', 'HILDEBRAND',
'St. Benedict', 'St. Boniface', 'St. Isidore of Seville',
'Lanfranc', 'Heloise', "Architects of Middle Ages", ' St.BERNARD',
'St. Francis Xavier', 'St. Charles Borromeo', 'St. Theresa',
'St. Vincent de Paul', 'Bourdaloue', 'William Penn', 'BOSSUET',
'Theodoric the Great', 'Pelayo', 'Otho the Great', 'St. Henry',
'Villers', 'Don John of Austria', 'ALFRED', 'Charles Martel',
'The Cid', 'Richard I', 'Joan of Arc', 'Albuquerque', 'Bayard',
'GODFREY', 'St. Leo the Great', 'Gerbert', 'Peter the Hermit',
'Suger', 'Alexander III', 'St. Francis of Assisi', 'INNOCENT III',
'St. Clotilde', 'St. Bathilda', 'St. Stephen of Hungary',
'St. Elizabeth of Hungary', 'Blanche of Castille',
'St. Ferdinand III', 'ST. LOUIS', 'The Troubadours', 'Boccaccio',
'Rabelais', 'Cervantes', 'La Fontain', 'De Foe', 'ARISTO',
'Leonardo da Vinci', 'Michael Angelo', 'Holbein', 'Poussin',
'Velásquez', 'Teniers', 'RAPHAEL', 'Froissart', 'Camoens',
'The Spanish Romancers', 'Chateaubriand', 'Walter Scott',
'Manzoni', 'TASSO', 'Petrarca', 'Thomas \u00E0 Kempis',
'Mme. de Lafayette', 'F\u00E9n\u00E9lon', 'Klopstock', 'Byron',
'MILTON', 'Marco Polo', 'Jacques Coeur', 'Vasco de Gama',
'Napier', 'Lacaille', 'Cook', 'COLUMBUS', 'Benvenuto Cellini',
'Amontons', 'Harrison', 'Dollond', 'Arkwright', 'Cont\u00e9',
'VAUCANSON', 'Stevin', 'Mariotte', 'Papin', 'Black', 'Jouffroy',
'Dalton', 'WATT', 'Bernard de Palissy', 'Guglielmini',
'Duhamel (du Monceau)', 'Saussure', 'Coulomb', 'Carnot',
'MONTGOLFIER', 'Lope de Vega', 'Moreto', 'Rojas', 'Otway',
'Lessing', 'Goethe', 'CALDERON', 'Tirso', 'Vondel', 'Racine',
'Voltaire', 'Metastasio', 'Schiller', 'CORNEILLE', 'Almarcon',
'Mme. de Motteville', 'Mme. de S\u00E9vign\u00E9', 'Lesage',
'Mme. de Staal', 'Fielding', 'MOLIERE', 'Pergolese', 'Sacchini',
'Gluck', 'Beethoven', 'Rossini', 'Bellini', 'MOZART',
'Albertus Magnus', 'Roger Bacon', 'St. Bonaventura', 'Ramus',
'Montaigne', 'Campanella', 'ST. THOMAS AQUINAS', 'Hobbes',
'Pascal', 'Locke', 'Vauvenargues', 'Diderot', 'Cabanis',
'LORD BACON', 'Grotius', 'Fontenelle', 'Vico', 'Fr\u00E9ret',
'Montesquieu', 'Buffon', 'LEIBNITZ', 'Robertson', 'Adam Smith',
'Kant', 'Condercet', 'Joseph de Maistre', 'Hegel', 'HUME',
'Marie de Molina', 'Cosmo de Medici the Elder',
'Philippe de Comines', 'Isabella of Castille', 'Charles V',
'Henry IV', 'LOUIS XI', "L'H\u0244pital", 'Barneveldt',
'Gustavus Adolphus', 'De Witt', 'Ruyter', 'William III',
'WILLIAM THE SILENT', 'Ximenes', 'Sully', 'Mazarin', 'Colbert',
"D'Aranda", 'Turgot', 'RICHELIEU', 'Sidney', 'Franklin',
'Washington', 'Jefferson', 'Bolivar', 'Francia', 'CROMWELL',
'Copernicus', 'Kepler', 'Huyghens', 'James Bernouilli', 'Bradley',
'Volta', 'GALILEO', 'Vieta', 'Wallis', 'Clairaut', 'Euler',
"D'Alembert", 'Lagrange', 'NEWTON', 'Bergmann', 'Priestley',
'Cavendish', 'Guyton Morveau', 'Berthollet', 'Berzelius',
'LAVOISIER', 'Harvey', 'Bo\u0235rhaave', 'Linn\u0230us', 'Haller',
'Lamarck', 'Broussais', 'GALL', 'Festival of All the Dead',
'Festival of Holy Women')
calendar.LEAPSAINTS = ('Cadmus', 'Theseus', 'Tiresias', '', '', '',
'', 'Semiramus', '', '', '', '', 'Ossian', '', '', '', '', '', '',
'Tamehameha', '', 'Joseph', '', 'David', '', '', 'Abderrahman',
'', '', 'Sappho', '', '', 'Euripides', 'Longus', '', '', '', '',
'', '', '', '', 'Pilpay', '', 'Menander', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', 'Leucippus', '', '', '', '',
'', '', 'Philolaus', '', '', '', '', '', 'Pliny the Younger',
'Arrian', '', '', '', '', '', 'St. Irenaeus', '', 'Tertullian',
'', '', '', '', '', '', 'Averrhoes', '', '', '', '', 'Ctesibius',
'', '', '', 'Aratus', 'Nearchus', 'Berosus', 'Sosigenes', '',
'Nasir-Eddin', '', '', '', '', '', '', '', '', '', '', '', '', '',
'Epaminondas', '', '', '', '', '', '', '', '', '', 'Cincinnatus',
'Regulus', '', '', 'The Gracchi', '', 'Mæcenas', 'Titus',
'Nerva', 'Marcus Aurelius', 'Ulpian', 'Aetius', '', 'St. James',
'', '', '', '', '', '', '', '', 'St. Basil', '', 'Marcian', '',
'', 'St. Anthony', 'St. Austin', 'St. Bruno', 'St. Anselm',
'Beatrice', 'St. Benezet', '', 'Ignatius Loyola',
'Fredrick Borromeo', 'St.Catharine of Siena',
"Abb\u00E9 de l'Ep\u00E9e", 'ClaudeFleury', 'George Fox', '', '',
'', 'Henry the Fowler', '', 'La Valette', 'John Sobieski', '', '',
'Tancred', 'Saladin', 'Marina', 'Sir Walter Raleigh', '', '',
'Leo IV', 'PeterDamian', '', 'St. Eligius', 'Becket',
'St. Dominic', '', '', 'St. Mathilda of Tuscany',
'Mathias Corvinus', '', '', 'Alfonso X', '', '', 'Chaucer',
'Swift', '', 'Burns', 'Goldsmith', '', 'Titian', 'Paul Veronese',
'Rembrandt', 'Lesueuer', 'Murillo', 'Rubens', '', 'Joinville',
'Spenser', '', '', 'James Fenimore Cooper', '', '', '',
'L. of Granada & Bunyan', 'Mme. de Sta\u00EBl',
'St. Francis of Sales', 'Gessner', '\u00E9. Mercoeur & Shelly',
'', 'Chardin', 'Gresham', 'Magellan', 'Briggs', 'Delambre',
'Tasman', '', '', 'Wheatstone', 'Pierre Leroy', 'Graham',
'Jacquard', '', '', 'Torricelli', 'Boyle', 'Worcester', '',
'Fulton', 'Thilorier', '', '', 'Riquet', 'Bourgelat', 'Bouguer',
'Borda', 'Vauban', '', 'Montalvan', 'Guillem de Castro',
'Guevara', '', '', '', '', '', '', '', '', 'Alfieri', '', '', '',
'Mme. Roland', 'Lady Montagu', 'Sterne', 'Miss Edgeworth',
'Richardson', '', 'Palestrina', 'Gr\u00E9try', 'Lully', 'Handel',
'Weber', 'Donizeti', '', 'John of Salisbury', 'Raymond Lully',
'Joachim', 'The Cardinal of Cusa', 'Erasmus', 'Sir Thomas More',
'', 'Spinoza', 'Giordano Bruno', 'Malebranche', 'Mme. de Lambert',
'Duclos', 'George Leroy', '', 'Cujas', 'Maupertuis', 'Herder',
'Winckle-mann', "D'Aguesseau", 'Oken', '', 'Gibbon', 'Dunoyer',
'Fichte', 'Ferguson', 'Bonald', 'Sophie Germain', '', '', '',
'Guicciardini', '', 'Sixtus V', '', '', '', '', '', '', '', '',
'', '', 'Oxenstiern', 'Walpole', 'Louis XIV', 'Pombal',
'Campomanes', '', 'Lambert', 'Hampden', 'Kosciusko', 'Madison',
"Toussaint L'Ouverture", '', '', 'Tycho Brah\u00E9', 'Halley',
'Varignon', 'John Bernouilli', 'R\u00F5mer', 'Sauveur', '',
'Harriot', 'Fermat', 'Poinsot', 'Monge', 'Daniel Bernouilli',
'Joseph Fourier', '', 'Scheele', 'Davy', '', 'Geoffroy', '',
'Ritter', '', 'Charles Bell', 'Stahl & Barthez',
'Bernard de Jussieu', "Vicq-d'Azyr", 'Blainville', 'Morgagni', '',
'', 'Festival of Holy Women')
class AlternateDate(object):
"""
A date object that's designed to behave analagously to the standard
library's datetime date objects.
To begin creating date objects, first create an AlternateCal
object. That can then generate objects using the today() or the
from_gregorian() methods.
"""
def __init__(self, year, month, day, altcal):
self.year = nz(year)
self.month = nz(month)
self.day = nz(day)
self.day_of_year = nz((month - 1) * altcal.weeks_in_a_month * altcal.days_in_a_week + day)
self.gregorian = altcal.to_gregorian(self.total_days())
if self.day_of_year > 366:
raise ValueError("Date exceeds days in year")
if self.year < altcal.MINYEAR:
raise ValueError("Year is earlier than minimum of {}".format(altcal.MINYEAR))
self.is_leap = std_isleap(self.gregorian.year)
self.weekday = nz(altcal.get_weekday(self.day))
self.month_name = altcal.get_month_name(self.month)
self.day_name = altcal.get_day_name(self.day_of_year,
self.is_leap)
self.weekday_name = altcal.get_weekday_name(self.weekday)
def total_days(self):
"""
Return the total number of days since year 1.
"""
year = self.year + calendar.year_offset
d_o_year_offset = int(self.day_of_year) - 1
return datetime.date(year, 1, 1).toordinal() + d_o_year_offset
def replace(self, year=None, month=None, day=None):
new_year = nz(year) or self.year
new_month = nz(month) or self.month
new_day = nz(day) or self.day
return calendar.date(new_year, new_month, new_day)
def timetuple(self):
return self.gregorian.timetuple()
def toordinal(self):
return self.gregorian.toordinal()
def weekday(self):
"""
Following the datetime.date weekday() model, returns 0-indexed weekday int
"""
return int(self.weekday) - 1
def isoweekday(self):
return self.weekday
def isocalendar(self):
return self.gregorian.isocalendar()
def isoformat(self):
return "{}-{:02}-{:02}".format(self.year, self.month, self.day)
def __str__(self):
if self.month is calendar.months_in_a_year + 1:
return "{}, {}".format(self.day_name, self.year)
else:
return "{}, {} of {}, {}: {}".format(self.weekday_name,
ordinal(self.day), self.month_name,
self.year, self.day_name)
def __repr__(self):
return '%s date(%d, %d, %d)' % (calendar.name.lower(),
self.year, self.month,
self.day)
def __add__(self, arg):
return self.calendar.from_gregorian(arg + self.gregorian)
__radd__ = __add__
def __sub__(self, arg):
return self.calendar.from_gregorian(self.gregorian - arg)
def __rsub__(self, arg):
return self.calendar.from_gregorian(arg - self.gregorian)
def __eq__(self, other_date):
return other_date == self.gregorian
def __gt__(self, other_date):
return self.gregorian > other_date
def __lt__(self, other_date):
return self.gregorian < other_date
def __ge__(self, other_date):
return self.gregorian >= other_date
def __le__(self, other_date):
return self.gregorian <= other_date
AlternateDate.calendar = calendar
calendar.date_class = AlternateDate
calendar.min = calendar.date(calendar.MINYEAR, 1, 1)
calendar.max = calendar.from_gregorian(datetime.date.max)
def from_gregorian(self, *args):
"""
Create an alternate date given one of three formats:
1. Three integers in Gregorian Y, M, D format.
2. A datetime date object.
"""
if not args:
raise ValueError("No Gregorian date provided")
if len(args) == 3:
year, month, day = args
gregorian = datetime.date(year, month, day)
elif len(args) == 1 and isinstance(args[0], datetime.date):
gregorian = args[0]
else:
raise ValueError("Please provide a datetime object or 3 ints in Y-M-D format")
year = nz(gregorian.year) - self.year_offset
day_of_year = gregorian.timetuple().tm_yday
month = ((day_of_year - 1) // self.days_in_a_month) + 1
day = day_of_year % self.days_in_a_month or self.days_in_a_month
return self.date_class(year, month, day, self)
def to_gregorian(self, days):
return datetime.date.fromordinal(days)
def date(self, *args):
"""
Create an alternate date given a 'native' input:
Three integers in Y, M, D format of the alternate calendar.
"""
if not args:
raise ValueError("Please provide values in Y, M, D format")
year, month, day = args
return self.date_class(year, month, day, self)
def today(self):
return self.from_gregorian(datetime.date.today())
def fromtimestamp(t):
return self.from_gregorian(datetime.date.fromtimestamp(t))
def fromordinal(o):
return self.from_gregorian(datetime.date.fromordinal(o))
def get_weekday(self, day):
return day % self.days_in_a_week or self.days_in_a_week
def get_weekday_name(self, weekday):
weekday = int(weekday)
if weekday > len(self.DAYS):
return ordinal(weekday) + " Weekday"
else:
return self.DAYS[weekday - 1]
def get_month_name(self, month):
month = int(month)
if month > len(self.MONTHS):
return ordinal(month) + " Month"
else:
return self.MONTHS[(month - 1)]
def get_day_name(self, day, is_leap):
day = int(day)
if day > len(self.SAINTS):
return ""
elif is_leap and self.LEAPSAINTS[day - 1]:
return self.LEAPSAINTS[day - 1]
else:
return self.SAINTS[day - 1]
def is_leap(self, year):
return std_isleap(year + self.year_offset)
def print_month(self, year=None, month=None):
"""
Print out a formatted one-page calendar for the specified year/month.
"""
page = []
maxwidth = max(len(saint) for saint in self.SAINTS + self.LEAPSAINTS)
if not year or not month:
today = self.today()
year = today.year
month = today.month
if month == self.months_in_a_year + 1:
intercal = True
page.append("THE {} EPAGOMENAL DAYS OF THE YEAR {}".format(
self.name.upper(), year))
else:
intercal = False
page.append("THE {} MONTH OF {}, {}".format(
self.name.upper(),
self.get_month_name(month).upper(),
year))
month_offset = (month - 1) * self.weeks_in_a_month * self.days_in_a_week
for week in range(self.weeks_in_a_month):
calbox = []
week_offset = (week * self.days_in_a_week)
for date in range(1 + week_offset,
week_offset + self.days_in_a_week + 1):
day_of_year = month_offset + date
if day_of_year > len(self.SAINTS):
break
if not intercal:
weekday = self.get_weekday(date)
wkd_name = self.get_weekday_name(weekday)
datestr = str(date)
else:
weekday = 0
wkd_name = ""
datestr = ""
saint = self.get_day_name(day_of_year, self.is_leap(year))
if day_of_year == self.today().day_of_year:
saint = "*" + saint + "*"
height = 4
box = []
cap = "|" if day_of_year % self.days_in_a_week == 0 else ""
box.append("+".ljust(maxwidth + 1, '-') + cap)
if wkd_name:
box.append("|" + wkd_name.ljust(maxwidth - len(datestr))
+ datestr + cap)
else:
box.append("|".ljust(maxwidth + 1) + cap)
for i in range(height):
box.append("|".ljust(maxwidth + 1) + cap)
box.append("|" + saint.rjust(maxwidth) + cap)
calbox.append(box)
cal_layout = horicat(calbox)
page.append(cal_layout)
return "\n".join(page)
def __str__(self):
return "The {} calendar, consisting of {}-day weeks, {}-week months, and {}-month years, with {} epagomenal day(s).".format(
self.name, self.days_in_a_week, self.weeks_in_a_month,
self.months_in_a_year, self.epagomenal_days)
if __name__ == "__main__":
import doctest
doctest.testmod()