[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

555.0. "FISCAL CALENDAR, Any suggestions??" by SWIFT::HOLDER () Mon Aug 04 1986 05:39

Does anyone have a good algorithm to work out fiscal calendar dates both
past and future?

I have looked at this problem and arrived at the following solutions
which works reasonable well except one thing, which will become apparent.

Observations are as follows:-

	The fiscal year starts in July. 
	The first day of July will start some time in the first week 
	 of the fiscal month.
	Of the 12 months, month divisible by 3 are 5 week months.

This gives us 8 * 4 week months, and 4 * 5 week months or 52 weeks of
7 days or 364 days, less than the year by 1.25 days.

If the 1st of July is converted to Julian date format, we can find the day
of the week,

	D_O_W		=	( JUL_DAY_NUM + 1.5 ) / 7
	D_O_W%		=	INT((( D_O_W - INT( D_O_W )) * 7 ) + 0.5 )

	0		= SUNDAY
	6		= SATURDAY

This will give the Julian day number for the fist Sunday in July, by
subtracting the day of the week (D_O_W) from the Julian day number, from
then on we add ( 4 * 7 - 1 ) or ( 5 * 7 - 1 )  days to find the fiscal
end date this requires sitting in some type of loop adding numbers
and creating a table or until a date match is found.

As noted earlier, we are 1.25 days short every year, which means that at
some point say 4 to 5 years a new week has to be added, eg one year a six
week fiscal month is added.

Question is, does any body know when and by what criteria this is determined?

Paul.

******************************************************************************

These are to two subroutines in basic (VMS) that I use to convert to and
from Julian date format to "normal" date. Note compile /DOUBLE and
link to you routine.


10	SUB	DATETOJD( FROM_DY%, FROM_MN%, FROM_YR%, TO_JUL, TO_DOW% )

20	%SBTTL	'CALCULATE JULIAN DAY NUMBER AND DAY OF WEEK'

1000	IF	FROM_MN%	<= 2
	THEN	JD_FROM_MN%	=  FROM_MN% + 12
 \		JD_FROM_YR%	=  FROM_YR% - 1
 \		JD_FROM_DY%	=  FROM_DY%
	ELSE	JD_FROM_MN%	=  FROM_MN%
 \		JD_FROM_YR%	=  FROM_YR%
 \		JD_FROM_DY%	=  FROM_DY%
	END	IF

	JD_FROM_YR%	=	JD_FROM_YR% + 1900%

	A		=	INT( JD_FROM_YR% / 100 )
	B		=	2 - A + INT( A / 4 )
	C		=	INT( JD_FROM_YR% * 365.25 )
	D		=	INT(( JD_FROM_MN% + 1 ) * 30.6001 )
	TO_JUL		=	B + C + D + JD_FROM_DY% + 1720994.5

	!***	Convert the Julian day number to the day of the week

	A		=	( TO_JUL + 1.5 ) / 7
	TO_DOW%		=	INT((( A - INT( A )) * 7 ) + 0.5 )

 	SUBEXIT

32767	SUBEND

******************************************************************************

10	SUB	DATEFROMJD( TO_DY%, TO_MN%, TO_YR%, FROM_JUL )

20	%SBTTL	'CALCULATE DATE FORM JULIAN DAY NUMBER'

	!***	CONVERT THE JULIAN DAY NUMBER TO THE DATE

	K	=	FROM_JUL + 0.5
	I	=	INT ( K )
	F	=	K - I

	IF	I	>	2299160					&
	THEN	A	=	INT(( I - 1867216.25 ) / 36524.25 )	&
 \		B	=	I + 1 + A - INT( A / 4 )		&
	ELSE	A	=	I					&
 \		B	=	0					&
	END	IF

	C	=	B + 1524
	D	=	INT(( C - 122.1 ) / 365.25 )
	E	=	INT( D * 365.25 )
	G	=	INT(( C - E ) / 30.6001 )
	H	=	C - E + F - INT( G * 30.6001 )

	TO_DY%	=	INT( H )

	IF	G	<	13.5					&
	THEN	TO_MN	=	G - 1					&
	ELSE	TO_MN	=	G - 13					&
	END	IF

	IF	TO_MN	<	2.5					&
	THEN	TO_YR	=	D - 4715				&
	ELSE	TO_YR	=	D - 4716				&
	END	IF

	TO_MN%	= TO_MN
	TO_YR%	= TO_YR - 1900

 	SUBEXIT

32767	SUBEND

T.RTitleUserPersonal
Name
DateLines
555.1Look in the ToolSHedMODEL::YARBROUGHTue Aug 05 1986 18:202
    There is a long discussion of this in the METOO::TOOLSHED notes
    file. It is non-trivial.