Operating System - OpenVMS
1829142 Members
6422 Online
109986 Solutions
New Discussion

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

 
sne
New Member

FIND THE FIRST WORKING OF DAY OF EACH MONTH

I need to write a proc to find the first working day of each month. i need this to schedule a monthly job.
21 REPLIES 21
Steven Schweda
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Define "working day". Hint:

alp $ write sys$output f$cvtime( "1-jan-2005", , "WEEKDAY")
Saturday

alp $ write sys$output f$cvtime( "2-jan-2005", , "WEEKDAY")
Sunday

alp $ write sys$output f$cvtime( "3-jan-2005", , "WEEKDAY")
Monday
Art Wiens
Respected Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Can you specify what "first working day" means to you?

First Monday of the month?

Art
sne
New Member

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

I need the first business day of each month. Ex: Jan 2006, first business day of the month was physically Jan 2-Monday, but first business day was jan 3rd, as 2nd was a substitute holiday for some companies. This needs to be in a continuous process as I need to schedule a job for the first business day of every month over the next 5 years.
Steven Schweda
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

I wouldn't hold my breath waiting for a new
"HOLIDAY_FOR_ME" output_field option for the
F$CVTIME() lexical function. It doesn't seem
to be a very well defined concept.
Wim Van den Wyngaert
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

The most simple and reliable way to do this is to store the 5 * 12 dates in a file. Manually. Would only take a few minutes.

Wim
Wim
Joseph Huber_1
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

In one of the Freeware distributions, there was a DCL file HOLIDAYS.COM, which might be helpfull.
It uses general algorithms (e.g. for Easterday), and additional customization by external files.

If You can find it on the freeware sites, here is my copy:
http://wwwvms.mppmu.mpg.de/vms$common/com/holidays.com

http://www.mpp.mpg.de/~huber
Doug_81
Frequent Advisor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

I've attached a command file which shows a bit of logic I use for that very function.

Should do the trick for you.

Doug
Robert_Boyd
Respected Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Doug,

a suggestion/request for you -- if you post DCL procedures here, please change the file type to .txt since some companies prevent access to files that look like Windows executable code from web sites.

Robert
Master you were right about 1 thing -- the negotiations were SHORT!
Doug_81
Frequent Advisor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Thanks Robert. I'll do that in the future.

Doug
sne
New Member

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Doug,

Where can I file the holidays.dat file. should i create one.

sne
sne
New Member

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Sorry it is find the file. holidays.dat

sne
Robert_Boyd
Respected Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Check out the CVTIME.COM posted under this thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=993097

CVTIME.COM provides sample code of how to calculate the beginning of a month.

Then you can use the code provided for checking if it's a weekend or holiday, and if so, bump the date ahead by 1 until you get one that is neither weekend nor holiday.

Robert
Master you were right about 1 thing -- the negotiations were SHORT!
Doug_81
Frequent Advisor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

sne:
Yes. Create a file called holidays.dat and put a list of holidays in it e.g. as follows:

20051226
20051227
20060102

Where the dates correspond to your actual holiday dates, of course.
Martin Vorlaender
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

A more general solution could include use of "Remind", a piece of Open Source software to handle calendar-related calculations.

One of the examples provided refers to the July 4th holiday:

#############################################################################
# Here's a tricky problem: The 4th of July is a holiday in the U.S.
# However, if it falls on a Saturday, the previous Friday is a holiday.
# If it falls on a Sunday, the next Monday is a holiday. Here's how
# to do it.############################################################################

# Calculate the weekday of the holiday.
REM 4 July SCANFROM [_back(7)] SATISFY 1

IF WKDAYNUM(TRIGDATE()) == Sat
REM [TRIGGER(TRIGDATE())] MSG Independence day (actual)
OMIT [TRIGGER(TRIGDATE()-1)] MSG Independence day (observed)
ELSE
IF WKDAYNUM(TRIGDATE()) == Sun
REM [TRIGGER(TRIGDATE())] MSG Independence day (actual)
OMIT [TRIGGER(TRIGDATE()+1)] MSG Independence day (observed)
ELSE
OMIT [TRIGGER(TRIGDATE())] MSG Independence day
ENDIF
ENDIF

You can find it at http://www.roaringpenguin.com/penguin/open_source_remind.php . In my experience, it wasn't hard to get it to compile under VMS.

cu,
Martin
Lawrence Czlapinski
Trusted Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

sne,
If you a system admin, then a good place for this would be in a monthly processing section of DAILY_MGR.COM (or whatever you have).
$! For English language
$ IF (F$CVTIME("TODAY",,"WEEKDAY").NES. "Saturday").AND.
(F$CVTIME("TODAY",,"WEEKDAY").NES. "Sunday") $ THEN
$! Calculate first business day of month
...
$! If first business day of month then submit your job.
$ IF F$CVTIME("TODAY",,"DAY") .EQS. FIRST_BUSINESS_DAY THEN SUBMIT ...
$ ENDIF
Lawrence
Hein van den Heuvel
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

I agree with Steven, Wim, Doug... just stick the dates in a file and look it up.

You might want to stick them into an indexed file for easy key lookup.

You might want to seed the file with a script, and then review and tweak as needed.
(datatrieve, dcl, edit+reconvert,...)

Below two DCL scripts to get you going with this. The first will create a file. The second will do a lookup. GIve it a whirl?

-------------- FIRST_WORKING_DAY.com -------
$! This procedure will generate a list of the first non-weekend days in each month.
$!It will create and seed the file if needed.
$! Provide YEAR to generate dates for as argument. Default is this year.
$
$file = F$ELEM(0,";",F$ENVI("PROCEDURE")) + "~" - ".COM~" + ".DAT"
$year = F$CVTIME("",,"YEAR")
$IF p1.nes."" THEN year = p1
$months := JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC
$Sunday_day := "02"
$Saturday_day := "03"
$month = 0
$OPEN/READ/WRITE/SHARE=WRITE/ERROR=create_file file 'file
$write:
$flag = " "
$date = "01-" + F$EXT(month*3,3,months) + "-" + year
$day = F$CVTIME(date,,"WEEKDAY")
$IF F$TYPE('day'_day) .NES. ""
$THEN
$date = 'day'_day + F$EXTR(2,9,date)
$flag := "*"
$ENDIF
$numeric_date = F$CVTIME(date,"COMPARISON","DATE") - "-" - "-"
$record = numeric_date + flag + date
$WRITE file record
$month = month + 1
$IF month .LT. 12 THEN GOTO write
$CLOSE file
$oops:
$EXIT
$
$create_file:
$CREATE/LOG/FDL=SYS$INPUT: 'file
file; organization indexed; key 0; seg0_length 8
$OPEN/READ/WRITE/ERROR=oops file 'file
$WRITE file "99999999 01-APR-9999" ! Stopper
$GOTO write
$



-------- lookup_FIRST_WORKING_DAY.com ------
$file = F$ELEM(0,";",F$ENVI("PROCEDURE")) + "~" - ".COM~" + ".DAT" - "LOOKUP_"
$date = F$TIME()
$IF p1.nes."" THEN date = p1
$target_year = F$CVTIME(date,,"YEAR")
$OPEN/READ/SHARE=WRITE/ERROR=create_file file 'file
$numeric_date = F$CVTIME(date,"COMPARISON","DATE") - "-" - "-"
$READ/MATCH=GT/KEY=&numeric_date file record
$numeric_first_working_day = F$EXTR(0,8,record)
$first_working_day = F$EXTR(9,99,record)
$SHOW SYMBOL first_working_day
$CLOSE file
$IF numeric_first_working_day .EQS. "99999999" THEN EXIT 9372
$EXIT

hth,
Hein.


Jan van den Ende
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

In for some REAL fun?

Some days are holidays ONLY to Jews, others ONLY to Muslims, or ONLY to catholics (but not to other Christians), and ... (please extend at will).
Then there exist days that are ONLY holidays to inhabitants of certain areas or towns (personal example: to me and my town-fellows April 1 is just about the biggest holiday of the year - the start of the liberation of the Netherlands back in 1572 by freeing our town Brielle).

Now, anyone who can get ALL of those together in one routine, THAT would be an achievement!

I'm clearly having a bad case of the Friday-afternoon feeling :-) :-)

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Doug_81
Frequent Advisor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Now, now Ende. Take a deep breath, count (slowly) to 10 and use the routine I posted earlier. Since it uses a data file which lists all the holidays you want to include (or make up), you can relax.

Doug
Jan van den Ende
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Doug,

(it still is friday!)

I could not find any means in your datafile to distinguish Jewish users from Catholics from Muslims from Buddhists from Briellenaren from Bavarians from .... :-)

and still, those different users have different holidays, even if users of the same system.

Multicultural societies are complex, and complex societies have complex problems!

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Doug_81
Frequent Advisor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Ende:
This is a good thing!
This procedure accepts all religions and treats them all equally. Even Jewish, Catholics, Muslims, Buddhists, Briellenaren, Bavarian or any other religion you wish to invent.

Simply put in the date of the holiday into the datafile and it is immediately accepted - no questions asked.

And, I think I will have one on you - thank you!

Doug
Jan van den Ende
Honored Contributor

Re: FIND THE FIRST WORKING OF DAY OF EACH MONTH

Doug,


This is a good thing!
This procedure accepts all religions and treats them all equally.


It _WOULD_ be a good thing if religions were prepared to be treated equally.
Just look at the dayly news broadcasts: how may wars are currently being fought that are (at least partly) religion-based?

That is my whole point: as soon as you pick one to base your holiday definitions upon, all others are discriminated, which is "not always" well-received!.

Then again, a day that is a holiday for only part of the users, probably is a working day for some others, meaning that for "the system" it is to be treated as a working day....
VERY hard to find a consensus!

... and we do not have the problem anyhow, being a full 24 * 365 organisation.

I think I will wash down the confusion with a good beer and forget about it.


Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.