The problem

The date: variable in HUGO needs to be actual, not in the past, for the post to register. I don’t know yet why but that isn’t important, only the solution is so…

The correct post date format in YAML is:

date: 2025-04-01T19:37:18+02:00

The last part of the string +02:00 indicates UTC1 plus 2 hours, which for my current location is CET +1 2.

The first solution

After a little searching, for the wrong thing (UTC offsets) I came across the Python class: time and the functiontime.daylight specifically. This boolean function returns True if it is Summer Time and False if it is Winter Time, which allows to check the state in an if statement, thus:

  import time
  
  if time.daylight:
    output_date = datetime.now().strftime("%Y-%m-%dT%H:%M:%S+02:00") # Summer
  else:
    output_date = datetime.now().strftime("%Y-%m-%dT%H:%M:%S+01:00") # Winter

This works perfectly well and is fairly efficient if a little verbose, and so I thought maybe I can make it shorter perhaps one line.

The second solution

Given that the return value of the function call is a Boolean i.e. 0 or 1, I did a little string theory magic I came up with the following one liner:

datetime.now().strftime("%Y-%m-%dT%H:%M:%S+0" + str(time.daylight+1) +":00")

This is a nice clean solution, although I will have to wait until October to know if it works for sure 😉

Comments are turned off on this site, if you wish to say something you are invited to do so via Mastodon


  1. Coordinated Universal Time ↩︎

  2. Central European Time ↩︎