[Coco] Julian Date

Wayne Campbell asa.rand at gmail.com
Fri May 26 12:23:43 EDT 2017


I found one error in my coding that needs to be corrected. When dealing
with dates prior to 1900, the value of the week day number can be greater
than 7. This results in a 55 error (subscript out of range) and causes the
program to crash. (No error trapping)

The correction is to replace the following two statements in the code:

IF weekdayNumberG=0 THEN
IF weekdayNumberJ=0 THEN

With:

IF weekdayNumberG<1 OR weekdayNumberG>7 THEN
IF weekdayNumberJ<0 OR weekdayNumberJ>7 THEN

This will correct the problem and return the correct weekday names. I
verified this using time and date.com for reference.


On May 25, 2017 1:27 PM, "Wayne Campbell" <asa.rand at gmail.com> wrote:

> Here is the corrected JD procedure. There are differences from the one
> i posted yesterday, so delete that one and replace it with this one.
>
> Wayne
>
> 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 weekdayNumberG,weekdayNumberJ: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 julianDayJ,julianDayG:REAL \(* ....... JDN for Julian date, JDN for
> Gregorian date
> DIM A,B,C,E,F:REAL \(* ................... used to calculate julianDay
> DIM leapYear,Gregorian:BOOLEAN \(* ....... leapYear TRUE = leap year,
> FALSE = not leap year,
> (* ....................................... Gregorian TRUE = Gregorian
> date, FALSE = Julian date
>
> (* Initial Assignment statements *)
> (* ============================= *)
>
> (* ====================================================== *)
> (* I calculated the JDN for Jan. 1, 1900 on the Gregorian *)
> (* calendar 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   *)
> (* January 1, 1900. (Julian calendar = 2415032.5)         *)
> (* ====================================================== *)
>
> _Jan1900:=2415020.5
> _cls:=12
> currentDate:=todaysDate
> weekdayNumberG:=1
> weekdayNumberJ:=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
>
> (* Beginning of Program *)
> (* ==================== *)
>
> (* 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 in this section and in subroutine 10 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 reorder the weekday       *)
> (* names to Monday through Sunday and add 1 to the        *)
> (* result of the MOD because the weekday name was off     *)
> (* by one. I found the calculator at:                     *)
> (* quasar.as.utexas.edu/BillInfo/JulianDateCalc.html      *)
> (* that uses the algorithm I have here. It was useful     *)
> (* in helping to determine how to correctly calculate     *)
> (* the JDN for both Julian and Gregorian calendar dates.  *)
> (* ====================================================== *)
>
> IF month=1 OR month=2 THEN
> year:=year-1
> month:=month+12
> ENDIF
>
> Gregorian:=TRUE
> GOSUB 10 \(* ............................. get JDN for Gregorian calendar
> Gregorian:=FALSE
> GOSUB 10 \(* ............................. get JDN for Julian calendar
>
> (* ====================================================== *)
>
> (* Determine weekday name *)
> (* ====================== *)
>
> weekdayNumberG:=MOD(julianDayG,7)+1
> IF weekdayNumberG=0 THEN
> weekdayNumberG:=1
> ENDIF
> weekdayNumberJ:=MOD(julianDayJ,7)+1
> IF weekdayNumberJ=0 THEN
> weekdayNumberj:=1
> ENDIF
>
> (* Print results *)
> (* ============= *)
>
> 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(weekdayNumberG); " (Gregorian, ";
> weekdayName(weekdayNumberJ); " Julian)"
> PRINT "and is ";
>
> IF year>1900 OR year=1900 AND (month>1 OR day>1) THEN
> PRINT julianDayG-_Jan1900; " days since January 1, 1900"
> PRINT "and is ";
> ENDIF
>
> PRINT julianDayJ; " (Julian), "; julianDayG; " (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
>
> (* Julian Day Number calculator *)
> (* ============================ *)
>
> 10 IF Gregorian THEN
> A:=INT(FLOAT(year)/100)
> B:=INT(FLOAT(A)/4)
> C:=2-A+B
> ELSE
> C:=0
> ENDIF
> E:=INT(365.25*(year+4716))
> F:=INT(30.6001*(month+1))
>
> IF Gregorian THEN
> julianDayG:=C+day+E+F-1524.5
> ELSE
> julianDayJ:=C+day+E+F-1524.5
> ENDIF
> RETURN
>
>
> On Wed, May 24, 2017 at 7:39 PM, Walter Zambotti <zambotti at iinet.net.au>
> wrote:
>
>>
>>
>> >Oh, and if someone feels up to it they can try removing the float()s
>> from the MOD and INT >statements and see if it runs correctly in the 6809
>> version. I'm fairly certain it will, but it would be >nice to know. I don't
>> have a 6809 version of NOS9 or Basic09 to test with.
>>
>> You don't need a 6809 or the 6809 version of Nitros09.
>>
>> You just need the 6809 version of Basic09
>>
>> How I tested:
>>
>> VCC 6309 + NOS09 Lvl2 6309  + Basic09_6309 (MOD didn't work)
>> and
>> VCC 6309 + NOS09 Lvl2 6309  + Basic09_6809 (MOD did work)
>>
>> In other words the 6809 version of Basic09 will run in the 6309
>> environment.
>>
>> You can tell which version of basic09 you have by reading the opening
>> banner when you start it.  It explicitly states the version.
>>
>> Walter
>>
>> -----Original Message-----
>> From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of Wayne
>> Campbell
>> Sent: Thursday, 25 May 2017 10:31 AM
>> To: CoCoList <coco at maltedmedia.com>
>> Subject: Re: [Coco] Julian Date
>>
>> Oh, and if someone feels up to it they can try removing the float()s from
>> the MOD and INT statements and see if it runs correctly in the 6809
>> version. I'm fairly certain it will, but it would be nice to know. I don't
>> have a 6809 version of NOS9 or Basic09 to test with.
>>
>>
>> On May 24, 2017 7:26 PM, "Wayne Campbell" <asa.rand at gmail.com> wrote:
>>
>> > The problem has been solved, and there are at least two broken
>> > functions in B09. The integer versions of INT and MOD do not return
>> > the correct results. I forced the use of the real (float) versions and
>> > the results are now correct.
>> >
>> > I also had to make a correction to the weekday name code. With the
>> > weekday names ordered from Monday through Sunday, the weekday name
>> > chosen was one off (Monday instead of Tuesday for example). Adding 1
>> > to the calculation corrected that. I could have ordered the array from
>> > Tuesday through Monday, but I decided adding 1 was easier.
>> >
>> > I will upload the corrected code tomorrow if I can, otherwise as soon
>> > as possible.
>> >
>> >
>> > On May 24, 2017 3:33 PM, "Christopher R. Hawks" <chawks at dls.net> wrote:
>> >
>> >> On Wed, 24 May 2017 14:28:04 -0700
>> >> 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.
>> >> >
>> >> >
>> >>
>> >>   And while you _can_ set the values of parameters passed in (dd =
>> >> dias, mm = FIX(dd / 61) * 2 + 1, etc) NOT recommended I'm pretty sure
>> >> you can't set the function name to something (FechaJulDMA = dias)
>> >>
>> >> > 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
>> >> >
>> >>
>> >>
>> >>
>> >>
>> >> Christopher R. Hawks
>> >> HAWKSoft
>> >> --
>> >> I dipped into the future far as human eye could see, Saw the vision
>> >> of the world and all the wonder that would be.
>> >>                 --Alfred Lord Tennyson
>> >> ----------------------------------------
>> >>        \   ^__^
>> >>         \  (oo)\_______
>> >>            (__)\       )\/\
>> >>                ||----w |
>> >>                ||     ||
>> >>
>> >> --
>> >> Coco mailing list
>> >> Coco at maltedmedia.com
>> >> https://pairlist5.pair.net/mailman/listinfo/coco
>> >>
>> >
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> https://pairlist5.pair.net/mailman/listinfo/coco
>>
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> https://pairlist5.pair.net/mailman/listinfo/coco
>>
>
>
>


More information about the Coco mailing list