A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: ISO-8601 Week Number from Date()

Hybrid View

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    10

    Thumbs up another way :

    another way :

    Code:
    public function WeekNumber(adate:Date):int{
    				//
    				// 1 - CALC JULIAN DATE NUMBER (note: nothing to do with the Julian calendar)
    				//
    				var wfullyear:int = adate.getFullYear();
    				var wmonth:int = adate.getMonth() + 1;
    				var wdate:int = adate.getDate();
    				//
    				var wa:int = Math.floor((14 - wmonth) / 12);
    				var wy:int = wfullyear + 4800 - wa;
    				var wm:int = wmonth + 12 * wa - 3;
    				//
    				// wJDN is the Julian Day Number
    				//
    				var wJDN:int = wdate + Math.floor(((153 * wm) + 2) / 5) + wy * 365
    				                     + Math.floor(wy / 4)
    				                     - Math.floor(wy / 100)
    				                     + Math.floor(wy / 400) - 32045;
    				//
    				// 2 - CALC WEEK NB
    				//
    				var d4:int = (((wJDN + 31741 - (wJDN % 7)) % 146097) % 36524) % 1461;
    				var L:int = Math.floor(d4 / 1460);
    				var d1:int = ((d4 - L) % 365) + L;
    				var wweekNb:int = Math.floor(d1 / 7) + 1;
    				return wweekNb;
    			};

  2. #2
    Quote Originally Posted by Michael REMY View Post
    another way :

    Code:
    public function WeekNumber(adate:Date):int{
    				//
    				// 1 - CALC JULIAN DATE NUMBER (note: nothing to do with the Julian calendar)
    				//
    				var wfullyear:int = adate.getFullYear();
    				var wmonth:int = adate.getMonth() + 1;
    				var wdate:int = adate.getDate();
    				//
    				var wa:int = Math.floor((14 - wmonth) / 12);
    				var wy:int = wfullyear + 4800 - wa;
    				var wm:int = wmonth + 12 * wa - 3;
    				//
    				// wJDN is the Julian Day Number
    				//
    				var wJDN:int = wdate + Math.floor(((153 * wm) + 2) / 5) + wy * 365
    				                     + Math.floor(wy / 4)
    				                     - Math.floor(wy / 100)
    				                     + Math.floor(wy / 400) - 32045;
    				//
    				// 2 - CALC WEEK NB
    				//
    				var d4:int = (((wJDN + 31741 - (wJDN % 7)) % 146097) % 36524) % 1461;
    				var L:int = Math.floor(d4 / 1460);
    				var d1:int = ((d4 - L) % 365) + L;
    				var wweekNb:int = Math.floor(d1 / 7) + 1;
    				return wweekNb;
    			};
    very useful! thanks...

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center