Add %s format specifier for strftime (#1335)

This commit is contained in:
John Kerl 2023-07-04 17:00:02 -04:00 committed by GitHub
parent 3baebea7a3
commit b30aceae36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 23 additions and 15 deletions

View file

@ -3434,5 +3434,5 @@ MILLER(1) MILLER(1)
2023-07-02 MILLER(1)
2023-07-04 MILLER(1)
</pre>

View file

@ -3413,4 +3413,4 @@ MILLER(1) MILLER(1)
2023-07-02 MILLER(1)
2023-07-04 MILLER(1)

View file

@ -246,7 +246,7 @@ Notes:
* For `strftime`, this is thanks to [https://github.com/lestrrat-go/strftime](https://github.com/lestrrat-go/strftime), with a Miller-specific modification for fractional seconds.
* For `strftime`, this is thanks to [https://github.com/pbnjay/strptime](https://github.com/pbnjay/strptime), with Miller-specific modifications.
Available format strings for `strftime`, taken directly from [https://github.com/lestrrat-go/strftime](https://github.com/lestrrat-go/strftime) except for `%1..%9`, `%N`, and `%O` which are Miller-specific additions:
Available format strings for `strftime`, taken directly from [https://github.com/lestrrat-go/strftime](https://github.com/lestrrat-go/strftime) except for `%1..%9`, `%s`, `%N`, and `%O` which are Miller-specific additions:
| Pattern | Description |
|---------|-------------|
@ -274,6 +274,7 @@ Available format strings for `strftime`, taken directly from [https://github.com
| `%p` | national representation of either "ante meridiem" (a.m.) or "post meridiem" (p.m.) as appropriate. |
| `%R` | equivalent to `%H:%M` |
| `%r` | equivalent to `%I:%M:%S %p` |
| `%s` | integer seconds since the epoch |
| `%S` | the second as a decimal number (00-60) |
| `%1S`, ..., `%9S` | the second as a decimal number (00-60) with 1..9 decimal places, respectively |
| `%T` | equivalent to `%H:%M:%S` |

View file

@ -178,7 +178,7 @@ Notes:
* For `strftime`, this is thanks to [https://github.com/lestrrat-go/strftime](https://github.com/lestrrat-go/strftime), with a Miller-specific modification for fractional seconds.
* For `strftime`, this is thanks to [https://github.com/pbnjay/strptime](https://github.com/pbnjay/strptime), with Miller-specific modifications.
Available format strings for `strftime`, taken directly from [https://github.com/lestrrat-go/strftime](https://github.com/lestrrat-go/strftime) except for `%1..%9`, `%N`, and `%O` which are Miller-specific additions:
Available format strings for `strftime`, taken directly from [https://github.com/lestrrat-go/strftime](https://github.com/lestrrat-go/strftime) except for `%1..%9`, `%s`, `%N`, and `%O` which are Miller-specific additions:
| Pattern | Description |
|---------|-------------|
@ -206,6 +206,7 @@ Available format strings for `strftime`, taken directly from [https://github.com
| `%p` | national representation of either "ante meridiem" (a.m.) or "post meridiem" (p.m.) as appropriate. |
| `%R` | equivalent to `%H:%M` |
| `%r` | equivalent to `%I:%M:%S %p` |
| `%s` | integer seconds since the epoch |
| `%S` | the second as a decimal number (00-60) |
| `%1S`, ..., `%9S` | the second as a decimal number (00-60) with 1..9 decimal places, respectively |
| `%T` | equivalent to `%H:%M:%S` |

View file

@ -437,6 +437,11 @@ func init() {
//return append(b, []byte(s))
return append(b, s...)
})
appenderS := strftime.AppendFunc(func(b []byte, t time.Time) []byte {
epochSeconds := t.Unix()
s := fmt.Sprintf("%d", epochSeconds)
return append(b, s...)
})
ss := strftime.NewSpecificationSet()
ss.Set('1', appender1)
@ -450,6 +455,7 @@ func init() {
ss.Set('9', appender9)
ss.Set('N', appenderN)
ss.Set('O', appenderO)
ss.Set('s', appenderS)
strftimeExtensions = strftime.WithSpecificationSet(ss)
}

View file

@ -3413,4 +3413,4 @@ MILLER(1) MILLER(1)
2023-07-02 MILLER(1)
2023-07-04 MILLER(1)

View file

@ -2,12 +2,12 @@
.\" Title: mlr
.\" Author: [see the "AUTHOR" section]
.\" Generator: ./mkman.rb
.\" Date: 2023-07-02
.\" Date: 2023-07-04
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "MILLER" "1" "2023-07-02" "\ \&" "\ \&"
.TH "MILLER" "1" "2023-07-04" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Portability definitions
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -10,5 +10,5 @@ TZ is Asia/Istanbul
1970-01-01 00:00:00 +0000
1970-01-01 00:00:00 UTC
1970-01-01 00:00:00 +0000
00 000123456
0 000123456
00 123456

View file

@ -10,5 +10,5 @@ TZ is America/Sao_Paulo
1970-01-01 00:00:00 +0000
1970-01-01 00:00:00 UTC
1970-01-01 00:00:00 +0000
00 000123456
0 000123456
00 123456

View file

@ -10,5 +10,5 @@ TZ is UTC
1970-01-01 00:00:00 +0000
1970-01-01 00:00:00 UTC
1970-01-01 00:00:00 +0000
00 000123456
0 000123456
00 123456

View file

@ -10,5 +10,5 @@ TZ is Asia/Istanbul
1970-01-01 00:00:00 +0000
1970-01-01 00:00:00 UTC
1970-01-01 00:00:00 +0000
00 123456000
0 123456000
00 123456000

View file

@ -10,5 +10,5 @@ TZ is America/Sao_Paulo
1970-01-01 00:00:00 +0000
1970-01-01 00:00:00 UTC
1970-01-01 00:00:00 +0000
00 123456000
0 123456000
00 123456000

View file

@ -10,5 +10,5 @@ TZ is UTC
1970-01-01 00:00:00 +0000
1970-01-01 00:00:00 UTC
1970-01-01 00:00:00 +0000
00 123456000
0 123456000
00 123456000

View file

@ -13,7 +13,7 @@ end {
print strfntime(123456, "%Y-%m-%d %H:%M:%S %z");
print strfntime(0, "%Y-%m-%d %H:%M:%S %Z");
print strfntime(0, "%Y-%m-%d %H:%M:%S %z");
print strfntime(123456, "%S %N");
print strfntime(123456, "%s %N");
print strfntime(123456, "%S %O");
}

View file

@ -13,7 +13,7 @@ end {
print strftime(0.123456, "%Y-%m-%d %H:%M:%S %z");
print strftime(0.0, "%Y-%m-%d %H:%M:%S %Z");
print strftime(0.0, "%Y-%m-%d %H:%M:%S %z");
print strftime(0.123456, "%S %N");
print strftime(0.123456, "%s %N");
print strftime(0.123456, "%S %O");
}