Sponsored Content
Full Discussion: get next working day
Top Forums Programming get next working day Post 302272673 by jim mcnamara on Wednesday 31st of December 2008 10:11:38 AM
Old 12-31-2008
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
Code:
 cal 9 1752

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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

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)
Discussion started by: phani
7 Replies

2. Shell Programming and Scripting

set Working day in ksh

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)
Discussion started by: Rafael.Buria
1 Replies

3. Shell Programming and Scripting

Get Last working day of the month

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)
Discussion started by: manmarirama
6 Replies

4. Shell Programming and Scripting

last working day of previous month

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)
Discussion started by: rspk_praveen
1 Replies

5. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

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)
Discussion started by: girish.raos
3 Replies

6. Shell Programming and Scripting

How to find the first working day of month ?

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)
Discussion started by: vnimavat
10 Replies

7. Shell Programming and Scripting

Calculating 12th working day

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)
Discussion started by: ami_smart
7 Replies

8. UNIX for Dummies Questions & Answers

Running Script via Crontab on 2nd Working day each month

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)
Discussion started by: Hollo
5 Replies

9. Shell Programming and Scripting

Find Month first Working Day

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)
Discussion started by: koti_rama
3 Replies

10. Shell Programming and Scripting

KSH script Not working (calculate days since 1/1/2000 given day 4444)

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)
Discussion started by: thibodc
5 Replies
tztab(4)						     Kernel Interfaces Manual							  tztab(4)

NAME
tztab - time zone adjustment table for date and ctime() DESCRIPTION
The file describes the differences between Coordinated Universal Time (UTC) and local time. Several local areas can be represented simul- taneously with historical detail. The file consists of one or more time zone adjustment entries. The first line of the entry contains a unique string that may match the value of the string in the user's environment. The format is where is the time zone name or abbreviation, diff is the difference in hours from UTC, and is the name or abbreviation of the "Daylight Savings" time zone. Fractional values of diff are expressed in minutes preceded by a colon. Each such string will start with an alphabetic character. The second and subsequent lines of each entry details the time zone adjustments for that time zone. The lines contain seven fields each. The first six fields specify the first minute in which the time zone adjustment, 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. The seventh field is a string that describes the time zone adjustment in its simplest form: where is an alphabetic string giving the time zone name or abbreviation, and diff is the difference in hours from UTC. must match either the field or the field in the first line of the time zone adjustment entry. Any fractional diff is shown in minutes. Comments begin with a in the first column, and include all characters up to a newline. Comments are ignored. EXTERNAL INFLUENCES
International Code Set Support Single-byte character code sets are supported. EXAMPLES
The time zone adjustment table for the Eastern Time Zone in the United States is: Normally (as indicated in the first line) Eastern Standard Time is five hours earlier than UTC. During Daylight Savings time, it changes to a 4 hour difference. The first time Daylight Savings Time took effect (second line) was on January 6, 1974 at 3:00 a.m., EDT. Note that the minute before was 1:59 a.m., EST. The change back to standard time took effect (sixth line) on the last Sunday in November of the same year. At that point, the time went from 1:59 a.m., EDT to 1:00 a.m., EST. The transition to Daylight Savings Time since then has gone from the last Sunday in February (third line) to the last Sunday in April (fourth line) to the first Sunday in April (fifth line). The return to standard time for the same period has remained at the last Sunday in October (seventh line). AUTHOR
was developed by HP. FILES
SEE ALSO
date(1), ctime(3C), environ(5). tztab(4)
All times are GMT -4. The time now is 08:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy