Session Ready
Exercise

Timezones

In order to work effectively with other timezones, you can use the pytz library. To use timezones, you need to import the timezone object from the pytz module. Then you can use the timezone constructor and pass it a name of a timezone, such as CT = timezone('US/Central'). You can get a full list of timezone names at Wikipedia. In Python 3, you can make a datetime object "aware" by passing a timezone as the tzinfo keyword argument to the .replace() method on a datetime instance.

An "aware" datetime object has an .astimezone() method that accepts a timezone object and returns a new datetime object in the desired timezone. If the tzinfo is not set for the datetime object it assumes the timezone of the computer you are working on.

A list, daily_summaries, has been supplied for you it contains the datetime and rail ridership for trains going to New York. You need to determine the time in New York so you can align it with the New York Transit Authority data.

Instructions
100 XP
  • Create a Timezone object for Chicago ('US/Central') called chicago_usa_tz.
  • Create a Timezone object for New York ('US/Eastern') called ny_usa_tz.
  • Iterate over the daily_summaries, unpacking it into the variables orig_dt and ridership.
    • Make the orig_dt timezone "aware" for Chicago, using chicago_usa_tz. Store the result in chicago_dt.
    • Convert chicago_dt to the New York timezone, ny_dt.
    • Print the chicago_dt, ny_dt, and ridership.