This is a great exercise in using cgo, however strftime is certainly not missing, nor should you need to use cgo to do something as trivial as printing formatted time.
Running the following very simple code shows precicely why.
I happen to find the time package much easier and intuitive to use than having to remember cryptic printing macros. I understand if you come from C if the loss of muscle memory might be annoying, but this is a bad solution in my opinion, not just for readability:
cgo, and anything relying on C will not always be available in docker containers. trying to run this in an alpine container for example will end in utter failure, whereas the time package will suffer no such issues.
This means that this solution is not portable, and very much reliant and the platform, which in my opinion makes it unfit for purpose.
packagemainimport("fmt""time")funcmain(){t:=time.Date(2018,1,1,0,0,0,0,time.UTC)fmt.Println(t.Weekday(),// full dayt.Weekday().String()[0:3],// abbreviatedint(t.Weekday()),// as integer 0 thru 6t.Minute(),// from 0 thru 59fmt.Sprintf("%02d",t.Minute()),// paddedt.Month(),// montht.Month().String()[0:3],// month abbrev.t.Location(),// time zone namet.Format("-0700"),// offset)}// prints: Monday, Mon, 1, 0, 00, January, Jan, UTC, +0000
This is a great exercise in using cgo, however
strftime
is certainly not missing, nor should you need to usecgo
to do something as trivial as printing formatted time.Running the following very simple code shows precicely why.
I happen to find the time package much easier and intuitive to use than having to remember cryptic printing macros. I understand if you come from
C
if the loss of muscle memory might be annoying, but this is a bad solution in my opinion, not just for readability:cgo, and anything relying on C will not always be available in docker containers. trying to run this in an alpine container for example will end in utter failure, whereas the time package will suffer no such issues.
This means that this solution is not portable, and very much reliant and the platform, which in my opinion makes it unfit for purpose.
yeah, it was just an idea and a weekend project ;D
I just realised I come across a little abrasive here:
It's great that you built this, and it surely could be useful in a cgo heavy code base!
the
time
package is one of my favourite from the standard library, precicely because I don't have to remember printing macros for everything.Some folks are a little put-off by the formatting, but I think it's amazing!
There's a little trick to remembering it by the way: