Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #56294
| From | Charles Montgomery <cgm@physics.utoledo.edu> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Dates in Forth |
| Date | 2017-03-25 16:36 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ob6k7q$747$1@dont-email.me> (permalink) |
The fundamental item for treating dates in Forth is Will Baden's
word to calculate the Julian Day for a date in the Gregorian calendar.
( The Julian Day is the number of days since 1 January 4713 BC.)
: JD ( dd mm yyyy -- julian-day )
>R ( dd mm)( R: yyyy)
3 - DUP 0< IF 12 + R> 1- >R THEN
306 * 5 + 10 / + ( day)
R@ 1461 4 */ + 1721116 +
DUP 2299169 > IF
3 + R@ 100 / - R@ 400 / +
THEN
R> DROP ( R: )
;
The day of the week is just the Julian Day mod 7.
For many purposes the Julian Fay is replaced by the
Modified Julian Day, which is just the Julian Day minus 2400000.5.
Its primary advantage is that the values aren't so huge and require
less storage space. It is zero for November 17. 1878.
The half day is present because the Julian Day goes from one noon
to the next, while the Modified Julian Day goes from midnight to midnight
like civil time. Time on the Greenwich meridian, of course.
It should be noted that the Gregorian calendar was adopted in different
ways at different times in different parts of the world. This causes no
problems for positive Modified Julian Days, though it limits the range of
applicability of Zeller's Congruence, for example.
: MJD ( dd mm yyyy - mod-julian-day )
>R 3 - DUP 0< IF 12 + R> 1- >R THEN
153 * 2 + 5 / + ( day R:year )
R@ 1461 4 */ + 678882 - R@ 100 / - R> 400 / +
;
A more interesting task, for which I have been unable to find a
published Forth solution, is the inverse problem: given the JD or MJD.
compute the day, month, and year in the Gregorian calendar.
I have a solution which works, but that I am not happy with. Does it
really have to be this complicated, or is there some number-theory tidbit
that I am failing to recognize?
: DJM4 ( Modified Julian Day -- year month day )
51604 - 146097 /mod swap
dup 146096 = IF drop 3 36524 ELSE 36524 /mod swap THEN
1461 /mod swap DUP 1460 = IF drop 3 366 ELSE 365 /mod swap 1+ THEN
>R rot 100 * + rot 400 * + swap 4 * + 2000 + R>
5 * 3 - 153 /mod swap 5 / 1+
>R 3 + DUP >R 12 > IF 1 + R> 12 - ELSE R> THEN R> ;
I hesitate to take up space on comp.lang.forth with a version with stack
comments and an explanation of what on earth is going on, because it may
Not be Of General Interest. I'd be happy to provide more details by email
if anyone is interested. Or to post more if there is interest.
regards to all cgm
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Dates in Forth Charles Montgomery <cgm@physics.utoledo.edu> - 2017-03-25 16:36 -0400
Re: Dates in Forth Alex <alex@rivadpm.com> - 2017-03-25 20:45 +0000
Re: Dates in Forth "Elizabeth D. Rather" <erather@forth.com> - 2017-03-25 11:34 -1000
Re: Dates in Forth krishna.myneni@ccreweb.org - 2017-03-25 18:31 -0700
Re: Dates in Forth Ron Aaron <rambamist@gmail.com> - 2017-03-26 06:57 +0300
Re: Dates in Forth krishna.myneni@ccreweb.org - 2017-03-26 05:15 -0700
Re: Dates in Forth Mark Wills <markwills1970@gmail.com> - 2017-03-26 02:29 -0700
Dates in Forth lehs <skydda.barnen@gmail.com> - 2017-03-29 10:39 -0700
csiph-web