?
Solved

How can i exclude weekends in my CF calendar?

Posted on 2005-04-02
4
Medium Priority
?
475 Views
Last Modified: 2013-12-24
I have a calendar program written in CF and HTML
When a user submits a vacation in the calendar, sometimes weekend days are part of the vacation.
Weekends are not charged as vacation, so I would like to change me code to not show the weekend days marked as a vacation day on the calendar.

Can someone help with this?

Cheers
0
Comment
Question by:g118481
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Tacobell777
ID: 13691317
you can see if the date is a saturday or sunday by doing dayOfWeek( now() ) and I beleive its 1 and 7
0
 
LVL 5

Expert Comment

by:kkhipple
ID: 13697829
therefor when you are displaying your calendar... you would have a clause that checks dayOfWeek( #DATE# )

and at each daily iteration of the menu ...
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functi62.htm


i think its better GUI design to show the days of the week including the weekend... one approach you can take is not to allow the user to select the weekneds... so if you have links to each day of the week, remove the links for saturday and sunday... just a thought
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 1000 total points
ID: 13699071
Well I would use a function to calculate business days.  The below tag does so and also allows you to send in a string or a file that contains a list of holidays since you probably don't want to charge vacation on holidays either....

<!--- BusDateDiff.cfm
Description: This CF custom tag calculates the number of business days
between two dates.
Attributes:
START - (required) Start date.
END - (optional) End Date. Default is Now().

HOLIDAYS - (optional) Carriage-return-delimited variable with
list of business holidays.

FILE - (optional) Location of carriage-return-delimited text file with
list of business holidays. Attribute is valid if
ATTRIBUTES.HOLIDAYS does not exist.

NAME - (optional) Variable to save result in. If this attribute
exists, the result is stored in the variable.
Otherwise, the output is printed to the screen.

Example: <CF_BUSDATEDIFF
START="January 1, 1998"
END="December 31, 1998"
NAME="bus_days"
FILE="C:\InetPub\wwwroot\holidays.txt">

Notes: Like the Cold Fusion function DateDiff, CF_BusDateDiff excludes the
start date, yet includes the end date.

Copyright 1998, Troy D. Ely.
This tag is freeware and can thus be freely used, copied,
modified, and distributed as long as this header is left
intact. Please annotate any changes in the code before
modifying. If you experience any problems, or have any
suggestions, please contact me at tchaos@tampabay.rr.com

This tag is studio ready:

In order to use the BusDateDiff.vtm file, you also need to copy
the VTM file into a sub-directory of the Cold Fusion Studio
installation, which is typically:

\Program Files\Allaire\Cold Fusion Studio\Templates\TagEditors\

Last Modified: 02 September 1998
--->
<!--- Ditch excess space --->

<CFSETTING ENABLECFOUTPUTONLY="YES">

<!--- Default parameters --->

<CFPARAM NAME="ATTRIBUTES.START">
<CFPARAM NAME="ATTRIBUTES.END" Default=#Now()#>
<CFPARAM NAME="ATTRIBUTES.HOLIDAYS" DEFAULT="">
<CFPARAM NAME="ATTRIBUTES.FILE" DEFAULT="">

<!--- If bad start or end date, abort with message --->

<CFIF NOT IsDate(ATTRIBUTES.START)>
<CFOUTPUT>You entered an invalid start date.</CFOUTPUT>
<CFABORT>
</CFIF>

<CFIF NOT IsDate(ATTRIBUTES.END)>
<CFOUTPUT>You entered an invalid end date.</CFOUTPUT>
<CFABORT>
</CFIF>

<!--- Load holidays from file, if it exists --->

<CFIF ATTRIBUTES.FILE NEQ "">
<CFIF FileExists(ATTRIBUTES.FILE)>
<CFFILE ACTION="READ" FILE="#ATTRIBUTES.FILE#" VARIABLE="FileText">
<CFELSE>
<CFOUTPUT>The filename supplied to the CF_BusDateDiff tag (#ATTRIBUTES.File#) could not be found.</CFOUTPUT>
<CFABORT>
</CFIF>
<CFELSE>
<CFSET FileText="">
</CFIF>

<!--- Local variables for holiday query --->

<CFSET CR = Chr(13)&Chr(10)>
<CFSET num_holidays = 0>

<!--- count holidays --->

<CFLOOP LIST="#ATTRIBUTES.HOLIDAYS#" INDEX="RowText" DELIMITERS="#CR#">
<CFIF IsDate(RowText)>
<CFIF (DateCompare(ATTRIBUTES.START, Trim(RowText)) EQ -1) AND
(DateCompare(Trim(RowText), ATTRIBUTES.END) LE 0)>
<CFSET num_holidays = num_holidays + 1>
</CFIF>
</CFIF>
</CFLOOP>

<!--- Add holidays in the file to previously counted ones --->

<CFLOOP LIST="#FileText#" INDEX="RowText" DELIMITERS="#CR#">
<CFIF IsDate(RowText)>
<CFIF (DateCompare(ATTRIBUTES.START, Trim(RowText)) EQ -1) AND
(DateCompare(Trim(RowText), ATTRIBUTES.END) LE 0)>
<CFSET num_holidays = num_holidays + 1>
</CFIF>
</CFIF>
</CFLOOP>

<!--- Local variables for date computations --->

<CFSET start_day = DayOfWeek(ATTRIBUTES.START)>
<CFSET end_day = DayOfWeek(ATTRIBUTES.END)>
<CFSET date_diff_in_days = DateDiff("D", ATTRIBUTES.START, ATTRIBUTES.END)>
<CFSET whole_weeks = date_diff_in_days\7>
<CFSET days_left = date_diff_in_days MOD 7>

<!-- Subtract weekends in whole weeks --->

<CFSET non_bus_days = whole_weeks * 2>

<!--- Subtract partial or whole weekends for partial weeks --->

<CFIF days_left>
<CFIF end_day EQ 7 OR start_day EQ 7>
<CFSET non_bus_days = non_bus_days + 1>
<CFELSEIF start_day GT end_day>
<CFSET non_bus_days = non_bus_days + 2>
</CFIF>
</CFIF>

<!--- total business days --->

<CFSET bus_days = date_diff_in_days - non_bus_days - num_holidays>

<!--- Display output --->

<CFIF IsDefined("ATTRIBUTES.NAME")>
<CFSET "Caller.#ATTRIBUTES.NAME#" = bus_days>
<CFELSE>
<CFOUTPUT>#bus_days#</CFOUTPUT>
</CFIF>

<CFSETTING ENABLECFOUTPUTONLY="NO">

0
 
LVL 35

Expert Comment

by:mrichmon
ID: 13699081
I personally use a slightly different version of the above...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What You Need to Know when Searching for a Webhost Provider
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question