TimeDelta class in ActionScript?
Is there any ActionScript class that represents "time durations" similar to Python's TimeDelta class?
Edit : Thanks for the answers. I should clarify though: I want to be able to ask questions such as "how many weeks are between date and date1" or "let it x
represent" one day. "What is date2 + x
?"
I know I can do all this by representing dates as timestamps ... But I hope to find something nicer.
a source to share
I've posted a complete AS3 port of the .NET TimeSpan class on this question , which sounds exactly like what you want.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
a source to share
I don't think there is a class that measures changes over time in ActionScript 3. According to this ActionScript Adventures blog post , timing is very inaccurate in the Flash player on the web. This post is quite informative and has a SuperTimer class that can help you. You might want to account for this inaccuracy if you use solutions created by Justin Nissner and Tosti.
a source to share