Macbuoy, in one of his comments, asked about shifting the day of the week functionality that ColdFusion provides. By default, ColdFusion assigns Sunday as day One and Saturday as day Seven. To shift this value, such as having Monday be day One and having Sunday be day Seven, requires wrapping ColdFusion's DayOfWeek() method in a custom, user defined function:
Launch code in new window » Download code as text file »
This ColdFusion user defined function takes an optional argument, FirstDayOfWeek, which will define which day is the first day of the week. It defaults to 2 which defines Monday as day One, but this can be any value between 1 and 7 (I am not doing any error checking on that).
To test, let's run over two weeks worth of dates to see how this ColdFusion user defined function translates the original DayOfWeek() to our business-related day of week:
Launch code in new window » Download code as text file »
This gives us the following output:
06-May-07 - 1 -to- 7
07-May-07 - 2 -to- 1
08-May-07 - 3 -to- 2
09-May-07 - 4 -to- 3
10-May-07 - 5 -to- 4
11-May-07 - 6 -to- 5
12-May-07 - 7 -to- 6
13-May-07 - 1 -to- 7
14-May-07 - 2 -to- 1
15-May-07 - 3 -to- 2
16-May-07 - 4 -to- 3
17-May-07 - 5 -to- 4
18-May-07 - 6 -to- 5
19-May-07 - 7 -to- 6
As you can see, we are successfully translating Monday (day 2) as the first day of the week.
Download Code Snippet ZIP File
Comments (7) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
Sending Text Messages (SMS) With ColdFusion And CFMail
ColdFusion Jobs And Developer Circuit's Distributed Flex Widget
good work, this should really have been an optional parameter to the function in the first place. CF's default to Sunday for the first day of the week isn't logical, especially for us in the UK. It's also against ISO 8601.
http://en.wikipedia.org/wiki/ISO_8601
Posted by duncan on May 9, 2007 at 4:20 AM
How is it in the UK? Is Monday the first calendar day over there?
Posted by Ben Nadel on May 9, 2007 at 7:54 AM
yes indeed.
Posted by duncan on May 9, 2007 at 10:27 AM
I'm not sure if I'm doing something wrong, but when I apply this to my version of your most recent Month calendar, I'm getting dates misaligned with day of week. I'm going to start from scratch with your example and add the new wrapper and see how it turns out.
Will report.
Posted by macbuoy on May 9, 2007 at 10:56 AM
Interesting. I did not try applying it to the calendar. I will give it a go at lunch, see what I can come up with.
Posted by Ben Nadel on May 9, 2007 at 10:58 AM
yeah. When I apply this to this:
http://www.bennadel.com/index.cfm?dax=blog:663.view
calendar grid alignment is off. my first guess is that I'm applying the wrapper too often. . .I need to understand the MyDayOfWeek math better to do this right.
Posted by macbuoy on May 9, 2007 at 11:05 AM
@Macbuoy,
Check this out:
http://www.bennadel.com/index.cfm?dax=blog:693.view
You're probably making a small mistake somewhere. This took practically no changes. I just replaced the DayOfWeek() calls and reordered the calendar header.
Posted by Ben Nadel on May 9, 2007 at 1:47 PM