Utility functions to find First Day of a month, Relative Date information like “Today”, “Yesterday”
public static function getFirstDayofMonth(fullyear:uint,month:uint):uint
{
var tmp:Date = new Date(fullyear,month,1);
return tmp.getDay();
}
public static function isLeapYear( fullyear:uint ):Boolean
{
var flag:Boolean = false;
if(((fullyear%4==0) && (fullyear%100!=0)) || (fullyear%400==0)) flag = true;
return flag;
}
public static function getWeekName( index:uint , type:uint=0 ):String
{
var week:Array;
if(type==0) week = [“SUNDAY”,”MONDAY”,”TUSEDAY”,”WEDNESDAY”,”THURSDAY”,”FRIDAY”,”SATURDAY”];
else if(type==1) week = [“SUN”,”MON”,”TUE”,”WED”,”THU”,”FRI”,”SAT”];
else week = [“Sun”,”Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”];
return week[index];
}
public static function getMonthName( index:uint , type:uint=0 ):String
{
var month:Array;
if(type==0) month = [“JANUARY”,”FEBRUARY”,”MARCH”,”APRIL”,”MAY”,”JUNE”,”JULY”,”AUGUST”,”SEPTEMBER”,”OCTOBER”,”NOVEMBER”,”DECEMBER”];
else if(type==1) month = [“jan”,”feb”,”mar”,”apr”,”may”,”jun”,”jul”,”aug”,”sep”,”oct”,”nov”,”dec”];
else month = [“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”];
return month[index];
}
public static function getRelativeDateName( date:Date, type:uint=0 ):String
{
var d1:Date = new Date();
d1 = new Date(d1.getFullYear(),d1.getMonth(),d1.getDate());
var d2:Date = new Date(date.getFullYear(),date.getMonth(),date.getDate());
if(d11000*60*60*24*7) return “”;
if(type>8||isNaN(type)) type = 0;
var list:Array;
switch(type) {
case 0: case 3:
list = [“TODAY”,”YESTERDAY”]; break;
case 1: case 4:
list = [“Today”,”Yesterday”]; break;
case 2: case 5:
list = [“today”,”yesterday”]; break;
}
var diff:int = d1.getDate()-d2.getDate();
if(diff<=1) return list[diff];
return getWeekName( d2.getDay(), type );
}