11 Comments
author

The one hour difference shouldn’t be linked to the f-string though. It could be earlier in your code?

Expand full comment
author

Hi Rolf, this is a great note. I wrote this code for my personal use and it works but I use a non-standard format specifier which I believe doesn’t work on Windows. I assume you’re on Windows?

My version gives the hour without a leading zero but with a space. Normally I’d avoid these variations in my tutorials, but this wasn’t intended as a tutorial so I forgot!

Expand full comment
author

Hi Rolf, this is a great note. I write this code for my personal use and it works but I use a non-standard format specifier which I believe doesn’t work on Windows. I assume you’re on Windows?

My version gives the hour without a leading zero but with a space. Normally I’d avoid these variations in my tutorials, but this wasn’t intended as a tutorial so I forgot!

Expand full comment

Hi Stephen,

the code in this form results in an error: ValueError: Invalid format string. As a beginner in Python I asked chatGPT whats wrong. The issue with the provided Python f-string seems to be related to the formatting of tz_time. The syntax %l is not a valid strftime directive for Python's datetime formatting.

If you intend to format tz_time as the hour in 12-hour clock format without leading zero, you should use %I instead of %l. Here's the corrected version of your f-string:

f"{tz_time:%I:%M %p} {tz.key.split('/')[1].replace('_', ' ')}{day_difference}"

This will format tz_time as the hour in 12-hour clock format with leading zero if necessary, followed by minutes, and the period (AM or PM). The rest of the f-string remains unchanged.

This works (with the second occurence correctet too) but the results differ one hour.

# 05:00 PM London

# 12:00 PM New York

# 09:00 AM Los Angeles

# 06:00 PM Berlin

# 04:00 AM Sydney (+1d)

# 10:30 PM Kolkata

# 05:00 PM UTC/GMT

So when should we listen to your broadcast?

Kind regards

Rolf

Expand full comment