very nice. thank you very much. ----- Original Message ----- From: "Merrill, Jason" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Thursday, April 27, 2006 4:27 PM
Subject: RE: [Flashcoders] calculating dates based on a starting date.


Here is a SuperDate class I wrote if it's of use to you.  You can get a
future date and also get the elapsed number of days since a date, get
the ordinal date etc.
/*
Name: SuperDate Class
Author: Jason Merrill
Date: 1/10/2006

Description:  Some methods to help with date class needs - still
a work in progress.  See descriptions beside each method.

Usage Example: var thisMonthAbreviated:String =
SuperDate.getMonthName(myMonthNumber, true);
*/

class com.icfconsulting.utils.SuperDate extends Date{

function SuperDate(){
};

public static function getMonthName(mo:Number,
abreviated:Boolean):String{//returns the name of the month in full or
abbreviated.
var months:Array = new Array("January", "February",
"March", "April", "May", "June", "July", "August", "September",
"October", "November", "December");
var monthsAbreviated:Array = new Array("Jan", "Feb",
"Mar", "Apr," ,"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var month:String;
if(abreviated){
month = monthsAbreviated[mo];
}else{
month = months[mo];
}
return month;
};

public static function getOrdinalDate(num:Number):String{//adds
the ordinal to the date - i.e. 15th, 21st, 2nd, 3rd. etc.
var ordinal:String;
if(num ==1 || num == 21 || num == 31){
ordinal = "st";
}else if (num == 2 || num == 22 ){
ordinal = "nd"; }else if (num == 3 || num == 23){
ordinal = "rd"
}else{
ordinal = "th"; }
return num+ordinal;
};

public static function formatDate(date:Date):String{//formats
the date object into somehting readable.
var thisMonth:Number = date.getMonth()+1;
var thisDay:Number = date.getDate();
var thisYear:Object = date.getUTCFullYear()-2000;
if(thisYear <10){
thisYear = "0"+String(thisYear);
};
var thisDate:String =
thisMonth+"/"+thisDay+"/"+thisYear;
return thisDate;
};

public static function getElapsedDays(earlierDay:Date,
laterDay:Date):Number{//calculated the number of days elapsed since the
input date.
var dms:Number = laterDay-earlierDay; // difference in
milliseconds
dms = Math.floor(dms/1000/60/60/24); // difference in
days
return dms;
};

public static  function returnDate(initDate:Date,
daysToAdd:Number):Date{//calculates a date in the future based on an
initial date.
var newDate:Date = new Date(initDate.getTime());
var newDateNum:Number =
newDate.setDate(newDate.getDate() + daysToAdd);
return new Date(newDateNum);
};

}



Jason Merrill   |   E-Learning Solutions   |  ICF International







_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to