# MyAge.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2009-01-23 File created. # 2022-12-28 Converted to Python 3. # Solutions to exercises with the ISODate class from ISODate import ISODate from ISODate import DateDistance class AnotherDate( ISODate ) : def to_anti_iso_format( self ) : day_as_string = "%02d" % self.this_day month_as_string = "%02d" % self.this_month year_as_string = "%04d" % self.this_year string_to_caller = day_as_string + "." + month_as_string \ + "." + year_as_string return string_to_caller my_birthday = ISODate( 1977, 7, 14 ) date_now = ISODate() print( "\n I was born on %s" \ "\n That was a %s" % ( my_birthday, my_birthday.get_day_of_week() ) ) distance_between = my_birthday.get_distance_to( date_now ) print( "\n I am now %d years, %d months, and %d days old." \ % ( distance_between.years, distance_between.months, distance_between.days ) ) print( "\n Here are my dates to celebrate. I am" ) years_to_celebrate = 10 while years_to_celebrate < 80 : date_to_celebrate = ISODate( my_birthday.year() + years_to_celebrate, my_birthday.month(), my_birthday.day() ) print( "\n %d years old on %s (%s)" % ( years_to_celebrate, date_to_celebrate, date_to_celebrate.get_day_of_week() ), end="" ) years_to_celebrate = years_to_celebrate + 10 # The following two lines test the new class. test_date = AnotherDate( date_now ) print( "\n\n Current date in anti-ISO format: " + test_date.to_anti_iso_format() ) day_counter = 0 date_to_increment = ISODate( my_birthday ) while day_counter < 30001 : day_counter += 1 date_to_increment.increment() if ( day_counter % 10000 ) == 0 : print( "\n %d days old on %s." % ( day_counter, date_to_increment ), end="" ) age_in_seconds = 0 date_to_increment = ISODate( my_birthday ) while age_in_seconds < 1000000000 : age_in_seconds += 24*60*60 date_to_increment.increment() print( "\n\n 1000000000 seconds old on %s." % ( date_to_increment ), end="" ) distance_between = my_birthday.get_distance_to( date_to_increment ) print( "\n I am then %d years, %d months, and %d days old." \ % ( distance_between.years, distance_between.months, distance_between.days ) )