Alexandre Martins On Agile Software Development

25Jan/070

[WTF] Eureka!

If you think you know how to work out the age of a person, based on his date of birth, it'd be better to review your concepts about implementing this functionality. Enjoy the code!!

    public UserImpl( UserTO user, String status ) {
        _user = user;
        _status = status;

        _age = 0;
        Calendar today = Calendar.getInstance();
        Calendar birthdate = Calendar.getInstance();
        birthdate.setTimeInMillis( getBirthdate().getTime() );
        birthdate.roll( Calendar.YEAR, 1 );
        while ( today.after( birthdate ) ) {
            birthdate.roll( Calendar.YEAR, 1 );
            _age++;
        }
    }
Share and Enjoy:
  • Digg
  • del.icio.us
  • Reddit
  • Twitter
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


Comment moderation is enabled. Your comment may take some time to appear.

No trackbacks yet.