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 Dates and Times in Python Where on Earth do Timezones Make Sense? Timezone Strings

The Task is vague, and I'm not sure how my function takes in a timezone as a string

In creating my function, I created it to take in a string for the timezone, but there is nothing in the script that I can relay it back to. More than anything, I'm confused how to structure this code to fulfill the challenges parameters.

import datetime

import pytz

starter = pytz.utc.localize(datetime.datetime(2015, 10, 21, 23, 29))
name = "US/Pacific"

def to_timezone(name, local):
    tmzn = pytz.timezone(name)
    return local.astimezone(tmzn)

to_timezone(name, starter)

1 Answer

8,568 Points

Chase Saldate, listen brother, you're overthinking it, All you need is a single 4-inch line of code, that's it. Lemme give you some hints.

1) You don't need to write any code out of the function.

2) In the challenge notes, it says that the function to_timezone will take a timezone name as a string, which means that the function to_timezone will have ONE argument parameter and the user calling the function will give a timezone name as a string for example "US/Pacific" or "Asia/Calcutta" will be the string parameter.

3) So all you have to do is convert the starter date-time variable, provided, into the timezone of the string parameter.

If you're having trouble just msg me and I will help you an infinite amount of time no problem for me (Just make sure you send me 5$)

Hahaha I appreciate the banter! And thank you for the help! I think I needed to sleep on it, but your guidance turned a needless 20min frustration into a minute relief.