Forum OpenACS Q&A: caledar module 3.2.5

Collapse
Posted by David Kuczek on
The calendar module in 3.2.5 shows Sunday as the first day of every
week. I was looking through the code in order to display Monday as the
first day of the week, but it turned out way more complicated than I
thought...

Anyone very familiar with that module?

Collapse
Posted by Jerry Asher on
I was just playing with this last night for another effort. Check out http://theashergroup.com/demos/calendar-widget/.

I added a new command option -week_starts_on_day. This should be a number between 1 and 7, where 1 represents Sunday. Regardless of the setting of this parameter, the days_of_week parameter, if supplied, still starts with "Sunday."

I tarred it up as it appears to be working, but let me know.

Collapse
Posted by Tom Jackson on

Just a note, both cron (unix crontab) and ns_fmttime use '0' as Sunday.

Collapse
Posted by Jerry Asher on
Interesting about ns_fmttime.  The use of 1 for Sunday appears to be a SQL thang.  It's what both Oracle and Postgres use.
Collapse
Posted by David Kuczek on
Looks like everything is working smoothly... GREAT!!!

It is really distracting to have a week start with Sunday. 😊

Collapse
Posted by Jerry Asher on
Oh I completely agree.  I like my week's to start on Wednesday - that way they are half over before they've even begun!
Collapse
Posted by Don Baccus on
So ... are you going to contribute this enhancement to the OpenACS 3.2.6
release?
Collapse
Posted by Kevin Crosbie on
Hi all,

I was wondering if anyone was using this widget still.  I have an ACS site which I had hand converted to start with monday.  Unfortunately, this month, I found that the day numbers were completely wrong, going between 33 and 61 instead of 1 and 30.  It seems to happen whenever the first of the month is in a week by itself.

I checked Jerry's widget out, and it seems to act like this too.

Any ideas as to how I might go about fixing this?

Cheers,

Kevin

Collapse
Posted by Roberto Mello on
Kevin, can you post the code that you're trying to run (in pre tags)? I have run the calendar widget on 3.2.5 for quite some time and it works good (http://fslc.usu.edu/calendar/)

-Roberto

Collapse
Posted by David Kuczek on
Kevin,

I have the same problem, funny! It must be some algorythmical problem with the julian dates... Whenever I click on a date, the correct date is being displayed on the next page.

It would be great if you could share your solution 😊

Collapse
Posted by Kevin Crosbie on
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