Results 1 to 2 of 2

Thread: Customize the script to add holidays.

  1. #1
    Join Date
    Apr 2011
    Location
    Hyderabad, India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Customize the script to add holidays.

    1) Script Title: Dynamic Calendar

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex6/dcalendar.htm

    3) Describe problem: I want to know if there is a way to add a list of holidays in a year to this script so that they too appear in red as a holiday.

    Other than that, it's a simple, yet efficient script.

    Thanks,
    Harsha.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Code:
    if (date.getDay() == 0 || date.getDay() == 6)
    document.layers["idMenuContainer"].document.layers["idDate"+nDate].color = "red";
    else
    //......
    That line determines whether the day is a saturday or a sunday. If it is, then it becomes red. You should be able to check if that date is a holiday like this:
    Code:
    if (date.getDay() == 0 || date.getDay() == 6 || isHoliday(date))
    That will also check if the date is a holiday, if it's not a saturday or a sunday.

    Now this means that you need to add a new Javascript function called "isHoliday()". The exact way that this will work depends on how you want to store your holidays, but here's a basic (non-working) example:
    Code:
    function isHoliday(date) {
       if (date_is_in_list_of_holidays) {
          return true;
       }
       else {
          return false;
       }
    }
    Does that help? Now if you want to fully implement this you'll need to decide how you will store the dates. An array (or object?) is probably best. You can store them in a format like this: "MM-DD" then use this: date.getMonth()+'-'+date.getDate() to find the equivalent string from the current date.
    (Note that it's actually (M)M-(D)D because it would be 1-1 for January first, for example.)

    So basically something like this:
    Code:
    function inArray(needle, haystack) {
        var length = haystack.length;
        for(var i = 0; i < length; i++) {
            if(haystack[i] == needle) return true;
        }
        return false;
    }
    function isHoliday(date) {
       var holidays = new Array('1-1','11-27','12-25');
       if (inArray(date.getMonth()+'-'+date.getDate(),holidays)) {
          return true;
       }
       else {
          return false;
       }
    }
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •