Currently Reading

Image of Derivatives Demystified: A Step-by-Step Guide to Forwards, Futures, Swaps and Options (The Wiley Finance Series)

Image of Working Effectively with Legacy Code (Robert C Martin)

Image of Coders at Work: Reflections on the Craft of Programming

Image of Succeeding with Agile: Software Development Using Scrum (Addison-Wesley Signature)

Recently Read

Image of Advanced Actionscript 3 with Design Patterns

Image of Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin)

Image of Cloud Atlas

Image of Beginning iPhone 3 Development: Exploring the iPhone SDK

Image of Refactoring: Improving the Design of Existing Code (Object Technology Series)

Image of The Secrets of Consulting: A Guide to Giving and Getting Advice Successfully

Image of Test Driven Development (The Addison-Wesley Signature Series)

Image of Test Driven: TDD and Acceptance TDD for Java Developers

Image of UML 2 for Dummies

Image of ActionScript 3.0 Design Patterns: Object Oriented Programming Techniques (Adobe Developer Library)


January 5, 2009

Time Calculator

Filed under: ActionScript, Flex — Anthony @ 11:19 pm

I recently found a post about someone needing a good time calculator and seeing as I had recently written one for the redbullracing website I figured I should improve it and release it here.

Features

  • Calculates time bi-directionally ie: if the date is in the past it will tell you the time since it elapsed or if it is in the future it will tell you the time left until it elapses.
  • Optionally set a expiration string to be returned when the date has been reached.
  • Fires a TimeCalculator.TIME_EXPIRED event when the time expires.
  • Set the precision level of the return values. ( YEARS, MONTHS, DAYS, WEEKS, HOURS, MINUTES, SECONDS, MILLISECONDS ). This allows you to return values for example where the date is 1 year 2 months in the future but you don't care about the years you just want the number of months, days, hours, minutes, seconds, milliseconds till that date. ie 13 months, 30days, 23hours, 59minutes, etc...
  • Individual time accessors ie get Years( ); Months( ); Days( ); etc... until the due date.
  • Set labels and separators to be returned with the time strings labels( 'years', 'months' ). 01years : 01months.
  • Optionally set removeEmptyTImes = false; This will display values that have no time associated with them. For example for a date 2 months in the future with a precision set to YEARS, the default return value from _timeCalculator.calculateTime( ); would be 01 : 30 :  23 : 59 : 59 : 999 with the years not being returned and the date starting at the months. However if you set removeEmptyTimes = false the return date would be 00 : 01 : 30 :  23 : 59 : 59 : 999 showing the years as 00 values.
  • Turn off individual time ammounts so if you wanted just the years, months and days for a given date you can set showHours = false; This will cut the date at the Days and only return YEARS : MONTHS : DAYS.

As usual you can right click to view the source.. Any comments suggestions or errors please leave a comment.

No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .