On Friday, October 20, 2023 at 3:09:53 PM UTC+2, none albert wrote:
Infuriated by the 3 page instructions of the Linux date
I decided to write my own.
The worst problem is that there is no canonical date format.
Look at 'man co' option -d . There is a plethora of options
to format the date. It is a day's work to find out whether
they agree.
Well, there is ISO 8601and RFC 1123. 4tH (will) support both. For my job I have to do with converting
data (including dates) all the time. So you will find there is a lot of stuff in 4tH targeted to that one.
At one time I had to integrate a dozen datasets with slightly different layouts. And the date was a
complete mess. You can think of a format? Well, somewhere in those twelve sets it was used somewhere.
So at one time I got REALLY mad and wrote a library that fixed that one permanently. I recently used it
again when testing an ISO 8601 lib I'd written for work. This is the output:
$ pp4th -x testdate.4th
25-MAR-1960 1960-03-25T07:00:00.00
December 26th 1981 1981-12-26T07:00:00.00
20031105 2003-11-05T07:00:00.00
02/12/39 2039-12-02T07:00:00.00
22. Dezember 1971 1971-12-22T07:00:00.00
July 4th, 1776 1776-07-04T07:00:00.00
12 augustus 1925 1925-08-12T07:00:00.00
14 Julliet 1792 1792-07-14T07:00:00.00
22161 1960-09-02T07:00:00.00
It's quite transparent to the user I guess, here is the source of the above program:
include lib/getdate.4th
include lib/anscore.4th
include lib/compare.4th
include lib/scanskip.4th
include iso8601.4th
: splitdate [char] - split number ;
: tab 9 emit ;
: makeisodate ( a1 n1 -- a2 n2)
2dup getdate 2swap 2over compare
if splitdate >r chop splitdate >r chop number r> r> else 2drop 0 0 0 then
0 0 7 .datetime0
;
s" 25-MAR-1960" 2dup type tab tab makeisodate type cr
s" December 26th 1981" 2dup type tab makeisodate type cr
s" 20031105" 2dup type tab tab makeisodate type cr
s" 02/12/39" 2dup type tab tab makeisodate type cr
s" 22. Dezember 1971" 2dup type tab makeisodate type cr
s" July 4th, 1776" 2dup type tab tab makeisodate type cr
s" 12 augustus 1925" 2dup type tab makeisodate type cr
s" 14 Julliet 1792" 2dup type tab tab makeisodate type cr
s" 22161" 2dup type tab tab tab makeisodate type cr
If you want to try to port the shebang to ANS, you can find all you need
right here:
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/lib/
Hans Bezemer
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)