Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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)) hill_valley.astimezone(paris)
Ryan S27,275 Points
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
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.