#! /usr/bin/env python

""" Prints a date according to the 1849 Positivist Calendar of Auguste Comte.

Usage: pdate [+format] [day month year]

For more information try `pdate --help` """

description = """
Prints a date according to the 1849 Positivist Calendar of Auguste Comte.

Inspired by the original Positivist Calendar viewable at
	http://gallica.bnf.fr/ark:/12148/bpt6k6108866f/f359.image
and by the Interactive Positivist Calendar at
	http://myweb.ecu.edu/mccartyr/pos-cal.html

If called with no arguments, pdate prints the current system date. If a date
is specified, with [day month year] given as numbers, pdate prints the
chosen date.

In the tradition of date and ddate, pdate can be called with an optional
format string, in which case the date will be printed in the format specified
by the string. The fields are:

	%A	Name of the day. (Each ordinary day commemorates a Positivist
		saint; in many cases a minor saint replaces the	usual one in
		a leap year. There are also two festival days which appear
		outside any month.)
	%D	Day of the week. (No output on festival days.)
	%d	Cardinal day of the month. (No output on festival days.)
	%e	Ordinal day of the month. (No output on festival days.)
	%m	Name of the month, unadorned. (No output on festival days.)
	%M	Name of the month, like %m but with a descriptive tag.
	%n	Newline.
	%y	The year, starting from year 1: Gregorian year A.D. 1789.
	%t	Tab.
	%{
	%}	Used to enclose the part of the string which will be removed
		if the day in question is a festival day.
In addition:
	%q	A ' character. This ensures that, if you use +'string' instead
		of +"string" - necessary to get Bash to let you use characters
		like ! - you can still use an apostrophe inside the string and
		write +'Party like it%qs %y!'
	%% 	A % character. (This escape string won't work with %{ and %}.)

N.B. pdate outputs ASCII for maximum compatibility, and therefore lacks the
umlaut, circumflex, etc. (This would be slightly worse if it used the
original French nomenclature.)
"""

__author__	= "Robert F.J. Seddon ( http://rfjseddon.net/ )" # Who is not aligned with Comte's Religion of Humanity.
__version__	= "1.0"


from datetime	import date
from calendar	import isleap
from sys	import stdout as s
from sys	import argv
from string	import Template
import re

class fmt(Template):
	delimiter = "%"
	idpattern = "[ADdeMmnqty]"


def usageHelp(longVer):
	s.write( "Usage: pdate [+format] [day month year]\n" )
	s.write( description+"\n" if longVer else "\nTry 'pdate --help' for more information.\n" )


# --- Check for --help and -h, --info and -i ---

if "-h" in argv or "-i" in argv:
	usageHelp(False)
	exit()

if "--help" in argv or "--info" in argv:
	usageHelp(True)
	exit()


# --- Gregorian date - read from argv[] ---

argLength = len(argv)

# Sanity checks
if argLength not in [1,2,4,5]:
	usageHelp(False)
	exit(argLength)

if (argLength in [2,5]) and argv[1][0] != "+":
	usageHelp(False)
	exit(5)

# Read date
if argLength > 3:
	try:
		g_year		= int( argv[-1] )
		g_month		= int( argv[-2] )
		g_day		= int( argv[-3] )
	except ValueError:
		s.write( "Something needs to be in digits that isn't.\n\n" )
		usageHelp(False)
		exit(4)
	# Sanity check: is this a valid date?
	try:
		date(g_year, g_month, g_day)
	except ValueError:
		s.write( "Not a valid Gregorian date in the required format.\n\n" )
		usageHelp(False)
		exit(2)
	# Okay, it's a valid date
	dayCount	= ( date(g_year, g_month, g_day) - date(g_year, 1, 1) ).days

# Choose today's if no date is specified.
if argLength < 4:
	theDate		= date.today()
	g_year		= theDate.year
	dayCount	= ( theDate - date(g_year, 1, 1) ).days

if g_year < 1789:
	s.write( "This year predates the Positivist Era.\n" )
	exit(1)

p_year = g_year - 1788


# Leap years--thankfully, Comte kept the Gregorian sequence. (1789 as year
# one means 1792 is year four.)

isLeap = isleap(g_year)


# Is it a year-end festival?

isDeadFestival		= (dayCount == 364)
isHolyWomenFestival	= (dayCount == 365)

if dayCount < 364:
	p_month		= dayCount // 28
	p_monthDay	= dayCount % 28 + 1
else:
	p_month		= 13	# Junk data because fmt needs it when populated by functions that refer to these vars
	p_monthDay	= 29


if argLength in [2,5]:
	# We're dealing with a custom format string
	fmtStr = argv[1]
	
	# Deal with the initial +, and any enclosing ' or "
	fmtStr = fmtStr[2:-1] if fmtStr[1:] == fmtStr[:-1] == ( '"' or "'" ) else fmtStr[1:]
else: fmtStr = ("Today is " if argLength == 1 else "") + "%A%{, the %e of %m%} in the year %y"

# Deal with %{ and %}
if isDeadFestival or isHolyWomenFestival: br = re.compile("%{.*?%}")
else: br = re.compile("%{|%}")

for match in br.findall(fmtStr): fmtStr = fmtStr.replace(match, "")


# --- Comtean calendar data ---

p_monthName = [
	"Moses (the initial theocracy)",
	"Homer (ancient poetry)",
	"Aristotle (ancient philosophy)",
	"Archimedes (ancient science)",
	"Caesar (military civilization)",
	"Saint Paul (Catholicism)",
	"Charlemagne (feudal civilization)",
	"Dante (modern epic poetry)",
	"Gutenberg (modern industry)",			# Comte uses the alternative French form 'Gutemberg'.
	"Shakespeare (modern drama)",
	"Descartes (modern philosophy)",
	"Frederick (modern politics)",			# (Or 'policy', as per the I.P.C.?) Friedrich II ('The Great') of Prussia.
	"Bichat (modern science)",
	""]						# Dummy--suppresses output during festivals

p_dayName = [						#Regular and minor (leap year) saints are separated by |
	"Prometheus|Cadmus",				# A little odd to see mythological names here, but such is Comtean whimsy...
	"Hercules|Theseus",
	"Orpheus|Tiresias",
	"Ulysses",
	"Lycurgus",
	"Romulus",
	"Numa",						# Numa Pompilius.
	"Belus|Semiramis",				# The I.P.C. changes this to 'Semiramus'. Being paired with Semiramis, the intended Belus is probably the purported Assyrian king.
	"Sesostris",
	"Manu",						# The I.P.C. has 'Menu'.
	"Cyrus",
	"Zoroaster",
	"The Druids|Ossian",				# Or 'Oisin'.
	"Buddha",
	"Fo-Hi",					# It seems now-preferred anglicisations would be 'Fu Xi', 'Fu Hsi' or 'Paoxi'. I'm leaving this one as it is, being too inexpert to select.
	"Lao-Tsu",					# 'Lao-Tseu' = Lao-Tsu, a.k.a. Laozi, Lao Tzu, Lao Tse, Lao Tu, Laotze, Laosi, etc.
	"Mencius",					# Probably the most recognisable English form; Comte has 'Meng-Tseu'. A.k.a. Meng Zi, Meng Tzu.
	"Theocrats of Tibet",
	"Theocrats of Japan",
	"Manco Capac|Tamehameha",			# The I.P.C. has 'Mano-Capac'. 'Kamehameha' is reportedly the now-preferred rendering of the minor saint.
	"Confucius",
	"Abraham|Joseph",
	"Samuel",
	"Solomon|David",
	"Isaiah",
	"St. John the Baptist",
	"Haroun al-Rashid|Abd-ar-Rahman III",		# A.k.a. Abd al-Rahman, Abdur Rahman, Abd ar-Rahman, Abdul Rahman, Abdur Rehman, Abdul Rehman, Abidur Rahman, Abdirahman, Abderrahmane... The I.P.C. opts for 'Abderrahman'. Comte has 'Abderame'. Apparently a very common name, but 'III' looks like the emir of Cordoba.
	"Muhammad",
	"Hesiod",
	"Tyrtaeus|Sappho",
	"Anacreon",
	"Pindar",
	"Sophocles|Euripides",
	"Theocritus|Longus",
	"Aeschylus",
	"Scopas",
	"Zeuxis",
	"Ictinus",
	"Praxiteles",
	"Lysippos",					# Also romanised 'Lysippus'.
	"Apelles",
	"Phidias",					# Or 'Pheidias'.
	"Aesop|Pilpay",					# The Pilpai to whom the Panchatantra fables were attributed.
	"Plautus",
	"Terence|Menander",
	"Phaedrus",					# In the context, presumably the Roman fabulist.
	"Juvenal",
	"Lucian",
	"Aristophanes",
	"Ennius",
	"Lucretius",
	"Horace",
	"Tibullus",
	"Ovid",
	"Lucan",
	"Virgil",
	"Anaximander",
	"Anaximenes",
	"Heraclitus",
	"Anaxagoras",
	"Democritus|Leucippus",
	"Herodotus",
	"Thales",
	"Solon",
	"Xenophanes",
	"Empedocles",
	"Thucydides",
	"Archytas|Philolaus",
	"Apollonius of Tyana",				# Horribly confusible with Apollonius of Tyre.
	"Pythagoras",
	"Aristippus",
	"Antisthenes",
	"Zeno",						# Presumably Zeno of Elea, but could be Zeno of Citium.
	"Cicero|Pliny the Younger",
	"Epictetus|Arrian",
	"Tacitus",
	"Socrates",
	"Xenocrates",
	"Philo of Alexandria",
	"St. John the Evangelist",
	"St. Justin|Saint Irenaeus",
	"Clement of Alexandria",
	"Origen|Tertullian",
	"Plato",
	"Theophrastus",
	"Herophilos",					# Also romanised 'Herophilus'.
	"Erasistratus",
	"Celsus",					# Given the medical context, presumably Aulus Cornelius Celsus.
	"Galen",
	"Avicenna|Averroes",				# Ibn Sina and Ibn Rushd.  The I.P.C. favours the romanisation 'Averrhoes'.
	"Hippocrates",
	"Euclid",
	"Aristaeus",					# Presumably Aristaeus the Elder, mathematician, rather than the minor deity.
	"Theodosius of Bithynia",			# A.k.a. 'of Tripoli'. The I.P.C. has 'Theodisius'.
	"Hero|Ctesibius",
	"Pappus",
	"Diophantus",
	"Apollonius",					# Presumably Apollonius of Perga.
	"Eudoxus|Aratus",				# Eudoxus of Cnidus, mathematician, linked with Aratus, who versified him. (Confusing since we're about to reach a couple of explorers, and there was a navigator named Eudoxus of Cyzicus.)
	"Pytheas|Nearchus",
	"Aristarchus|Berosus",				# Aristarchus of Samos best complements Berosus/Berossus the astronomer.
	"Eratosthenes|Sosigenes",			# Given the astronomical theme, I'm guessing Sosigenes of Alexandria (calendar reform shout-out).
	"Ptolemy",
	"Albategnius|Nasireddin",			# Al-Battani and, I'm guessing from the adjacent astronomers, Nasir al-Din al-Tusi, after whom the Nasireddin lunar crater was named, rather than the protragonist of the Nasreddin stories or any of the other people with the name.
	"Hipparchus",					# Hipparchos of Nicaea.
	"Varro",
	"Columella",
	"Vitruvius",
	"Strabo",
	"Frontinus",
	"Plutarch",
	"Pliny the Elder",
	"Miltiades",
	"Leonidas",
	"Aristides",
	"Cimon",
	"Xenophon",
	"Phocion|Epaminondas",
	"Themistocles",
	"Pericles",
	"Philip",
	"Demosthenes",
	"Ptolemy Lagus",				# The 'Lagus' patronymic as used by Comte seems to occur in at least one translation of the Book of Daniel, though it seems 'Ptolemy Lagides' and 'Ptolemy I Soter' are rather more commonplace.
	"Philopoemen",
	"Polybius",
	"Alexander",
	"Junius Brutus",				# Maybe Lucius Junius Brutus, rather than the more obvious Marcus Junius Brutus...? He'd also fit the neighbouring Positivst saints' dates better.
	"Camillus|Cincinnatus",				# Marcus Furius Camillus.
	"Fabricius|Regulus",				# Gaius Fabricius Luscinus and presumably the second Marcus Atilius Regulus.
	"Hannibal",
	"Paulus Aemilius",				# Lucius Aemilius Paullus Macedonicus.
	"Marius|The Gracchi",
	"Scipio",
	"Augustus|Maecenas",
	"Vespasian|Titus",
	"Hadrian|Nerva",
	"Antonius|Marcus Aurelius",
	"Papinian|Ulpian",
	"Alexander Severus|Aetius",			# Flavius Aetius.
	"Trajan",
	"Saint Luke|Saint James",
	"Saint Cyprian",
	"Saint Athanasius",
	"Saint Jerome",
	"Saint Ambrose",
	"Saint Monica",
	"Saint Augustine",
	"Constantine",
	"Theodosius",					# Were the Theodosii of Alexandria Catholic enough for this month? Maybe it's Theodosius the Cenobiarch.
	"Saint Chrysostom|Saint Basil",
	"Saint Pulcheria|Marcian",			# Marcian (Byzantine Emperor) was Pulcheria's husband, the marriage remaining unconsummated owing to her vow of chastity. Given the pairing, this must be he rather than the more obviously thematic Saint Marcian of Tortona.
	"Saint Genevieve of Paris",
	"Saint Gregory the Great",
	"Hildebrand",
	"Saint Benedict|Saint Anthony",
	"Saint Boniface|Saint Austin",			# We saw Saint Augustine (French original: 'Saint Augustin') a few days ago, so maybe this one is Augustine of Canterbury. There are a couple of Archbishops of Canterbury coming up the day after next...
	"Saint Isidore of Seville|Saint Bruno",
	"Lanfranc|Saint Anselm",
	"Heloise|Beatrice",				# Beatrice of Silva actually is also a Catholic Saint, but wasn't canonised until 1976.
	"Architects of the Middle Ages|Saint Benezet",	# 'Les archit.'
	"Saint Bernard",
	"Saint Francis Xavier|Ignatius of Loyola",	# Ignatius isn't marked 'Saint' despite having been canonised in 1622. This is probably because of limited space; even the major names in this section have the 'St.'/'Ste.' form (here expanded), whereas Comte prefers the unabbreviated word when he has room.
	"Saint Charles Borromeo|Federico Borromeo",	# The I.P.C. uses the anglicisation 'Fredrick'; here I follow http://www.newadvent.org/cathen/02688b.htm
	"Saint Theresa|Saint Catherine of Siena",	# The I.P.C. favours the 'Catharine' spelling.
	"Saint Vincent de Paul|L'abbe de l'Epee",      	# Charles-Michel de l'Epee; the I.P.C. omits the initial article.
	"Bourdaloue|Claude Fleury",
	"William Penn|George Fox",
	"Bossuet",
	"Theodoric the Great",
	"Pelagius",					# The Visigoth of Asturias. The I.P.C. opts for the Spanish form 'Pelayo'.
	"Otto the Great|Henry the Fowler",		# The I.P.C. has 'Otho', following Comte's 'Othon'. | No connection to Henry Fowler the grammarian.
	"Saint Henry",					# Henry II, Holy Roman Emperor.
	"Villiers|La Valette",				# The latter is presumably Jean Parisot de la Valette, of the Knights Hospitaller, so this Villiers must be Philippe de Villiers de L'Isle-Adam.  The I.P.C. has 'Villers'.
	"Don John of Austria|John Sobieski",		# Comte actually writes 'Don Juan de Lepante', referring to the Battle of Lepanto; I follow the I.P.C.'s lead in giving him his more usual name/title. | Jan III Sobieski, King of Poland & Grand Duke of Lithuania.
	"Alfred",					# Presumably Alfred the Great.
	"Charles Martel",
	"El Cid|Tancred",				# Presumably the Tancred of the First Crusade, especially given El Cid's dates. | The I.P.C. follows Comte in localising the definite article.
	"Richard the Lionheart|Saladin",	       	# Comte just has 'Richard', but since he's paired with Saladin it must be the Lionheart. The I.P.C. identifies him as 'Richard I' accordingly.
	"Joan of Arc|Marina",				# Possibly St. Marina of Aguas Santas.  Or Marina of Omura/Nagasaki (later canonised). St. Margaret of Antioch is also sometimes called Marina. Little did Comte know that to a modern English reader, 'Marina' is a character in Stingray.
	"Albuquerque|Sir Walter Raleigh",
	"Bayard",					# Presumably Pierre Terrail, seigneur de Bayard.
	"Godfrey",					# Given the theme, probably the Crusader Godfrey of Bouillon.
	"Saint Leo the Great|Leo IV",
	"Gerbert|Peter Damian",				# Presumably the Gerbert of Aurillac who became Pope Sylvester II, but why does Comte just write 'Gerbert'?
	"Peter the Hermit",
	"Suger|Saint Eligius",
	"Alexander III|Thomas Becket",
	"Saint Francis of Assisi|Saint Dominic",
	"Innocent III",
	"Saint Clotilde",
	"Saint Bathild|Saint Matilda of Tuscany",	# The I.P.C. uses the 'Bathilda' and 'Mathilda' forms. There was a Matilda of Tuscany, a.k.a. Matilda of Canossa, but I can't find any indication that she was ever canonised...
	"Saint Stephen of Hungary|Mathias Corvinus",
	"Saint Elizabeth of Hungary",
	"Blanche of Castile",				# The I.P.C. sticks with Comte's 'Castille'.
	"Saint Ferdinand III|Alfonso X",
	"Saint Louis",
	"The Troubadours",
	"Boccaccio|Chaucer",
	"Rabelais|Swift",
	"Cervantes",
	"La Fontaine|Robert Burns",			# The I.P.C. alters this to 'La Fontain'.
	"Defoe|Goldsmith",				# Comte goes with the original 'Foe'; the I.P.C. compromises with the 'De Foe' form. | Presumably Oliver Goldsmith, of 'The Vicar of Wakefield' fame.
	"Ariosto",					# The I.P.C. has 'Aristo', but while 'Aristo[n]' is a name, but most of the bearers were ancient Greeks. Comte's original reads 'Arioste'.
	"Leonardo da Vinci|Titian",
	"Michaelangelo|Paul Veronese",
	"Holbein|Rembrandt",
	"Poussin|Lesueur",				# The I.P.C. alters this to 'Lesueuer'.
	"Velasquez|Murillo",
	"Teniers|Rubens",				# The Teniers were a whole family of painters.
	"Raphael",
	"Froissart|Joinville",
	"Camoens|Spenser",				# Comte spells it 'Spencer'.
	"The Spanish Romancers",
	"Chateaubriand",
	"Sir Walter Scott|James Fenimore Cooper",	# No 'Sir' in the original. | Abbreviated to 'Fen. Cooper'.
	"Manzoni",
	"Tasso",
	"Petrarch",					# The I.P.C. opts for the original Italian form, 'Petrarca'. Comte has the French form 'Petrarque'.
	"Thomas a Kempis|Louis of Granada & Bunyan",	# L&B are mysteriously obliged to share a minor saints' day, with the result that this sounds misleading.
	"Mme. de Lafayette|Mme. de Stael",
	"Fenelon|Saint Francis of Sales",
	"Klopstock|Gessner",				# Comte has 'Gesner'. The I.P.C. changes this to 'Gessner', the more usual form for the painter/poet Solomon/Salomon Gessner.
	"Byron|Elisa Mercoeur & Shelley",		# Another pairing of minor saints. The I.P.C. has 'Shelly' for some reason.
	"Milton",
	"Marco Polo|Chardin",				# Presumably Jean Chardin, being paired with Marco Polo.
	"Jacques Coeur|Gresham",			# Presumably Sir Thomas Gresham.
	"Vasco da Gama|Magellan",			# Comte just has 'Gama'; I follow the I.P.C. in giving the full name, though for some reason it uses the French'de'. 
	"Napier|Briggs",
	"Lacaille|Delambre",
	"Cook|Tasman",					# Abel Tasman.
	"Columbus",
	"Benvenuto Cellini",
	"Amontons|Wheatstone",				# Charles Wheatstone.
	"Harrison|Pierre Le Roy",			# Le Roy (Comte has 'Leroy') was a clockmaker, so the best match is John Harrison (1693 - 1776).
	"Dollond|Graham",				# John Dollond, optician known for his work in optics/lenses. So one might expect the minor saint to be another physicist, but actually the best candidate I found seems to be Thomas Graham, known mainly as a chemist.
	"Arkwright|Jacquard",				# Alongside Arkwright, it must be Joseph Marie Jacquard; I follow the I.P.C. in writing it as such, though Comte has it as 'Jacquart'.
	"Conte",					# Awkward ASCII limitations: the e should be acute. (Nicolas-Jacques Conte.)
	"Vaucanson",
	"Stevin|Torricelli",
	"Mariotte|Boyle",				# Edme Mariotte.
	"Papin|Worcester",				# Denis Papin | That'll be Edward Somerset, inventor and Marquess of Worcester.
	"Black",					# Presumably Joseph Black.
	"Jouffroy|Fulton",				# Robert Fulton and Claude-Francois-Dorothee, marquis de Jouffroy d'Abbans.
	"Dalton|Thilorier",
	"Watt",
	"Bernard de Palissy",				# Often seen without the 'de'.
	"Guglielmini|Riquet",
	"Duhamel (du Monceau)|Bourgelat",		# Brackets in original.
	"Saussure|Bouguer",
	"Coulomb|Borda",
	"Carnot|Vauban",				# I'm unsure whether this is Lazare Carnot or his son Nicholas.
	"Montgolfier",
	"Lope de Vega|Montalvan",			# Juan Perez de Montalvan/Montalban, among other accomplishments Vega's biographer.
	"Moreto|Guillem de Castro",			# Not the wine called Moreto; presumably Agustin Moreto y Cavana. | Guillen de Castro y Bellvis; apparently the form Comte uses is how he's known in Valencian.
	"Rojas|Guevara",				# Probably Fernando de Rojas, though there were other dramatists named Rojas: Augustin de Rojas Villandrando and Francisco de Rojas Zorrilla. | Presumably Antonio de Guevara. Certainly not Che.
	"Otway",
	"Lessing",					# Presumably Gotthold Ephraim Lessing, though his brother Karl Gotthelf also wrote plays.
	"Goethe",
	"Calderon",
	"Tirso",
	"Vondel",
	"Racine",
	"Voltaire",
	"Metastasio|Alfieri",
	"Schiller",
	"Corneille",					# Pierre Corneille; though his brother Thomas was also a playwright.
	"Alarcon",					# The I.P.C. changes this to 'Almarcon'.
	"Mme. de Motteville|Mme. Roland",		# Francoise Bertaut de Motteville. | Marie-Jeanne Phlippon Roland; though she seems to have been known more for her politics than for literature. Probably here as a letter-writer, like the next two.
	"Mme. de Sevigne|Lady Montagu",
	"Lesage|Sterne",				# Alain-Rene Lesage.
	"Mme. de Staal|Miss Edgeworth",			# One wonders what misunderstandings 'Mme. de Staal' vs. 'Mme. de Stael' (in the month of Dante) might have caused.
	"Fielding|Richardson",
	"Moliere",
	"Pergolesi|Palestrina",				# The I.P.C. keeps the French form 'Pergolese'.
	"Sacchini|Gretry",				# Andre Gretry; Lucile Gretry's career in composing comic operas ended with her early death.
	"Gluck|Lully",
	"Beethoven|Handel",
	"Rossini|Weber",				# Carl Maria Friedrich Ernst von Weber.
	"Bellini|Donizetti",				# The I.P.C. changes this to 'Donizeti'.
	"Mozart",
	"Albertus Magnus|John of Salisbury",
	"Roger Bacon|Ramon Llull",			# The I.P.C. favours the Anglicised 'Raymond Lully'--not to be confused with the Lully six days previously. (French originals: Lully vs. Raimond Lulle.) 'Raymond Lull' is another Anglicisation in use.
	"Saint Bonaventure|Joachim",			# The I.P.C. uses the 'Bonaventura' form. | Perhaps Joachim of Fiore, a theologian of the century before Bonaventure's.
	"Ramus|The Cardinal of Cusa",			# Petrus Ramus. | Nicholas of Cusa/Nicholas Cusanus.
	"Montaigne|Erasmus",
	"Campanella|More",				# Comte has 'Morus'; the I.P.C. extends it to the full 'Sir Thomas More'.
	"Saint Thomas Aquinas",
	"Hobbes|Spinoza",
	"Pascal|Giordano Bruno",
	"Locke|Malebranche",				# Comte actually has 'Mallebranche'.
	"Vauvenargues|Mme. de Lambert",
	"Diderot|Duclos",				# Presumably Charles Pinot Duclos: like the saloniere just above, not an obvious choice for a philosophers' month nowadays.
	"Cabanis|Charles-Georges Le Roy",		# Comte has 'Georges Leroy'; The I.P.C. goes for 'George Leroy'.
	"Francis Bacon",				# Comte has 'Le Chancelier Bacon'. [Lord] Chancellor Bacon (who apparently styled himself Lord Verulam once elevated to the peerage) is here given his familiar name (in full, to avoid confusion with Roger Bacon); the I.P.C. opts for 'Lord Bacon'.
	"Grotius|Cujas",
	"Fontenelle|Maupertuis",
	"Vico|Herder",
	"Freret|Winckelmann",				# Johann Joachim Winckelmann (not Winkelmann or Winkelman, both of which are existing surnames). The I.P.C. changes this to 'Wincklemann'.
	"Montesquieu|D'Aguesseau",			# Presumably Henri Francois d'Aguesseau rather than his grandson Henri-Cardin-Jean-Baptiste d'Aguesseau.
	"Buffon|Oken",
	"Leibniz",
	"Robertson|Gibbon",				# Presumably William Robertson (1721 - 1793); Eben William Robertson and James Burton Robertson both came a bit late on, and seem to have been less distinguished.
	"Adam Smith|Dunoyer",
	"Kant|Fichte",
	"Condercet|Ferguson",				# Adam Ferguson is probably a better match for Condorcet than James Ferguson.
	"Joseph de Maistre|Bonald",
	"Hegel|Sophie Germain",
	"Hume",
	"Maria de Molina",				# The I.P.C. sticks with Comte's 'Marie de Molina'.
	"Cosimo de Medici the Elder",
	"Philippe de Comines|Guicciardini",		# Or 'de Commynes'.
	"Isabella of Castille",
	"Charles V|Sixtus V",
	"Henry IV",					# ...of France, no doubt.
	"Louis XI",
	"L'Hopital",					# The statesman (Michel), not the mathematician (Guillaume).
	"Barneveldt",					# Johan van Oldenbarnevelt/Olden Barnevelt. Comte's extra 'd' appears to be an alternative or variant spelling.
	"Gustavus Adolphus",				# Gustav II Adolf of Sweden: Comte has 'Gustave Adolphe', and I follow the I.P.C. in using the common Latinisation.
	"De Witt",					# Probably Johan de Witt, but the de Witts were a whole patrician family.
	"Ruyter",
	"William III",					# Given the Dutch theme, this is probably William of Orange, i.e. William III of England. Especially with another William of Orange the following day.
	"William the Silent",
	"Ximenes",					# Presumably Cardinal Ximenes de Cisneros (Francisco Jimenez de Cisneros).
	"Sully|Oxenstiern",				# Maximilien de Bethune, duc de Sully. | Axel Gustafsson Oxenstierna af Sodermore. 'Oxenstiern' seems to be some sort of alternative form of 'Oxenstierna'.
	"Mazarin|Walpole",
	"Colbert|Louis XIV",				# Probably the Jean-Baptiste Colbert who was Louis's Minster of Finances (though a couple of his relatives were also politically involved).
	"D'Aranda|Pombal",				# Presumably Pedro Pablo Abarca de Bolea, the 10th Count of Aranda. Emanuel d'Aranda was famous for writing about his captivity, and beyond those two... | Presumably the first Marquess of Pombal.
	"Turgot|Campomanes",				# Probably Anne-Robert-Jacques Turgot.
	"Richelieu",
	"Sidney|Lambert",				# Most probably Algernon Sidney, in which case Lambert (not to be confused with Mme. de Lambert last month) is probably General John Lambert.
	"Franklin|Hampden",				# Perhaps most probably the first John Hampden.
	"Washington|Kosciusko",
	"Jefferson|Madison",
	"Bolivar|Toussaint Louverture",			# The I.P.C. uses the variant 'Toussaint L'Ouverture'.
	"Francia",
	"Cromwell",
	"Copernicus|Tycho Brahe",
	"Kepler|Halley",
	"Huygens|Varignon",
	"Jacob Bernouilli|Johann Bernouilli",		# Comte has Jacques and Jean; the I.P.C. has James and John (fishers of numbers?). Take your pick.
	"Bradley|Roemer",				# Presumably James Bradley, Astronomer Royal. | Probably Ole Christensen Roemer, another astronomer.
	"Volta|Sauveur",
	"Galileo",
	"Vieta|Harriot",
	"Wallis|Fermat",
	"Clairaut|Poinsot",
	"Euler|Monge",
	"D'Alembert|Daniel Bernouilli",
	"Lagrange|Joseph Fourier",
	"Newton",
	"Bergman|Scheele",				# Being paired with Scheele, this is probably Torbern Olaf Bergman. Comte's favoured spelling is 'Bergmann', which the I.P.C. retains. (Christian Bergmann would be an unusually up-to-date Positivist saint for the Calendar, having been born in 1814.)
	"Priestley|Davy",
	"Cavendish",
	"Guyton-Morveau|Geoffroy",			# The I.P.C. de-hyphenises Guyton-Morveau (a.k.a. Guyton de Morveau). | Probably Geoffroy the Elder.
	"Berthollet",
	"Berzelius|Ritter",				# Being paired with Berzelius, this is presumably Johann Wilhelm Ritter, not Carl Ritter.
	"Lavoisier",
	"Harvey|Charles Bell",
	"Boerhaave|Stahl & Barthez",			# Another pairing of minor Positivist saints. Barthez will be Paul Joseph Barthez, and Stahl is presumably Georg Ernst Stahl.
	"Linnaeus|Bernard de Jussieu",
	"Haller|Vicq-d'Azyr",				# Probably Albrecht von Haller Senior.
	"Lamarck|Blainville",
	"Broussais|Morgagni",
	"Gall"]						# Franz Josef Gall.



# --- Output functions ---

def getDay(isOrdinal):
	if p_monthDay > 28: return ""	# Dummy--suppresses output during festivals
	else: return str(p_monthDay) + ( ("th","st","nd","rd","th","th","th","th","th","th")[ 0 if p_monthDay in [11,12,13] else p_monthDay % 10 ] if isOrdinal else "" )

def getDayName():
	if isDeadFestival:		return "The Festival of All the Dead"
	elif isHolyWomenFestival:	return "The Festival of Holy Women"
	else:				return p_dayName[dayCount].split("|",1)[ -1 if isLeap else 0 ]

def getWeekDay():
	return "" if isDeadFestival or isHolyWomenFestival else ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")[ (p_monthDay % 7) - 1 ]

def getMonthName(isLong):
	return p_monthName[p_month].split( ( "**" if isLong else " (" ), 1)[0]

def getYear():
	return str(p_year)


# --- Output ---

s.write( fmt(fmtStr).safe_substitute(	q = "'",
					n = "\n",
					t = "\t",
					A = getDayName(),
					D = getWeekDay(),
					d = getDay(False),
					e = getDay(True),
					m = getMonthName(False),
					M = getMonthName(True),
					y = getYear()
					) )
s.write("\n")
