Hi David,
I fixed the system that I use, i.e. to start on Monday. My system was based on ACS 3.4, which doesn't have Jerry's fix. I haven't fixed Jerry's, as you need to play around with values and work out the exact formula which will handle starting on any day of the week.
I would say that this solution will work for you, as you say that you want your calendar to start on Monday:
all of the changes are in calendar_info_from_db.
in the sql part, change:
to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), 'D') as first_day_of_month,
to:
decode(mod(to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), 'D')+6,7),0,7,mod(to_char(trunc(to_date(:the_date, 'yyyy-mm-dd'), 'Month'), 'D')+6,7)) as first_day_of_month,
Now, in the part where you are setting your variables, use:
# We put all the columns into calendar_info_set and return it later
set calendar_info_set [ns_set create]
set bind_vars [ad_tcl_vars_to_ns_set the_date]
db_1row calendar_get_information $month_info_query -bind $bind_vars -column_set calendar_info_set
ns_set free $bind_vars
# We need the variables from the select query here as well
ad_ns_set_to_tcl_vars $calendar_info_set
ns_set put $calendar_info_set first_julian_date
[expr $first_julian_date_of_month + 1 - $first_day_of_month]
ns_set put $calendar_info_set first_day
[expr $days_in_last_month + 2 - $first_day_of_month]
ns_set put $calendar_info_set last_julian_date_in_month
[expr $first_julian_date_of_month + $num_days_in_month - 1]
set days_in_next_month [expr 7 - (($num_days_in_month + $first_day_of_month - 1) % 7)]
if {$days_in_next_month == 7} {
set days_in_next_month 0
}
ns_set put $calendar_info_set last_julian_date
[expr $first_julian_date_of_month + $num_days_in_month - 1 + $days_in_next_month]
# Now, set the variables in the caller's environment
ad_ns_set_to_tcl_vars -level 2 $calendar_info_set
ns_set free $calendar_info_set
I tested it all out using Jerry's version, and there are one or two things you need to change to the above solution:
The sql changes in the same way, and the variables change to:
# We put all the columns into calendar_info_set and return it later
set calendar_info_set [ns_set create]
set bind_vars [ad_tcl_vars_to_ns_set the_date]
db_1row calendar_get_information $month_info_query -bind $bind_vars -column_set calendar_info_set
ns_set free $bind_vars
# We need the variables from the select query here as well
ad_ns_set_to_tcl_vars $calendar_info_set
ns_set put $calendar_info_set first_julian_date
[expr $first_julian_date_of_month + 0 - $first_day_of_month]
ns_set put $calendar_info_set first_day
[expr $days_in_last_month + 1 - $first_day_of_month]
ns_set put $calendar_info_set last_julian_date_in_month
[expr $first_julian_date_of_month + $num_days_in_month - 1]
set days_in_next_month [expr 7 - (($num_days_in_month + $first_day_of_month - 1) % 7)]
if {$days_in_next_month == 7} {
set days_in_next_month 0
}
ns_set put $calendar_info_set last_julian_date
[expr $first_julian_date_of_month + $num_days_in_month - 2 + $days_in_next_month]
# Now, set the variables in the caller's environment
ad_ns_set_to_tcl_vars -level 2 $calendar_info_set
ns_set free $calendar_info_set
Regards,
Kevin