There was a suggestion in the comments that the code excerpt I showcased in my previous post was not shit at all, but rather just the way you do things in a functional programming language. By way of illustrating why it actually is shit, I present the following code that does exactly the same thing, using the same methodology:
less_shit(GregSecs) ->
Date=calendar:gregorian_seconds_to_datetime(GregSecs),
{{Y, Mo, D},{H, Mi, S}} = Date,
[UDate|_] = calendar:local_time_to_universal_time_dst(Date),
{DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ tzid(DiffD,DiffH,DiffMi).
tzid(DiffD,DiffH,DiffMi) when DiffH < 12, DiffH /= 0 ->
"+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12, DiffD == 0 ->
"+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12, DiffD /= 0, DiffMi /= 0 ->
"-" ++ add_zero(23-DiffH) ++ ":" ++ add_zero(60-DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12, DiffD /= 0, DiffMi == 0 ->
"-" ++ add_zero(24-DiffH) ++ ":" ++ add_zero(60-DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH == 0 -> "Z".
The point to note is that no complex expression is repeated multiple times, and nor is the actual logic of generating the timezone identifier buried within one. It’s much clearer, and much shorter.
Another point to note is that it is still shit, and I make no apologies for that, as firstly I wanted to keep the methodology the same, and secondly I am still getting to grips with Erlang.