Operating System - HP-UX
1748140 Members
3735 Online
108758 Solutions
New Discussion юеВ

Re: First work day in the month?

 
SOLVED
Go to solution
Ryan Clerk
Frequent Advisor

Re: First work day in the month?

Hi Clay,

My script now works great but I have a new problem. My company has offices in three countries and some of the holidays are different for each of them. Is there a way to use a different file instead of /etc/acct/holidays?

Thanks,
Ryan
A. Clay Stephenson
Acclaimed Contributor

Re: First work day in the month?

Great Googly Moogly, Ryan.

You are wanting WAY too much sugar for a dime. You could move your holidays file(s) to a temporary location and replace with different version(s) and move the temporary
file(s) back to the original location when finished. The only downside is that this action could clobber accounting if someone happened to be running some of the accounting commands during the interim.

I'll take a look and see how hard this will be. One of my biggest problems is finding free letters for options. There have been so many requests for enhancements that the alphabet is beginning to run dry. There was a time when caljd.sh was only a few lines long.
If it ain't broke, I can fix that.
Hein van den Heuvel
Honored Contributor

Re: First work day in the month?

>> My script now works great but I have a new problem. My company has offices in three countries and some of the holidays are different for each of them. Is there a way to use a different file instead of /etc/acct/holidays?


Ryan,

You may want to further clarify this need.
I'm guessing here that you want to run the script in a central location, for all countries, otherwise it should prove easy enough to give each country the right holidays file.

Are you now looking for the first day in the months which is a work day in all countries? That's create serious missunderstandings I bet! Or do just want to deal with a country at a time?
If so, it would be nice if the script poicked up an environment variable to point to the right holidays file, or you coudl temporary softlink it.

Clay,
I tend to deal with running out of letter in the alphabet through env variables.

In your case without a letter of an explicit argument option I would code up something like:

my $CALJD_HOLIDAY_FILE='etc/acct/holidays';
my $CALJD_HOLIDAYS_ENV='CALJD_HOLIDAYS';
:
my $caljd_holiday_file = $ENV{$CALJD_HOLIDAYS_ENV};
$caljd_holiday_file = $CALJD_HOLIDAY_FILE unless $caljd_holiday_file ;


If I have a letter, then I might use getops as, in a 3-way naming scheme as

my $EVALUATE_CSV = "EVALUATE_CSV";
my $CSV = "evaluate.csv";
:
getopts ('c:dr:vis',\%opt) or &usage;
&usage unless @ARGV;
$verbose = $opt{v} ? 1 : 0;
$debug = $opt{d} ? 1 : 0;
$csv = $opt{c} ? $opt{c} : $ENV{$EVALUATE_CSV} ;
$csv = $CSV unless $csv;

So there is 3 places to get a name...
1) explicit argument
2) env variable
3) softcoded default.



But you knew all that!
Cheers,

Hein.




A. Clay Stephenson
Acclaimed Contributor

Re: First work day in the month?

Ok, Ryan. This proved to be not too difficult. I added a -H /home/user1/holidays option which behaves exactly like -h except that the specified filename, /home/user1/holidays, substitues for /etc/acct/holidays. Moreover, the filename_yyyy convention applies so that you can create multiple years.

Based upon your script logic, your should now be able to replace the "-h" argument with "-H ${YOURFILE}".

It took much longer to update the usage and examples than it did to implement the actual coding changes.

Here is caljd.sh, Vrsn 2.3.

Hein: Thanks for the advice but fortunately 'H' was still available.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: First work day in the month?

... and here is the equivalent, caljd.pl, Vrsn 2.3 p.
If it ain't broke, I can fix that.
Ryan Clerk
Frequent Advisor

Re: First work day in the month?

Clay,

Thank you very much! The new option works great!

Hein,
Thanks for your ideas as well.

This is the best unix website in the world!!!!!

Thank you,
Ryan
Tor-Arne Nostdal
Trusted Contributor

Re: First work day in the month?

This is just to give some general comments and also more credit to Clay.

In general this topic once again show:
'somebody need to enter the holidays'
'there's local variations'
'many systems have the need for handling several calendars'
Our company is involved in operations many places around the world. Date/Time/Timezones/holidays/character sets seems to always be a returning problem.

Using Julian date have always been one of the trick's to overcome some of the date calculation problems.

Thanks Clay for yet a new version of caljd I've been using it for "the tricky dates" many times, and other times as reference lookup when "date scripting".

P.S.
* In some countries first working day would also be Sunday... :-)

* If you have Microsoft Outlook you could search for a file named: OUTLOOK.HOL
This is a flat-file which can contain dates that you need. It is also sectioned into countries.

/Tor-Arne
I'm trying to become President of the state I'm in...