[Coco] Julian Date

Wayne Campbell asa.rand at gmail.com
Wed May 24 18:28:49 EDT 2017


I have got my code ready to post here, but there are a couple of caveats.
The day number generated is still not correct all of the time, and the
Gregorian parts are my best guess until I figure out how to properly
calculate it. I will post again when I have the issues still plaguing the
procedure corrected. The comments on the DIM and PARAM statement lines are
lined up, but when you load the source into Basic09 all the extra spaces
will be removed.

PROCEDURE JD

(* Parameter statements *)
PARAM todaysDate:STRING[10]  \(* Pass todays date in form of mm/dd/yyyy *)

(* Constant Dimension statements *)
DIM _cls:BYTE                \(* clear screen value *)
DIM _Jan1900:REAL            \(* Julian day number for 1/1/1900 *)

(* Variable Dimension statements *)
DIM currentDate:STRING[10]   \(* internal variable to hold contents of the
todaysDate parameter *)
DIM weekdayNumber:BYTE       \(* weekdayNumber = 1-7 *)
DIM weekdayName(7):STRING[9] \(* array of weekday names *)
DIM month,day,year:INTEGER   \(* month = 1-12, day = 1-31, year = any valid
positive INTEGER > 0 *)
DIM julianDay:REAL           \(* Julian day number *)
DIM A,B,C,E,F:REAL           \(* Used to calculate julianDay *)
DIM leapYear:BOOLEAN         \(* TRUE = leap year FALSE = not leap year *)

(* Initial assignment statements *)

(* ==================================================== *)
(* I calculated the JDN for Jan. 1, 1900 and created    *)
(* the "constant" _Jan1900 to hold this value, then I   *)
(* subtract it from the JDN for the current date to get *)
(* how many days have elapsed since 1/1/1900.           *)
(* ==================================================== *)
_Jan1900:=2415032.5
_cls:=12
currentDate:=todaysDate
weekdayNumber:=1
weekdayName(1):="Monday"
weekdayName(2):="Tuesday"
weekdayName(3):="Wednesday"
weekdayName(4):="Thursday"
weekdayName(5):="Friday"
weekdayName(6):="Saturday"
weekdayName(7):="Sunday"
month:=VAL(MID$(currentDate,1,2))
day:=VAL(MID$(currentDate,4,2))
year:=VAL(MID$(currentDate,7,4))
leapYear:=FALSE

(* Set the leap year flag *)
IF MOD(FLOAT(year),4)=0 THEN
IF MOD(FLOAT(year),100)<>0 OR MOD(FLOAT(year),100)=0 AND
MOD(FLOAT(year),400)=0 THEN
leapYear:=TRUE
ELSE
leapYear:=FALSE
ENDIF
ENDIF

(* ==================================================== *)
(* Everything here is based on what I found online at   *)
(* quasar.as.utexas.edu/BillInfo/JulianDatesG.html.     *)
(* It calculates the Julian Day Number (JDN) back to    *)
(* January 1, 4713 BC. I had to change 1524.5 to 1526.5 *)
(* to get the resulting Julian day to be correct on the *)
(* whole number part. After making this change I had to *)
(* reorder the weekday names to Monday through Sunday   *)
(* because the weekday name was off by one. BTW, the    *)
(* weekday name and JDN both correspond to the Julian   *)
(* calendar, not the Gregorian. I found that the .5 is  *)
(* supposed to be there. I found the calculator at      *)
(* quasar.as.utexas.edu/BillInfo/JulianDateCalc.html    *)
(* that uses the algorithm I have here.                 *)
(* ==================================================== *)

IF month=1 OR month=2 THEN
year:=year-1
month:=month+12
ENDIF

A:=INT(year/100)
B:=INT(A/4)
C:=2-A+B
E:=INT(365.25*(year+4716))
F:=INT(30.6001*(month+1))


julianDay:=C+day+E+F-1526.5
REM julianDay:=C+day+E+F-1524.5

(* ==================================================== *)

weekdayNumber:=MOD(julianDay,7)
IF weekdayNumber=0 THEN
weekdayNumber:=1
ENDIF

(* ==================================================== *)
(* The day number is twelve less when calculating a     *)
(* Gregorian date than when calculating a Julian date.  *)
(* I have accounted for this in the output.             *)
(* ==================================================== *)

PUT #1,_cls

PRINT "The JDN (Julian Day Number) (and possibly the weekday name) is
different when"
PRINT "calculating from a Gregorian calendar date than when calculating
from a Julian"
PRINT "calendar date."
PRINT "(Julian) means Julian calendar date, and"
PRINT "(Gregorian) means Gregorian calendar date."

PRINT
PRINT "The date you specified is: "; currentDate
PRINT "and is a "; weekdayName(weekdayNumber)
PRINT "and is ";

IF year>1900 OR year=1900 AND month>1 OR day>1 THEN
PRINT julianDay-_Jan1900; " days since January 1, 1900"
PRINT "and is ";
ENDIF

PRINT julianDay; " (Julian), "; julianDay-12; " (Gregorian), days since
January 1, 4713 BC"
PRINT

IF leapYear THEN
PRINT "It is a leap year"
ELSE
PRINT "It is not a leap year"
ENDIF

END


On Wed, May 24, 2017 at 2:28 PM, Wayne Campbell <asa.rand at gmail.com> wrote:

> The functions provided by Luis are not Basic09. B09 does not support
> function structures like this, and MOD in B09 is a ML function whose syntax
> is MOD(arg1,arg2), not arg1 MOD arg2.
>
>
> On May 24, 2017 2:22 PM, "Gregory Law" <glaw at live.com> wrote:
>
> This is Basic09 on OS-9/NitrOS-9.
>
> On 5/24/2017 5:18:54 PM, "Wayne Campbell" <asa.rand at gmail.com> wrote:
>
> >I find these two functions interesting. What language is it?
> >
> >It looks like BASIC, but I've never seen a function in basic written
> >this
> >way before.
> >
> >
> >On May 23, 2017 7:37 PM, "Luis Fernández" <luis46coco at hotmail.com>
> >wrote:
> >
> >>  OR
> >>
> >>
> >>  FUNCTION FechaJulDMA (tjul, dd, mm, aa)
> >>  T = tjul + 62
> >>  t2 = FIX(T / 1461) * 4 + 1700
> >>  t1 = T MOD 1461
> >>  IF t1 > 365 THEN
> >>  t1 = t1 - 1
> >>  oa = FIX(t1 / 365)
> >>  t1 = t1 MOD 365
> >>  END IF
> >>  aa = t2 + oa
> >>  dias = t1 + 1
> >>  dd = dias
> >>  swb = 1 - SGN(oa)
> >>  IF dd > 212 + swb THEN dd = dd + 30
> >>  IF dd > 59 + swb THEN dd = dd + 2 - swb
> >>  mm = FIX(dd / 61) * 2 + 1
> >>  dd = dd MOD 61
> >>  IF dd > 31 THEN mm = mm + 1: dd = dd - 31
> >>  IF mm > 7 THEN mm = mm - 1
> >>  FechaJulDMA = dias
> >>  END FUNCTION
> >>
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
>
>


More information about the Coco mailing list