Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) Where on Earth do Timezones Make Sense? Datetime Awareness

Python Datetime Awareness Challenge

I've read through the question and answers that are on the forum for this and I've tried whats there and I've tried what I have here and they both say Task 1 is no longer passing.

Im not sure what Im doing wrong.

import datetime

naive = datetime.datetime(2015, 10, 21, 4, 29)
pacific = datetime.timezone(datetime.timedelta(hours=-8))
hill_valley = datetime.datetime(2017, 1, 10, 10, 44, tzinfo=pacific)
paris = datetime.timezone(datetime.timedelta(hour=1))

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Jeremy,

There are a couple issues with your code.

In task 1 you were asked to use the replace method in order to make an aware datetime object out of the "naive" variable. Instead, you created a datetime object with an arbitrary value of your own choosing. Notice the wording of the challenge and how they differentiate certain keywords using markdown. This is a good indication that you will need to do something with those.

"Then make a new variable named hill_valley that is naive with its tzinfo attribute replaced with the US/Pacific timezone you made."

It passed task 1 because I'm guessing that the code checker was only looking for the timezone that was associated with "hill_valley", not the actual date and time. But in task 2, the date and time will be checked so your arbitrary values will cause problems. It is important to not create your own variables that the challenge doesn't ask for.

Your "pacific" variable is correct, but "hill_valley" should be the following:

hill_valley = naive.replace(tzinfo=pacific)

In task 2, "paris" is not supposed to be the new timezone. You are to "Make a new timezone that is UTC+01:00." You can name this whatever you want.

new_timezone = datetime.timezone(datetime.timedelta(hours=1))

Next, "create a new variable named paris that uses your new timezone and the astimezone method to change hill_valley to the new timezone.

paris = hill_valley.astimezone(new_timezone)

You can do task 2 in one line without the intermediary "new_timezone" variable, but I've separated it for clarity.