You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds explicit sections to describe the meaning of the various
`layout_types` along with a table showing the available `strptime` and
`gotime` directives.
Copy file name to clipboardExpand all lines: pkg/stanza/docs/types/timestamp.md
+65-21Lines changed: 65 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,71 @@ If a timestamp block is specified, the parser operator will perform the timestam
13
13
|`layout`| required | The exact layout of the timestamp to be parsed. |
14
14
|`location`|`Local`| The geographic location (timezone) to use when parsing a timestamp that does not include a timezone. The available locations depend on the local IANA Time Zone database. [This page](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) contains many examples, such as `America/New_York`. |
15
15
16
+
## Layout Types
17
+
18
+
### `strptime` and `gotime`
19
+
20
+
The `strptime` layout type approximates familiar strptime/strftime formats. See the table below for a list of supported directives.
21
+
22
+
The `gotime` layout type uses Golang's native time parsing capabilities. Golang takes an [unconventional approach](https://www.pauladamsmith.com/blog/2011/05/go_time.html) to time parsing. Finer details are documented [here](https://golang.org/src/time/format.go?s=25102:25148#L9).
|`%S`|`05`| Second as a zero-padded decimal number (00, 01, ..., 59) |
45
+
|`%L`|`999`| Millisecond as a decimal number, zero-padded on the left (000, 001, ..., 999) |
46
+
|`%f`|`999999`| Microsecond as a decimal number, zero-padded on the left (000000, ..., 999999) |
47
+
|`%s`|`99999999`| Nanosecond as a decimal number, zero-padded on the left (000000, ..., 999999) |
48
+
|`%Z`|`MST`| Timezone name or abbreviation or empty (UTC, EST, CST) |
49
+
|`%z`|`Z0700`| UTC offset in the form ±HHMM[SS[.ffffff]] or empty(+0000, -0400) |
50
+
|`%i`|`-07`| UTC offset in the form ±HH or empty(+00, -04) |
51
+
|`%j`|`-07:00`| UTC offset in the form ±HH:MM or empty(+00:00, -04:00) |
52
+
|`%k`|`-07:00:00`| UTC offset in the form ±HH:MM:SS or empty(+00:00:00, -04:00:00) |
53
+
|`%D`|`01/02/2006`| Short MM/DD/YY date, equivalent to `%m/%d/%y`|
54
+
|`%F`|`2006-01-02`| Short YYYY-MM-DD date, equivalent to `%Y-%m-%d`|
55
+
|`%T`|`15:04:05`| ISO 8601 time format (HH:MM:SS), equivalent to `%H:%M:%S`|
56
+
|`%r`|`03:04:05 pm`| 12-hour clock time, equivalent to `%l:%M:%S %p`|
57
+
|`%c`|`Mon Jan 02 15:04:05 2006`| Date and time representation, equivalent to `%a %b %d %H:%M:%S %Y`|
58
+
|`%R`|`15:04`| 24-hour HH:MM time, equivalent to `%H:%M`|
59
+
|`%n`|`\n`| New-line character |
60
+
|`%t`|`\t`| Horizontal-tab character |
61
+
|`%%`|`%`| Percent sign |
62
+
63
+
### `epoch`
64
+
65
+
The `epoch` layout type uses can consume epoch-based timestamps. The following layouts are supported:
66
+
67
+
| Layout | Meaning | Example |`parse_from` data type support |
68
+
| --- | --- | --- | --- |
69
+
|`s`| Seconds since the epoch | 1136214245 |`string`, `int64`, `float64`|
70
+
|`ms`| Milliseconds since the epoch | 1136214245123 |`string`, `int64`, `float64`|
71
+
|`us`| Microseconds since the epoch | 1136214245123456 |`string`, `int64`, `float64`|
72
+
|`ns`| Nanoseconds since the epoch | 1136214245123456789 |`string`, `int64`, `float64`<sup>[2]</sup> |
73
+
|`s.ms`| Seconds plus milliseconds since the epoch | 1136214245.123 |`string`, `int64`<sup>[1]</sup>, `float64`|
74
+
|`s.us`| Seconds plus microseconds since the epoch | 1136214245.123456 |`string`, `int64`<sup>[1]</sup>, `float64`|
75
+
|`s.ns`| Seconds plus nanoseconds since the epoch | 1136214245.123456789 |`string`, `int64`<sup>[1]</sup>, `float64`<sup>[2]</sup> |
76
+
77
+
<sub>[1] Interpretted as seconds. Equivalent to using `s` layout.</sub><br/>
78
+
<sub>[2] Due to floating point precision limitations, loss of up to 100ns may be expected.</sub>
79
+
80
+
16
81
### How to specify timestamp parsing parameters
17
82
18
83
```yaml
@@ -145,8 +210,6 @@ but you could also use a `timestamp` block inside the `json_parser`.
145
210
146
211
#### Parse a timestamp using a `strptime` layout
147
212
148
-
The default `layout_type` is `strptime`, which uses "directives" such as `%Y` (4-digit year) and `%H` (2-digit hour). A full list of supported directives is found [here](../../../../internal/coreinternal/timeutils/internal/ctimefmt/ctimefmt.go#L68).
149
-
150
213
Configuration:
151
214
```yaml
152
215
- type: time_parser
@@ -187,8 +250,6 @@ Configuration:
187
250
188
251
#### Parse a timestamp using a `gotime` layout
189
252
190
-
The `gotime` layout type uses Golang's native time parsing capabilities. Golang takes an [unconventional approach](https://www.pauladamsmith.com/blog/2011/05/go_time.html) to time parsing. Finer details are well-documented [here](https://golang.org/src/time/format.go?s=25102:25148#L9).
191
-
192
253
Configuration:
193
254
```yaml
194
255
- type: time_parser
@@ -229,23 +290,6 @@ Configuration:
229
290
230
291
#### Parse a timestamp using an `epoch` layout
231
292
232
-
The `epoch` layout type uses can consume epoch-based timestamps. The following layouts are supported:
233
-
234
-
| Layout | Meaning | Example | `parse_from` data type support |
235
-
| --- | --- | --- | --- |
236
-
| `s` | Seconds since the epoch | 1136214245 | `string`, `int64`, `float64` |
237
-
| `ms` | Milliseconds since the epoch | 1136214245123 | `string`, `int64`, `float64` |
238
-
| `us` | Microseconds since the epoch | 1136214245123456 | `string`, `int64`, `float64` |
239
-
| `ns` | Nanoseconds since the epoch | 1136214245123456789 | `string`, `int64`, `float64`<sup>[2]</sup> |
240
-
| `s.ms` | Seconds plus milliseconds since the epoch | 1136214245.123 | `string`, `int64`<sup>[1]</sup>, `float64` |
241
-
| `s.us` | Seconds plus microseconds since the epoch | 1136214245.123456 | `string`, `int64`<sup>[1]</sup>, `float64` |
242
-
| `s.ns` | Seconds plus nanoseconds since the epoch | 1136214245.123456789 | `string`, `int64`<sup>[1]</sup>, `float64`<sup>[2]</sup> |
243
-
244
-
<sub>[1] Interpretted as seconds. Equivalent to using `s` layout.</sub><br/>
245
-
<sub>[2] Due to floating point precision limitations, loss of up to 100ns may be expected.</sub>
0 commit comments