lestrrat-go / strftime

Fast strftime for Go
MIT License
117 stars 22 forks source link

Support `%s` pattern representing the Unix timestamp #15

Closed JamesJJ closed 4 years ago

JamesJJ commented 4 years ago

Please could you consider this PR for a default implementation to produce a Unix timestamp?

%s is a standard pattern for a Unix timestamp, e.g in the ubiquitous date CLI command :

$ date '+%s'
1589032633

Why not just use Time.Unix in golang's standard library?

==> Use of Time.Unix requires compile-time awareness of the time string format, or separate templating. I feel it's important to conveniently support a strftime pattern for Unix timestamp representation to cover cases where the pattern is only known at runtime e.g specified in an application's configuration file.

lestrrat commented 4 years ago

Thanks for the PR! LGTM

On a side note: upon checking Linux man pages, looks like it exists in the specification ... I wonder where I took the original set of specs from.

But yeah, at this point in time, an extension seems safer. We can consider adding %s to the standard set in a future version