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
[pkg/ottl] Added support for timezone in Time converter (#32479)
**Description:**
Added support for default timezone in Time converter.
Timezone is optional and can be specified as so: `Time("2023-05-26
12:34:56", "%Y-%m-%d %H:%M:%S", "America/New_York")`
**Link to tracking Issue:** #32140
**Testing:** Unit tests added
**Documentation:** Documentation in ottl/Readme updated
---------
Co-authored-by: Tyler Helmuth <[email protected]>
Co-authored-by: Evan Bradley <[email protected]>
Copy file name to clipboardExpand all lines: pkg/ottl/ottlfuncs/README.md
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1131,11 +1131,11 @@ Examples:
1131
1131
1132
1132
### Time
1133
1133
1134
-
`Time(target, format)`
1134
+
`Time(target, format, Optional[location])`
1135
1135
1136
1136
The `Time` Converter takes a string representation of a time and converts it to a Golang `time.Time`.
1137
1137
1138
-
`target` is a string. `format` is a string.
1138
+
`target` is a string. `format` is a string, `location` is an optional string.
1139
1139
1140
1140
If either `target` or `format` are nil, an error is returned. The parser used is the parser at [internal/coreinternal/parser](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/internal/coreinternal/timeutils). If the `target` and `format` do not follow the parsing rules used by this parser, an error is returned.
1141
1141
@@ -1176,13 +1176,24 @@ If either `target` or `format` are nil, an error is returned. The parser used is
1176
1176
|`%%`| A % sign ||
1177
1177
|`%c`| Date and time representation | Mon Jan 02 15:04:05 2006 |
1178
1178
1179
+
`location` specifies a default time zone canonical ID to be used for date parsing in case it is not part of `format`.
1180
+
1181
+
When loading `location`, this function will look for the IANA Time Zone database in the following locations in order:
1182
+
- a directory or uncompressed zip file named by the ZONEINFO environment variable
1183
+
- on a Unix system, the system standard installation location
1184
+
- $GOROOT/lib/time/zoneinfo.zip
1185
+
- the `time/tzdata` package, if it was imported.
1186
+
1187
+
When building a Collector binary, importing `time/tzdata` in any Go source file will bundle the database into the binary, which guarantees the lookups will work regardless of the setup on the host setup. Note this will add roughly 500kB to binary size.
0 commit comments