Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Palindromic date

128 views
Skip to first unread message

Peter Duncanson [BrE]

unread,
Dec 2, 2021, 7:15:25 AM12/2/21
to

Today's date is palindromic for those of us who write the date
numerically as "year month day":

20211202

aka
2021 12 02



--
Peter Duncanson, UK
(in alt.usage.english)

Kerr-Mudd, John

unread,
Dec 2, 2021, 7:33:16 AM12/2/21
to
On Thu, 02 Dec 2021 12:15:15 +0000
"Peter Duncanson [BrE]" <ma...@peterduncanson.net> wrote:

>
> Today's date is palindromic for those of us who write the date
> numerically as "year month day":
>
> 20211202
>
> aka
> 2021 12 02
>
Long time til another one of that sort!


Spoiler:



















3001 10 03
(top of my head, other answers might be available, etc.)
--
Bah, and indeed Humbug.

Snidely

unread,
Dec 2, 2021, 7:36:48 AM12/2/21
to
Peter Duncanson [BrE] used thar keyboard to writen:
> Today's date is palindromic for those of us who write the date
> numerically as "year month day":
>
> 20211202
>
> aka
> 2021 12 02

I can mirror that now ....

-d

--
"What do you think of my cart, Miss Morland? A neat one, is not it?
Well hung: curricle-hung in fact. Come sit by me and we'll test the
springs."
(Speculative fiction by H.Lacedaemonian.)

Snidely

unread,
Dec 2, 2021, 9:03:49 PM12/2/21
to
Snidely suggested that ...
> Peter Duncanson [BrE] used thar keyboard to writen:
>> Today's date is palindromic for those of us who write the date
>> numerically as "year month day":
>>
>> 20211202
>>
>> aka
>> 2021 12 02
>
> I can mirror that now ....

I think I also heard it described as an ambidrome ... if you use
7-segment-style numerals, you can turn it upside down as well.

/dps

--
There's nothing inherently wrong with Big Data. What matters, as it
does for Arnold Lund in California or Richard Rothman in Baltimore, are
the questions -- old and new, good and bad -- this newest tool lets us
ask. (R. Lerhman, CSMonitor.com)

Richard Heathfield

unread,
Dec 3, 2021, 2:44:48 AM12/3/21
to
[Context: Second of December this year written as 20211202:]

On 03/12/2021 02:03, Snidely wrote:
> I think I also heard it described as an ambidrome ... if you use
> 7-segment-style numerals, you can turn it upside down as well.

Nearly 40 years ago Douglas Hofstadter labelled such formulations
"ambigrams".

"An ambigram is a visual pun of a special kind: a calligraphic design
having two or more (clear) interpretations as written words. One can
voluntarily jump back and forth between the rival readings usually by
shifting one’s physical point of view (moving the design in some way)
but sometimes by simply altering one’s perceptual bias towards a design
(clicking an internal mental switch, so to speak). Sometimes the
readings will say identical things, sometimes they will say different
things." - DH

The Internet seems to know all about ambigrams, but has never heard of
ambidromes, so you might want to use "ambigram" if you're interested in
finding similar examples of word play.

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Bob Martin

unread,
Dec 3, 2021, 3:06:20 AM12/3/21
to
On 2 Dec 2021 at 12:26:15, "Kerr-Mudd, John" <ad...@127.0.0.1> wrote:
> On Thu, 02 Dec 2021 12:15:15 +0000
> "Peter Duncanson [BrE]" <ma...@peterduncanson.net> wrote:
>
>>
>> Today's date is palindromic for those of us who write the date
>> numerically as "year month day":
>>
>> 20211202
>>
>> aka
>> 2021 12 02
>>
> Long time til another one of that sort!
>
>
> Spoiler:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 3001 10 03

2030 03 02


Kerr-Mudd, John

unread,
Dec 3, 2021, 6:11:50 AM12/3/21
to
On 3 Dec 2021 08:06:14 GMT
Ok, perhaps I'll stay up for that one.

occam

unread,
Dec 3, 2021, 6:43:46 AM12/3/21
to
Or you may consider to defecting to the American way of writing dates:
yyyy-dd-mm (a variant of mm-dd-yyyy)

2022 22 02

Snidely

unread,
Dec 3, 2021, 2:34:25 PM12/3/21
to
Thursday, Snidely murmurred ...
> Snidely suggested that ...
>> Peter Duncanson [BrE] used thar keyboard to writen:
>>> Today's date is palindromic for those of us who write the date
>>> numerically as "year month day":
>>>
>>> 20211202
>>>
>>> aka
>>> 2021 12 02
>>
>> I can mirror that now ....
>
> I think I also heard it described as an ambidrome ... if you use
> 7-segment-style numerals, you can turn it upside down as well.
>

Apparently, what I heard was "ambigram".

-d

--
The presence of this syntax results from the fact that SQLite is really
a Tcl extension that has escaped into the wild.
<http://www.sqlite.org/lang_expr.html>

Snidely

unread,
Dec 3, 2021, 2:35:49 PM12/3/21
to
occam explained :
American? I don't think I've ever encountered that one.

/dps

lar3ryca

unread,
Dec 4, 2021, 5:20:17 PM12/4/21
to
On Thursday, December 2, 2021 at 6:33:16 AM UTC-6, Kerr-Mudd, John wrote:
> On Thu, 02 Dec 2021 12:15:15 +0000
> "Peter Duncanson [BrE]" <ma...@peterduncanson.net> wrote:
>
> >
> > Today's date is palindromic for those of us who write the date
> > numerically as "year month day":
> >
> > 20211202
> >
> > aka
> > 2021 12 02
> >
> Long time til another one of that sort!
> 3001 10 03
> (top of my head, other answers might be available, etc.)

I've been thinking about this, and decided to write a program to
find palindromic dates in the yyyymmdd format.

#!/usr/bin/rexx
startyear = 2021
endyear = 2099
monthlength = ("1 0 1 0 1 0 1 1 0 1 0 1")

do y = startyear to endyear
do m=1 to 12
do d = 1 to 31
if m = 2 & d = 29 then do
d=31
iterate
end
else if word(monthlength,m) = "0" & d=31 then do
iterate
end
if length(d) = 1 then d = 0||d
if length(m) = 1 then m = 0||m
fulldate = y||m||d
if fulldate = reverse(full) then say full
end
end
end

For this century, the results are:
20211202
20300302
20400402
20500502
20600602
20700702
20800802
20900902

lar3ryca

unread,
Dec 4, 2021, 5:21:16 PM12/4/21
to
Bummer. All my nice indentation is gone.

Ken Blake

unread,
Dec 4, 2021, 5:49:06 PM12/4/21
to
It was fine on what I read here.


lar3ryca

unread,
Dec 4, 2021, 5:55:55 PM12/4/21
to
Ahh... I got it in my email, and it was indented properly. I think it's just
the web view that messed it up. Not surprising. HTML doesn't really
like spaces or tabs.

Athel Cornish-Bowden

unread,
Dec 5, 2021, 5:54:09 AM12/5/21
to
For me too.


--
Athel -- French and British, living mainly in England until 1987.

Ken Blake

unread,
Dec 5, 2021, 10:34:43 AM12/5/21
to
One of the many terrible things about using Google Groups instead of a
newsreader.

Peter T. Daniels

unread,
Dec 5, 2021, 11:49:16 AM12/5/21
to
On Sunday, December 5, 2021 at 10:34:43 AM UTC-5, Ken Blake wrote:
> On 12/4/2021 3:55 PM, lar3ryca wrote:

> > Ahh... I got it in my email, and it was indented properly. I think it's just
> > the web view that messed it up.
>
> One of the many terrible things about using Google Groups instead of a
> newsreader.

Really? What are the other "many" things?

Madhu

unread,
Dec 6, 2021, 5:46:37 AM12/6/21
to

* lar3ryca <c4568781-3b0c-4f94...@googlegroups.com> :
Wrote on Sat, 4 Dec 2021 14:20:14 -0800 (PST):
I haven't heard REXX mentioned in many years. The one-or-two IBMers I
worked briefly with preferred SNOBOL.

You can reduce the brute force problem space by half because the 4 year
YYYY fully determines if a 8-character date is a palindrome or not:

;; YYYY-MM-DD: ABCD-DC-BA
;; YYYY-DD-MM: ABCD-DC-BA

And you can check if a year is a palindrome or not and you are done
without generating all the strings for every day and month.

quickly coded in lisp

(defun palindrome-year-p (year &key (format-ymd-p t))
(assert (and (< 100 year) (< year 10000)))
(destructuring-bind (a b c d) (split-num year)
(let* ((dc (+ (* 10 d) c))
(ba (+ (* 10 b) a))
(month (if format-ymd-p dc ba))
(day (if format-ymd-p ba dc)))
(and (< 0 month) (< month 13)
(< 0 day) (< day (days-in-month month year))))))

(defun split-num (q &aux r ret)
"return a list of digits in Q"
(loop (cond ((zerop (multiple-value-setq (q r) (truncate q 10)))
(return (cons r ret)))

(defun days-in-month (month year)
(ecase month
((1 3 5 7 8 10 12) 31)
((4 6 9 11) 30)
(2 (if (gregorian-leap-year-p year) 29 28))))

(defun gregorian-leap-year-p (year)
(and (zerop (mod year 4))
(or (not (zerop (mod year 100)))
(zerop (mod year 400)))))

(loop for y from 2021 below 2100
if (palindrome-year-p y)
collect y)

;; => (2021 2030 2040 2050 2060 2070 2080 2090)


lar3ryca

unread,
Dec 6, 2021, 7:47:15 PM12/6/21
to
I never did use REXX on an IBM system. My introduction to it was
ARexx, on the Amiga. What made is especially useful was that some
programs had a built-in Arexx interface, allowing an ARexx program to
do pretty much whatever the programmer wanted to expose to ARexx.

> You can reduce the brute force problem space by half because the 4 year
> YYYY fully determines if a 8-character date is a palindrome or not:
>
> ;; YYYY-MM-DD: ABCD-DC-BA
> ;; YYYY-DD-MM: ABCD-DC-BA
>
> And you can check if a year is a palindrome or not and you are done
> without generating all the strings for every day and month.
>
> quickly coded in lisp

And quickly my eyes glazed over.
I knew there was a reason I never learned LISP. I cannot, for the
life of me, figure out how you are making the determination that the
year is a palindrome.
Nice. I can only assume that it's faster than mine, which takes about
0.033 seconds for 2021 to 2099.

But thanks for the LISP program. Makes me realize I forgot about leap
years.

Peter Moylan

unread,
Dec 6, 2021, 8:12:08 PM12/6/21
to
On 07/12/21 08:26, lar3ryca wrote:

> I never did use REXX on an IBM system. My introduction to it was
> ARexx, on the Amiga. What made is especially useful was that some
> programs had a built-in Arexx interface, allowing an ARexx program
> to do pretty much whatever the programmer wanted to expose to ARexx.

I've written one myself. On my OS/2 mail server you can specify filters
to be run (for spam detection, etc) at various stages of receiving the
mail. It turns out that most people write those filters in Rexx. The
filters that I supply are also in Rexx, not because I like the language
(I don't) but because that makes the source code available to anyone who
wants to customise them.

--
Peter Moylan Newcastle, NSW http://www.pmoylan.org

lar3ryca

unread,
Dec 6, 2021, 11:47:15 PM12/6/21
to
I must admit that even though I wrote my first program in about 1966, and
have been paid for programming since about 1995, I am self-taught, and
have only used a few languages to write more than few trivial programs.

I do like Rexx, quite a lot. Within a few days of starting to program in ARexx,
I wrote a 'uniq' program that was short simple, and had one advantage
over the Unix/Linux uniq. You did not have to sort the input file prior to
running it. It takes input from stdin.

#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end

Madhu

unread,
Dec 7, 2021, 9:06:19 AM12/7/21
to

* lar3ryca <d50283ce-ee8c-4fe6...@googlegroups.com> :
Wrote on Mon, 6 Dec 2021 13:26:38 -0800 (PST):

> On Monday, December 6, 2021 at 4:46:37 AM UTC-6, Madhu wrote:
> I never did use REXX on an IBM system. My introduction to it was
> ARexx, on the Amiga. What made is especially useful was that some
> programs had a built-in Arexx interface, allowing an ARexx program to
> do pretty much whatever the programmer wanted to expose to ARexx.
>> You can reduce the brute force problem space by half because the 4 year
>> YYYY fully determines if a 8-character date is a palindrome or not:
>>
>> ;; YYYY-MM-DD: ABCD-DC-BA
>> ;; YYYY-DD-MM: ABCD-DC-BA
>>
>> And you can check if a year is a palindrome or not and you are done
>> without generating all the strings for every day and month.

[snip]

> And quickly my eyes glazed over. I knew there was a reason I never
> learned LISP. I cannot, for the life of me, figure out how you are
> making the determination that the year is a palindrome.

Sorry, I did spring it on you to see if it was readable and the
algorithm was understandable and I guess that answers it. The posted
code has at least one off-by-one bug and is missing 2 lines in one
function lost in cut & paste

> Nice. I can only assume that it's fasfter than mine, which takes about
> 0.033 seconds for 2021 to 2099.

The range is too small for any comparison and i dont think you can
compare script executions with the `time' command meaningfully

I downloaded and installed regina-rexx and read the wikipedia page for
the syntax for 2-3 hours I came up with this: the algorithm should be
faster. maybe you can check or comment


#!/usr/bin/rexx
startyear = 2021
endyear = 2099

do y = startyear to endyear
if value(palindrome_year_p(y)) then
say y||reverse(y)
end
return 0

gregorian_leap_year_p:
parse arg year
p = year // 4
q = year // 400
return (p = 0) & ^ (q = 100 | q = 200 | q = 300)

days_in_month:
parse arg year month
select
when month = 1 | month = 3 | month = 5 | month = 8 | month = 10 | month = 12 then return 31
when month = 4 | month = 6 | month = 9 | month = 11 then return 30
when month = 2 then do
if gregorian_leap_year_p(year) then return 29
else return 28
end
otherwise
say "invalid month" month
exit 1
end

/* ABCD-DC-BA = YYYY-MM-DD*/

palindrome_year_p:
parse arg year
parse var year 1 ab 3 3 cd 5
mm = reverse(ab)
dd = reverse(cd)
return 0 < mm & mm < 13 & 0 < dd & dd < 1 + days_in_month(year mm)

Madhu

unread,
Dec 7, 2021, 9:26:17 AM12/7/21
to

sorry for hijacking aue for programming language nonsense, but there are
some bugs in what I posted, and I've got the programming bug

* Madhu <m3pmq8eci3.fsf @leonis4.robolove.meer.net> :
Wrote on Tue, 07 Dec 2021 19:35:40 +0530:
[snip]

> #!/usr/bin/rexx
> startyear = 2021
> endyear = 2099
...

This procedure is missing the 'month = 7' conditional in the first select clause

> days_in_month:
> parse arg year month
> select
> when month = 1 | month = 3 | month = 5 | month = 8 | month = 10 | month = 12 then return 31
> when month = 4 | month = 6 | month = 9 | month = 11 then return 30
> when month = 2 then do
> if gregorian_leap_year_p(year) then return 29
> else return 28
> end
> otherwise
> say "invalid month" month
> exit 1
> end
>
> /* ABCD-DC-BA = YYYY-MM-DD*/
>
> palindrome_year_p:
> parse arg year
> parse var year 1 ab 3 3 cd 5
> mm = reverse(ab)
> dd = reverse(cd)
> return 0 < mm & mm < 13 & 0 < dd & dd < 1 + days_in_month(year mm)

and here I got mm and dd reversed. mm should be reverse(cd) and dd
should be reverse(ab)

also I didn't realise rexx didn't have a short circuiting AND operator.
so the last return statement is wrong, it has to be something like

if 0 < mm & mm < 13 & 0 < dd then do
days = days_in_month(year mm)
if (dd < 1 + days)
then return 1
else return 0
end
else return 0

lar3ryca

unread,
Dec 7, 2021, 1:07:21 PM12/7/21
to
First, let me say that I didn't mean to nerdsnipe you. I should have
realized that you were susceptible when I saw your LISP program.

In case you aren't familiar with the term, see https://xkcd.com/356/

Of course, the entire Palindromic Dates thread nerdsniped me.

Anyway, thanks for the Rexx program. I now know how your algorithm
works, and it is VERY much faster than mine. Just for grins, I timed
both of them. Mine stutters when writing to the terminal, and yours
just slaps them all up faster than I can see it happening.

Mine:
real 0m2.884s
user 0m2.845s
sys 0m0.004s

Yours:
real 0m0.010s
user 0m0.010s
sys 0m0.000s

This time is for starting year = 1753, ending year = 9999.
This also showed me that the first palindromic year of the Gregorian
calendar is 2001/10/02, and that there are 288 palindromic years in
that range.

Your program looks good to me. There are a few things I need to
study. I have never used a parse like
parse var year 1 ab 3 3 cd 5
but it looks real handy.

I just checked, and it was also documented in ARexx. Can't believe I
missed it.

Richard Heathfield

unread,
Dec 7, 2021, 2:36:28 PM12/7/21
to
On 07/12/2021 18:07, lar3ryca wrote:

<snip>

> Anyway, thanks for the Rexx program. I now know how your algorithm
> works, and it is VERY much faster than mine. Just for grins, I timed
> both of them. Mine stutters when writing to the terminal, and yours
> just slaps them all up faster than I can see it happening.
>
> Mine:
> real 0m2.884s
> user 0m2.845s
> sys 0m0.004s
>
> Yours:
> real 0m0.010s
> user 0m0.010s
> sys 0m0.000s

That's impressive.

> This time is for starting year = 1753, ending year = 9999.

For the same date range, the best I can manage in C is:

real 0m0.063s
user 0m0.063s
sys 0m0.000s

> This also showed me that the first palindromic year of the Gregorian
> calendar is 2001/10/02, and that there are 288 palindromic years in
> that range.

Both confirmed.

> Your program looks good to me.

FWIW here's my C:


#include "jdate.h"
#include <stdio.h>

static int is_paldate(int y, int m, int d)
{
return y / 1000 == d % 10 &&
(y / 100) % 10 == d / 10 &&
(y / 10) % 10 == m % 10 &&
y % 10 == m / 10;
}

int main(void)
{
long startdate = to_julian(1753, 1, 1);
long enddate = to_julian(9999,12, 31);
long date = startdate;
int y, m, d;

while(date <= enddate)
{
from_julian(&y, &m, &d, date);
if(is_paldate(y, m, d))
{
printf("%d%02d%02d\n", y, m, d);
}
++date;
}
return 0;

Jerry Friedman

unread,
Dec 7, 2021, 3:09:44 PM12/7/21
to
On Tuesday, December 7, 2021 at 11:07:21 AM UTC-7, lar3...@gmail.com wrote:
> On Tuesday, December 7, 2021 at 8:06:19 AM UTC-6, Madhu wrote:
...

> > I downloaded and installed regina-rexx and read the wikipedia page for
> > the syntax for 2-3 hours I came up with this: the algorithm should be
> > faster. maybe you can check or comment

> First, let me say that I didn't mean to nerdsnipe you. I should have
> realized that you were susceptible when I saw your LISP program.
>
> In case you aren't familiar with the term, see https://xkcd.com/356/
...

There is no need to bring up what almost happened during a street
crossing in San José, Costa Rica, when a flock of parrots flew over.

--
Jerry Friedman resents being worth fewer points than a mathematician.

Peter Moylan

unread,
Dec 7, 2021, 5:50:58 PM12/7/21
to
I had that reaction in Brisbane when a possum tried to jump from one
power line to another and its front feet hit the destination line before
its back feet had left the source line.

That doesn't count as nerdsniping, though. Nerdsniping is when I was
almost sucked into giving my program for palindromic dates.

Peter Moylan

unread,
Dec 7, 2021, 6:03:18 PM12/7/21
to
On 08/12/21 06:36, Richard Heathfield wrote:

> printf("%d%02d%02d\n", y, m, d);

That reminds me of a situation where I failed to see the obvious.
Because I write a lot of internet server applications, I have often
needed to produce a timestamp in a format specified by some standard.
Initially I wrote a module with a couple of routines to produce the
timestamp. But, standards being standards, the number of different
"standard" formats I had to handle just grew and grew.

It literally took me years before I realised that I needed just one
procedure that would let me make calls like

FormatDateTime (dt, "the time is ddd/mm HH:MM", timestamp)

with a small range of possibilities for the format string.

In some ways FORTRAN was ahead of its time with the FORMAT statement. C
copied some of this, but to make it work it had to introduce a major
weakness in the language: the concept of a function with a variable
number of parameters.

Mark Brader

unread,
Dec 7, 2021, 6:10:17 PM12/7/21
to
Peter Moylan:
> In some ways FORTRAN was ahead of its time with the FORMAT statement. C
> copied some of this, but to make it work it had to introduce a major
> weakness in the language:

Strength, that is.

> the concept of a function with a variable number of parameters.

Even FORTRAN had that, with its AMAX1 and family.
--
Mark Brader, Toronto | "I like work; it fascinates me. I can sit and
m...@vex.net | look at it for hours." -- Jerome K. Jerome

Quinn C

unread,
Dec 7, 2021, 6:16:24 PM12/7/21
to
* Jerry Friedman:
Can this be raised to a higher power by a flock of snipes?

--
The universe hates you - deal with it.
-- Seamus Harper

Sam Plusnet

unread,
Dec 7, 2021, 7:21:16 PM12/7/21
to
Factor in a few sn!pes & try it.

--
Sam Plusnet

Kerr-Mudd, John

unread,
Dec 8, 2021, 4:48:42 AM12/8/21
to
Well, I'm half-caught; I've written one, but I won't publish it (cos I didn't handle leap years^w the one leap year case).

Richard Heathfield

unread,
Dec 8, 2021, 5:46:19 AM12/8/21
to
On 08/12/2021 09:48, Kerr-Mudd, John wrote:
> Well, I'm half-caught; I've written one, but I won't publish it (cos I didn't handle leap years^w the one leap year case).

Then you need a better date library. I didn't bother to consider leap
years specially because I could just iterate through the Julian dates
and let the library worry about what the actual date was.

Lewis

unread,
Dec 8, 2021, 7:13:25 AM12/8/21
to
In message <soq2dn$fgh$1...@dont-email.me> Richard Heathfield <r...@cpax.org.uk> wrote:
> On 08/12/2021 09:48, Kerr-Mudd, John wrote:
>> Well, I'm half-caught; I've written one, but I won't publish it (cos I didn't handle leap years^w the one leap year case).

> Then you need a better date library. I didn't bother to consider leap
> years specially because I could just iterate through the Julian dates
> and let the library worry about what the actual date was.

I don't think Julian date means what you think it means.

<https://en.wikipedia.org/wiki/Julian_date>


--
A man, in a word, who should never have been taught to write and whom
if unhappily gifted with that ability, should have been
restrained by a Act of Parliament from writing Reminiscences.
- PG Wodehouse

CDB

unread,
Dec 8, 2021, 9:06:07 AM12/8/21
to
On 12/7/2021 3:09 PM, Jerry Friedman wrote:
> lar3...@gmail.com wrote:
>> Madhu wrote:
> ...

>>> I downloaded and installed regina-rexx and read the wikipedia
>>> page for the syntax for 2-3 hours I came up with this: the
>>> algorithm should be faster. maybe you can check or comment

>> First, let me say that I didn't mean to nerdsnipe you. I should
>> have realized that you were susceptible when I saw your LISP
>> program.

>> In case you aren't familiar with the term, see
>> https://xkcd.com/356/
> ...

> There is no need to bring up what almost happened during a street
> crossing in San José, Costa Rica, when a flock of parrots flew over.

You mean birdsniping? They are all derived from the sport of shouting
"squirrel" when a dog is otherwise busy about their concerns.


Kerr-Mudd, John

unread,
Dec 8, 2021, 11:54:32 AM12/8/21
to
On Wed, 8 Dec 2021 12:13:21 -0000 (UTC)
Lewis <g.k...@kreme.dont-email.me> wrote:

> In message <soq2dn$fgh$1...@dont-email.me> Richard Heathfield <r...@cpax.org.uk> wrote:
> > On 08/12/2021 09:48, Kerr-Mudd, John wrote:
> >> Well, I'm half-caught; I've written one, but I won't publish it (cos I didn't handle leap years^w the one leap year case).
>
> > Then you need a better date library. I didn't bother to consider leap
> > years specially because I could just iterate through the Julian dates
> > and let the library worry about what the actual date was.
>
> I don't think Julian date means what you think it means.
>
> <https://en.wikipedia.org/wiki/Julian_date>
>
Redirects to Julian Day

Iterating through all days seems quite wasteful; "ccyy mmdd" will only be palindomic at most once a year.

Who needs a Library?
>
> --
> A man, in a word, who should never have been taught to write and whom
> if unhappily gifted with that ability, should have been
> restrained by a Act of Parliament from writing Reminiscences.
> - PG Wodehouse


Richard Heathfield

unread,
Dec 8, 2021, 12:13:35 PM12/8/21
to
On 08/12/2021 16:54, Kerr-Mudd, John wrote:
> On Wed, 8 Dec 2021 12:13:21 -0000 (UTC)
> Lewis <g.k...@kreme.dont-email.me> wrote:
>
>> In message <soq2dn$fgh$1...@dont-email.me> Richard Heathfield <r...@cpax.org.uk> wrote:
>>> On 08/12/2021 09:48, Kerr-Mudd, John wrote:
>>>> Well, I'm half-caught; I've written one, but I won't publish it (cos I didn't handle leap years^w the one leap year case).
>>
>>> Then you need a better date library. I didn't bother to consider leap
>>> years specially because I could just iterate through the Julian dates
>>> and let the library worry about what the actual date was.
>>
>> I don't think Julian date means what you think it means.
>>
>> <https://en.wikipedia.org/wiki/Julian_date>
>>
> Redirects to Julian Day

And, surprise surprise, it turns out that Julian date means pretty much
what I thought I meant.

> Iterating through all days seems quite wasteful; "ccyy mmdd" will only be palindomic at most once a year.

What is wasteful is spending a long time on writing an optimised curio
when one may in a short time write an unoptimised curio that will run in
next to nothing flat anyway.

>
> Who needs a Library?

A man who feels no particular need to write the same code over and over
again.

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
"I suppose you burned the library -- barbarians always do." - James Blish.

Snidely

unread,
Dec 8, 2021, 10:54:45 PM12/8/21
to
Tuesday, Sam Plusnet quipped:
That's a divisive post. Let's subtract it from the message list.

/dps

--
We’ve learned way more than we wanted to know about the early history
of American professional basketball, like that you could have once
watched a game between teams named the Indianapolis Kautskys and the
Akron Firestone Non-Skids. -- fivethirtyeight.com

Lewis

unread,
Dec 9, 2021, 3:07:02 AM12/9/21
to
In message <20211208165431.e7dd...@127.0.0.1> Kerr-Mudd, John <ad...@127.0.0.1> wrote:
> On Wed, 8 Dec 2021 12:13:21 -0000 (UTC)
> Lewis <g.k...@kreme.dont-email.me> wrote:

>> In message <soq2dn$fgh$1...@dont-email.me> Richard Heathfield <r...@cpax.org.uk> wrote:
>> > On 08/12/2021 09:48, Kerr-Mudd, John wrote:
>> >> Well, I'm half-caught; I've written one, but I won't publish it (cos I didn't handle leap years^w the one leap year case).
>>
>> > Then you need a better date library. I didn't bother to consider leap
>> > years specially because I could just iterate through the Julian dates
>> > and let the library worry about what the actual date was.
>>
>> I don't think Julian date means what you think it means.
>>
>> <https://en.wikipedia.org/wiki/Julian_date>
>>
> Redirects to Julian Day

Yes, they are equivalent terms.

> Iterating through all days seems quite wasteful; "ccyy mmdd" will only be palindomic at most once a year.

Julian Dates are very useful in certain contexts.

--
what is magic actually for?
For fixing things, dummy.

Anders D. Nygaard

unread,
Dec 9, 2021, 1:34:58 PM12/9/21
to
Den 08-12-2021 kl. 00:03 skrev Peter Moylan:
> On 08/12/21 06:36, Richard Heathfield wrote:
>
>> printf("%d%02d%02d\n", y, m, d);
>
> That reminds me of a situation where I failed to see the obvious.
> Because I write a lot of internet server applications, I have often
> needed to produce a timestamp in a format specified by some standard.
> Initially I wrote a module with a couple of routines to produce the
> timestamp. But, standards being standards, the number of different
> "standard" formats I had to handle just grew and grew.
>
> It literally took me years before I realised that I needed just one
> procedure that would let me make calls like
>
>  FormatDateTime (dt, "the time is ddd/mm HH:MM", timestamp)
>
> with a small range of possibilities for the format string.

How come the range of possibilities for the format string is small,
and by implication smaller than the growing number of standard formats?

Or am I misreading you?

/Anders, Denmark

Peter Moylan

unread,
Dec 9, 2021, 6:01:56 PM12/9/21
to
I'd better rephrase that. The format string can be anything at all, so
there are unlimited possibilities. My "small range of possibilities"
referred to the symbols with special meanings, like HH and yyyy. There
don't need to be many of those to cover the many standard formats.

My complete list of special symbols is

dd day, numeric
ddd day, three-letter name
mm month, numeric
mmm month, three-letter name
yy year, including Y2K bug
yyyy year, all four digits
HH hours
MM minutes
SS seconds
zz first time: sign and hours of time zone
zz second time: minutes part of time zone

I could add a few more to that list, but so far I haven't needed to.

Madhu

unread,
Dec 9, 2021, 8:51:28 PM12/9/21
to
* Peter Moylan <sou1t0$d5c$1...@dont-email.me> :
Wrote on Fri, 10 Dec 2021 10:01:50 +1100:

> I'd better rephrase that. The format string can be anything at all, so
> there are unlimited possibilities. My "small range of possibilities"
> referred to the symbols with special meanings, like HH and yyyy. There
> don't need to be many of those to cover the many standard formats.
>
> My complete list of special symbols is
>
> dd day, numeric
> ddd day, three-letter name
> mm month, numeric
> mmm month, three-letter name
> yy year, including Y2K bug
> yyyy year, all four digits
> HH hours
> MM minutes
> SS seconds
> zz first time: sign and hours of time zone
> zz second time: minutes part of time zone
>
> I could add a few more to that list, but so far I haven't needed to.

Unless I misunderstood, C has strftime and strptime which does pretty
much the same thing in both directions.

the `date' program tries to accomodate a bunch of formats using this
mechanism but it still commonly fails in my experience

Anders D. Nygaard

unread,
Dec 10, 2021, 5:36:20 PM12/10/21
to
Ah - that makes sense, thank you.

/Anders, Denmark

Richard Heathfield

unread,
Dec 12, 2021, 9:20:51 AM12/12/21
to
On 07/12/2021 19:36, Richard Heathfield wrote:
> On 07/12/2021 18:07, lar3ryca wrote:
>
> <snip>
>
>> Anyway, thanks for the Rexx program. I now know how your algorithm
>> works, and it is VERY much faster than mine. Just for grins, I timed
>> both of them. Mine stutters when writing to the terminal, and yours
>> just slaps them all up faster than I can see it happening.
>>
>> Mine:
>> real    0m2.884s
>> user 0m2.845s
>> sys   0m0.004s
>>
>> Yours:
>> real    0m0.010s
>> user 0m0.010s
>> sys     0m0.000s
>
> That's impressive.
>
>> This time is for starting year = 1753, ending year = 9999.
>
> For the same date range, the best I can manage in C is:
>
> real    0m0.063s
> user    0m0.063s
> sys    0m0.000s


Try to ignore the feeling as I might, this has been bothering me. So in
five minutes just now I cobbled together a slightly more pedal-to-metal
version:

real 0m0.003s
user 0m0.003s
sys 0m0.000s

Now *that* I can live with.
0 new messages