in reply to The Perl Review's Date Format Challenge

"the date sequence 01:02:03 04/05/06 will only happen once in all of human history"

1 Calendar considerations

1.1 The Gregorian calendar

As the OP stresses, the Gregorian calendar is by no means the only one in existence. However, before looking at other calendars, let's examine all the ways Mr Pogue got it wrong just within his own frame of reference.

1.1.1 Basic silliness

As already pointed out, even assuming HH:MM:SS MM/DD/YY, this sequence will, of course, occur every century in human history.

1.1.2 Ordering conventions

1.1.2.1 Preliminary remarks: Let us accept the convention, for the sake of argument, that a slash ('/') separates years from months from days (in whatever order, see below) and that a colon (':') separates hours from minutes from seconds (again in whatever order). This precludes, for example, interpreting our sequence as 'Jan 2 2003 at 4h:5m:6s', or McDarren's creative suggestions above. Let us also assume a 24 hour clock.

1.1.2.2 MM/DD/YY: This is just one ordering convention*. What about DD/MM/YY (widely used in Europe)? Or YY/MM/DD? There are in fact six possible ways of ordering these elements, which means that '04/05/06' occurs 6 times every century.

* Used mainly, I believe, in North America.

1.1.2.3 HH:MM:SS: In theory, there are also six ways of interpreting this part of our sequence. However, I can find no evidence advocating anything other than descending (HH:MM:SS) or ascending (SS:MM:HH) order. This still means that we must double the number of times that our sequence may happen each century.

1.1.2.4 Conclusion: $NUMBER_OF_TIMES_PER_CENTURY = 12.

1.1.3 BCE vs CE (BC vs AD)

Sentences along the lines of "Emperor Foo was crowned on 5 April 406 BC(E)" are common in texts about ancient history. As none of the numbers in our sequence are signed, we may interpret this date (assuming MM/DD/YY format) as matching '04/05/06'*.

* If you are unconvinced by this reasoning, just replace the value of the constant $BEGINNING_OF_HUMAN_HISTORY by 1**. Note, however, that you will have to adjust for all the other (non-Gregorian, see below) calendars accordingly.
** Remember that there was no year 0 (although that doesn’t really matter in this particular case).

1.2 Other calendars

I am no calendar expert, but basic googling suggests that the number of known calendars (in common use now or in the past) is at least in the hundreds*. Arbitrarily, I set the value of $NUMBER_OF_CALENDARS at 300. Feel free to adjust this value as you please.

* Of course, not all of these calendars are based on a 'year' of 365-and-a-bit days, or a 'month' of 30-odd days (not to mention the division of a day into 24 'hours', 60 'minutes' and 60 'seconds'). Adjusting the code for this factor is left as an exercise for the reader.

1.3 'Scope' of a given calendar

It might be argued that the date 04/07/2006 (today, in Gregorian MM/DD/YYYY format) didn't exist in, for example, the French Revolutionary calendar, which was abolished, if my memory serves me well, in 1806, having lasted for less than 13 years*. However, it was perfectly possible to express future dates in this calendar (today, for example, would be 'Décade II, Octidi de Germinal de l'Année CCXIV de la Revolution', or, in MM/DD/YY format, 02/07/14)**, just as we can quite validly write 03/03/2525 (in Gregorian) today, despite the fact that the Earth might be invaded by Klingons tomorrow, and that they could impose their own calendar, rendering all our existing ones obsolete. Similarly, there is no problem in expressing a date in the arbitrarily distant past in either of the example calendars under discussion. From this we may conclude that any calendar is capable of expressing any date in history (past, present or future).

* Ignoring a brief attempt to re-introduce it during the Paris Commune some 65 years later.
** My calculations might be wrong, but you will agree that this doesn't affect the thrust of my argument :).

2 Human history

2.1 Beginning of human history

Once again for the sake of argument, let us define the beginning of humanity with the emergence of Homo sapiens (rather than, for example, H. neanderthalensis or H. erectus). I am no more a palaeoanthropologist than I am a calendar expert, but according to Wikipedia, "H. sapiens has lived from around 200 TYA* to the present". On this basis, we may set the value of $BEGINNING_OF_HUMAN_HISTORY at 197994 (200,000 – 2006).**

* Thousand Years Ago.
** You may wish to change this value as new fossil discoveries are made (or, of course, in function of your particular religious beliefs).

2.2 End of human history

I personally am sceptical as to mankind's chances of surviving the 21st Century, given the way we're treating our planet. However, this is no place for a diatribe about global warming and the like. Looking on the bright side, why not give us another couple of millennia before we become extinct? On this basis, I set the constant $END_OF_HUMAN_HISTORY at 4006 (YMMV).

So, given the above, here's my code (untested):

use strict; use warnings; my $NUMBER_OF_TIMES_PER_CENTURY = 12; my $NUMBER_OF_CALENDARS = 300; my $BEGINNING_OF_HUMAN_HISTORY = 197994; my $END_OF_HUMAN_HISTORY = 4006; my $human_history = $BEGINNING_OF_HUMAN_HISTORY + $END_OF_HUMAN_HISTOR +Y; my $centuries = $human_history / 100; my $total = $centuries * $NUMBER_OF_TIMES_PER_CENTURY * $NUMBER_OF_CAL +ENDARS; if ( $total > 1 ) { print "David Pogue was wrong\n"; }

Update: Corrected a couple of silly mistakes.

Replies are listed 'Best First'.