Loading ...
Sorry, an error occurred while loading the content.
 

Re: [ydn-javascript] Calendar week numbers: how do I set a different starting week number?

Expand Messages
  • dav.glass@yahoo.com
    Anup -- You should be able to override the DateMath function called: getWeekNumber. You could mod it something like this: YAHOO.widget.DateMath.getWeekNumber
    Message 1 of 3 , Apr 3, 2007
      Anup --

      You should be able to "override" the DateMath function called: getWeekNumber.

      You could mod it something like this:

      YAHOO.widget.DateMath.getWeekNumber = function(date, calendarYear) {
          date = this.clearTime(date);
          var nearestThurs = new Date(date.getTime() + (4 * this.ONE_DAY_MS) - ((date.getDay()) * this.ONE_DAY_MS));

          var jan1 = new Date(nearestThurs.getFullYear(),2,1);
          var dayOfYear = ((nearestThurs.getTime() - jan1.getTime()) / this.ONE_DAY_MS) - 1;
          var weekNum = Math.ceil((dayOfYear)/ 7);

          if (weekNum < 0) {
              var jan1 = new Date(nearestThurs.getFullYear() - 1 ,2,1);
              var dayOfYear = ((nearestThurs.getTime() - jan1.getTime()) / this.ONE_DAY_MS) - 1;
              var weekNum = Math.ceil((dayOfYear)/ 7);
          }
          return weekNum;
      }

      Now include this function somewhere after the YUI includes, but before you initialize your calendar..

      Hope that helps 8-)

      Dav
       
      Dav Glass
      dav.glass@...
      blog.davglass.com


      + Windows: n. - The most successful computer virus, ever. +
      + A computer without a Microsoft operating system is like a dog
      without bricks tied to its head +
      + A Microsoft Certified Systems Engineer is to computing what a
      McDonalds Certified Food Specialist is to fine cuisine +


      ----- Original Message ----
      From: anup.shah <anupshah.geo@...>
      To: ydn-javascript@yahoogroups.com
      Sent: Tuesday, April 3, 2007 3:59:06 AM
      Subject: [ydn-javascript] Calendar week numbers: how do I set a different starting week number?

      Hi,

      I use the YUI Calendar's SHOW_WEEK_HEADER property to show the week
      number, which is great.

      However, it uses Jan 1 as week number 1.

      I need to use a financial year (March 1) for our customer. Is there a
      way to configure what the start week for week number should be?

      I was thinking of somehow using the DateMath's getWeekNumber() method
      to get week number, offsetting for March 1 (based on Jan 1 = week 1)
      and update the value somehow, but that feels like more work than
      necessary. [If I had to do this, what event would I attach to do this?]

      Is there a config setting I am missing to indicate what week should be
      the first week number?

      Many thanks!
      Anup




      Yahoo! Groups Links

      <*> To visit your group on the web, go to:
          http://groups.yahoo.com/group/ydn-javascript/

      <*> Your email settings:
          Individual Email | Traditional

      <*> To change settings online go to:
          http://groups.yahoo.com/group/ydn-javascript/join
          (Yahoo! ID required)

      <*> To change settings via email:
          mailto:ydn-javascript-digest@yahoogroups.com
          mailto:ydn-javascript-fullfeatured@yahoogroups.com

      <*> To unsubscribe from this group, send an email to:
          ydn-javascript-unsubscribe@yahoogroups.com

      <*> Your use of Yahoo! Groups is subject to:
          http://docs.yahoo.com/info/terms/


    • anup.shah
      Thanks Dave. Overriding the getWeekNumber method (or even the YAHOO.widget.Calendar.prototype.renderRowHeader ) was another thing I was thinking. I was feeling
      Message 2 of 3 , Apr 3, 2007
        Thanks Dave.

        Overriding the getWeekNumber method (or even the
        YAHOO.widget.Calendar.prototype.renderRowHeader ) was another thing I
        was thinking.

        I was feeling a bit hesitant to do that in case of problems for me if
        later versions of Calendar changed how they work. But then I thought
        that I am sure to have many other things to change/refactor anyway.

        I may try assigning the existing renderRowHeader method to another
        variable, so that I can call it from my overriding renderRowHeader,
        just with a calculated new week number to use!

        Anup

        --- In ydn-javascript@yahoogroups.com, dav.glass@... wrote:
        >
        > Anup --
        >
        > You should be able to "override" the DateMath function called:
        getWeekNumber.
        >
        > You could mod it something like this:
        >
        > YAHOO.widget.DateMath.getWeekNumber = function(date, calendarYear) {
        > date = this.clearTime(date);
        > var nearestThurs = new Date(date.getTime() + (4 *
        this.ONE_DAY_MS) - ((date.getDay()) * this.ONE_DAY_MS));
        >
        > var jan1 = new Date(nearestThurs.getFullYear(),2,1);
        > var dayOfYear = ((nearestThurs.getTime() - jan1.getTime()) /
        this.ONE_DAY_MS) - 1;
        > var weekNum = Math.ceil((dayOfYear)/ 7);
        >
        > if (weekNum < 0) {
        > var jan1 = new Date(nearestThurs.getFullYear() - 1 ,2,1);
        > var dayOfYear = ((nearestThurs.getTime() - jan1.getTime()) /
        this.ONE_DAY_MS) - 1;
        > var weekNum = Math.ceil((dayOfYear)/ 7);
        > }
        > return weekNum;
        > }
        >
        > Now include this function somewhere after the YUI includes, but
        before you initialize your calendar..
        >
        > Hope that helps 8-)
        >
        > Dav
        >
        > Dav Glass
        > dav.glass@...
        > blog.davglass.com
        >
        >
        > + Windows: n. - The most successful computer virus, ever. +
        > + A computer without a Microsoft operating system is like a dog
        > without bricks tied to its head +
        > + A Microsoft Certified Systems Engineer is to computing what a
        > McDonalds Certified Food Specialist is to fine cuisine +
        >
        > ----- Original Message ----
        > From: anup.shah <anupshah.geo@...>
        > To: ydn-javascript@yahoogroups.com
        > Sent: Tuesday, April 3, 2007 3:59:06 AM
        > Subject: [ydn-javascript] Calendar week numbers: how do I set a
        different starting week number?
        >
        > Hi,
        >
        > I use the YUI Calendar's SHOW_WEEK_HEADER property to show the week
        > number, which is great.
        >
        > However, it uses Jan 1 as week number 1.
        >
        > I need to use a financial year (March 1) for our customer. Is there a
        > way to configure what the start week for week number should be?
        >
        > I was thinking of somehow using the DateMath's getWeekNumber() method
        > to get week number, offsetting for March 1 (based on Jan 1 = week 1)
        > and update the value somehow, but that feels like more work than
        > necessary. [If I had to do this, what event would I attach to do this?]
        >
        > Is there a config setting I am missing to indicate what week should be
        > the first week number?
        >
        > Many thanks!
        > Anup
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.