Flex: 获得给定日期在其月份内为第几个day of week

Categories: Flex; Tagged with: ; @ June 28th, 2009 18:10
/*

 * All Rights Reserved
 * Changelog:
 * Li Guoliang - 2009-6-5: Initial version
 * @liguoliang.com
 */

  	/** 
  	 * 获得给定日期的是该月的第几个day of week. 如2009.6.28日, 为2009.06月的第四个周日, 则返回4.
  	 * @param date_  要计算周数的日期
	 * @return int 所在月的第几个周几.
	 */ 
	public static function getWeekOfMonth(date_:Date):int {
		var date:Date = new Date(date_.time);
		var month:int = date.month;
		var weekOfMonth:int = 0;

		while(true) {
			date.date -= 7;
			weekOfMonth ++;
			if(date.month != month) {
				break;
			}
		}
		
		return weekOfMonth;
	} 
	
	  /** 
  	 * 获得给定日期的是该月的倒数第几个day of week. 如2009.6.28日, 为2009.06月的倒数第一个[最后一个]周日, 则返回1.
  	 * @param date_  要计算周数的日期
	 * @return int 所在月的倒数第几个周day of week.
	 */ 
	public static function getWeekOfMonthFromLast(date_:Date):int {
		var date:Date = new Date(date_.time);
		var month:int = date.month;

		var weekOfMonthFromLat:int = 0;

		while(true) {
			date.date += 7;
			weekOfMonthFromLat ++;
			if(date.month != month) {
            	break;
			}
		}
		
		return weekOfMonthFromLat;
	}



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.