gopher-lua icon indicating copy to clipboard operation
gopher-lua copied to clipboard

Improve `os.date` / `strftime`

Open bvisness opened this issue 2 years ago • 1 comments

The implementation of os.date didn't support many flags that I was used to from other systems. This new implementation supports many more of the flags from the C standard for strftime, plus some utilities borrowed from other strftime implementations such as glibc and Ruby.

The overall changes are:

  • Added the following flags unchanged from the C spec: %n, %t, %j, %e, %D, %r, %R, %T, %G, %g, %V
  • %x was just wrong; it formatted a time as if it was a date. It has now been defined to be the same as %D.
  • Added:
    • %-m: trimmed month
    • %-d: trimmed day of month

I see that this flag-scanning code is also used by strGsubStr. Please do let me know if my changes are unacceptable because of that!

bvisness avatar Dec 10 '23 21:12 bvisness

Would like to know when this will get merged. My Lua code uses os.date but %a is not formatted correctly in the current gopher-lua codebase and will always result in "mon" instead "Mon" or any other correct day for that matter. I was going to submit a fix for that bug myself, but then this PR came along and now I am just waiting for it to get merged.

LittleToonCat avatar Feb 27 '24 00:02 LittleToonCat