So if I have something like this, it outputs 01:56AM PST
{{ .Lastmod.Format "Jan 02, 2006 at 03:04PM MST" }}
What would be a efficient method to convert AM / PM to a.m. / p.m. like Associated Press style formats require? Been struggling to wrap my head around the best way to do this in a Hugo template.
Does the AP requires dots in the a.m./p.m.? I am afraid you can do that only with some helpers like replace. The time formatting package only allows for a large AM, that you could replace or lowercase in a piped command (like .Lastmod.Format "formatstring" | lower. Golang is a bit inflexible with date formatting.
With some languages, if your format string includes the full month or full day, the code above will produce undesirable results because the full month or full day may include the string “am”. For example, “January” in Finnish is “tammikuu”. You can handle this with a more precise regex value (the first arg to strings.ReplaceRE).
replaceRE looks to be what I was trying to find! Thanks for the suggestion.
Since I’m doing this on a .LastMod, I assume to work around that I could just call the Date and Time separately? Not being a web developer, and just knowing enough about code/ssg’s to be dangerous, the Regex solution would be the correct path, but I’d have to learn how to do that.
But something like {{ .Lastmod.Format "January 02, 2006"}} at {{ .Lastmod.Format "3:04 pm" | replaceRE "am" "a.m." | replaceRE "pm" "p.m." }} should work.
And for Month formatting, AP Style requires some months be abbreviated and some not. Maybe down the road I’ll get under the hood and figure out a more elegant solution, but for now, I could just use replaceRE for the months that need to be abbreviated. "January" "Jan." or is there a far better way to do something like this?