# # # build_calendar_html() # # include "templates.util.date_time.date_time"; include "templates.statistics.calendar.get_calendar_info"; subroutine(build_calendar_html( string profile_name, node report_job), ( node db_state = report_job . ".report_state.database"; string earliest_log_date = @db_state{"earliest_log_date"}; string latest_log_date = @db_state{"latest_log_date"}; int first_weekday = @report_job{"first_weekday"}; int marked_weekday = @report_job{"marked_weekday"}; # Fix older profiles where first_weekday or marked_weekday contains a 0 value. # The 0 value must be converted to 1 if (first_weekday == 0) then (first_weekday = 1); if (marked_weekday == 0) then (marked_weekday = 1); # # Note, weekdays are counted from 1-7! # 1 = Sunday # 2 = Monday # .. # 7 = Saturday # debug_message("\n\n#### build_calendar_html() START \n\n"); debug_message("#### earliest_log_date: " . earliest_log_date . "\n"); debug_message("#### latest_log_date: " . latest_log_date . "\n"); debug_message("#### first_weekday: " . first_weekday . "\n"); debug_message("#### marked_weekday: " . marked_weekday . "\n"); # # # Get calendar_info # # node calendar_info = get_calendar_info(profile_name, earliest_log_date, latest_log_date); int earliest_date_in_epoc = date_time_to_epoc(earliest_log_date . " 12:00:00"); int latest_date_in_epoc = date_time_to_epoc(latest_log_date . " 12:00:00"); volatile.temp_week_count = 0; # # # get_weekdays_info() # # # Returns a node where the node names present the ordered weekdays (as in calendar). # An "offset" subnode presents the offset/shift value of the first of the month which is used # to position the first day of the month. # # A "seconds_relative_to_start_day_in_week" subnode keeps the seconds relative to the start # day of a week. It is used to calculate the start day of a week. # # A "seconds_relative_to_end_day_in_week" subnode keeps the seconds relative to the end # day of a week. It is used to calculate the end day of a week. subroutine(get_weekdays_info(int first_weekday), ( delete_node("v.weekdays_info"); int weekday_count = first_weekday; int j = 6; for (int i = 0; i < 7; i++) ( "v.weekdays_info." . weekday_count . ".offset" = i; "v.weekdays_info." . weekday_count . ".seconds_relative_to_start_day_in_week" = 24 * 60 * 60 * i; "v.weekdays_info." . weekday_count . ".seconds_relative_to_end_day_in_week" = 24 * 60 * 60 * j; weekday_count++; j--; if (weekday_count > 7) then ( # start over with 1 weekday_count = 1; ); ); debug_message("\n\n" . node_as_string("v.weekdays_info") . "\n"); "v.weekdays_info"; )); subroutine(get_week_id( node weekdays_info, int earliest_date_in_epoc, int latest_date_in_epoc, string year, string month_number, string month_in_salang_format, int day), ( # debug_message("\n\n#### get_week_id() START \n"); # This subroutine calculates the start date and end date of a week. # The given day in the argument can be any day in the week. # Note that the first letter in week ID's is followed by a number. The number avoids duplicate id's # because the last week id in i.e. Jan could be the same id as the first week in Feb! # Get the week_count int week_count = volatile.temp_week_count; volatile.temp_week_count = week_count + 1; # Get the weekday int weekday = get_weekday(year, month_number, day); string day_in_salang_format = if (day > 9) then (day) else ("0" . day); string date_time = day_in_salang_format . "/" . month_in_salang_format . "/" . year . " 12:00:00"; int day_in_epoc = date_time_to_epoc(date_time); int start_day_in_epoc = day_in_epoc - @(weekdays_info . "." . weekday . ".seconds_relative_to_start_day_in_week"); int end_day_in_epoc = day_in_epoc + @(weekdays_info . "." . weekday . ".seconds_relative_to_end_day_in_week"); if (start_day_in_epoc < earliest_date_in_epoc) then ( start_day_in_epoc = earliest_date_in_epoc; ); if (end_day_in_epoc > latest_date_in_epoc) then ( end_day_in_epoc = latest_date_in_epoc; ); string start_day = epoc_to_date_time(start_day_in_epoc); string end_day = epoc_to_date_time(end_day_in_epoc); # debug_message("#### start_day: $start_day \n"); # debug_message("#### end_day: $end_day \n"); # Note, month in week_id is in javascript format (0-11) string week_id = "w" . week_count . ":" . get_year(start_day) . ":" . (get_month_as_number(start_day) - 1) . ":" . get_day(start_day) . ":"; week_id .= get_year(end_day) . ":" . (get_month_as_number(end_day) - 1) . ":" . get_day(end_day); # debug_message("#### weekday: $weekday \n"); # debug_message("#### week_id: $week_id \n"); week_id; )); subroutine(build_days_header_row( int first_weekday, int marked_weekday), ( int weekday_label_count = first_weekday; string weekday_label; string span_class_name; '
\n';
'
| \n';
'|||
\n';
' \n';
' \n';
' | \n';
'