i want to get next working day from give date, that is other than Saturday or Sunday.
suppose given date is 26-DEC-2008 (i.e Friday) then i should get 29-DEC-2008 as next working day(i.e Monday). how code this in C. do we have any calendar API in C. please help me out.
thanks and regards
Include <time.h>, get the current time (time(2)), increase once by 86400 (next day), feed it to localtime(3) and check if 0<struct tm.tm_wday<6 (Mon-Fri is 1-5). If it's not in that range, increase by 86400 until it is.
Feed you character array to strptime(3), the resulting struct tm to mktime, the resulting time_t to localtime, and test that result until struct tm.tm_wday indicates a workday. Then convert it to a character array and return that.
fpmurphy gave you a very reasonable response based on your requirements.
I work in calendrics a lot, and the requirements you stated for the
definition of a "business day" were either very naive, or for a country
I have never done work for. In most places there are a lot of other
considerations as to what the definition of a "business day" is.
One reason is because the requirment doesn't take holidays and religious
observances into account. Holidays are never trivial, they are often
very local and often based on a distinctly non-Gregorian lunar
calculation. So there is no general method presented very often.
The other issue is that programmers think they "know" calendars
because they grew up with them, but may not know what calendars really do..
Even for the Gregorian calendar. Read the langinfo man page. Look at
the output of
Do you know why September seems wrong?
And if you live in France that output of cal is wrong.
Holidays --
One way is parse a tztab-like file, then write code: maybe a "isholiday(struct
tm *)" function to parse the table the against a given date:
Quote:
# The first six fields specify the first minute in which a holiday
# specified in the seventh field, applies. The fields are
# separated by spaces or tabs. The first six are integer patterns that
# specify the minute (0-59), hour (0-23), day of the month (1-31), month
# of the year (1-12), year (1970-2038), and day of the week (0-6, with
# 0=Sunday). The minute, hour, and month of the year must contain a
# number in the (respective) range indicated above. The day of the
# month, year, and day of the week can contain a number as above or two
# numbers separated by a minus (indicating an inclusive range). Either
# the day of the month or the day of the week field must be a range, the
# other must be simple number.
#
#
# Holiday table - partial table example
MST7MDT
#minute
# hour
# DOM
# month
# year
# DOW
0 0 25 12 1990-2038 1-5 christmas
0 0 24 12 1990-2038 1-5 christmas eve
0 0 26 12 1990-2038 1 christmas on sunday
0 0 23 12 1990-2038 5 christmas eve on saturday
0 0 4 7 1990-2038 1-5 july 4
0 0 3 7 1990-2038 5 july 4 on saturday
0 0 5 7 1990-2038 1 july 4 on sunday
0 0 25-31 5 1990-2038 1 Memorial day always on the last monday of may
0 0 15-21 1 1990-2038 1 MLK day 3rd Monday in April
0 0 1-7 9 1990-2038 1 Labor day 1st Monday in Sept
0 0 E-2 0 0 0 Good Friday two days before easter
The E-2 entry is a paschal lunar easter algorithm for western Easter
(as opposed to Orthodox Easter) - the entry above returns two days
before Easter. Lunar holidays and very important religious observances
usually require special algorithms.
The table also deals with moving holidays onto work days, like observing
July 4th (a US holiday) on July 5 or on July 3 because July 4 is on a weekend.
I am unable to get this KSH script to work. Can someone help. I've been told this should work with KSH93. Which I think I have on Solaris 10.
If I do a grep -i version /usr/dt/bin/dtksh I get
@(#)Version M-12/28/93d
@(#)Version 12/28/93
@(#)Version M-12/28/93
This is correct for... (5 Replies)
Hi,
I would like to calculate 1st working/Business day of each month.
Exp:
1st -Oct-2011 is Saturday--- Non Business Day
So the Next Working Day would be 3-Oct-2011
I need a shell script to calculate the month first business date. (3 Replies)
Hello Guys,
I have a questions regarding running a shell script every second working day each month.
I have no clue how solve this problem :wall:.
Important is that it has to be the second working (Mo-Fr).
Example: If 1st and 2nd Days of month are Sat and Sun the script must run on 4th day... (5 Replies)
I have a business requirement in my project where I need to calculate the 12th working day of every month. Can any please tell me the solution to my problem.
Thanks in advance (7 Replies)
Hi,
How to find the first working day of month ?
My requirement is, I need to call the function only if today is first working day of month. I could find out one function which finds last working day in month in this forum. Can anyone pls let me know for first working day. Thanks.
for... (10 Replies)
Hi All,
I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this.
My Requirment is as below:
Input for me will be 2000909(YYYYMM)
I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Hi,
I want a script(ksh) to see if today is the last working day(Mon-Fri) of the month. If it is the last working day I need to print current date, else I need the last working day of previous month. Thanks in advance. (1 Reply)
Hi
I need a script to get "Last working day of the month". I will pass the month and year as parameters and i need to get the last working date.
Ex
for June 2008 the last working day is 30th its monday.
for August 2008 the last working day is 29th and it is Friday.
ie the last working... (6 Replies)
Hello guys it´s a pleasure to type with the unix community...I´m new in shell script and I need to insert into a #!/ksh a statment that will check if a file that I´ll receive from another script is arriving in the first working day of each month:
let´s say that I´ll reveive the following files... (1 Reply)
Hi ,
I am relatively new to unix...
Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell..
This is very urgent.
Thanks for ur help... (7 Replies)