Skip to content

Commit e7aa7d2

Browse files
committedJan 10, 2025·
rename to FormatTime
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
1 parent 40235c6 commit e7aa7d2

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed
 

‎.chloggen/ottl-timestamp.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ change_type: enhancement
77
component: pkg/ottl
88

99
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10-
note: "Introduce new Timestamp() converter function."
10+
note: "Introduce new FormatTime() converter function."
1111

1212
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
1313
issues: [36870]

‎pkg/ottl/e2e/e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ func Test_e2e_converters(t *testing.T) {
938938
},
939939
},
940940
{
941-
statement: `set(attributes["time"],Timestamp(time, "%Y-%m-%d"))`,
941+
statement: `set(attributes["time"], FormatTime(time, "%Y-%m-%d"))`,
942942
want: func(tCtx ottllog.TransformContext) {
943943
tCtx.GetLogRecord().Attributes().PutStr("time", "2020-02-11")
944944
},

‎pkg/ottl/ottlfuncs/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Available Converters:
465465
- [String](#string)
466466
- [Substring](#substring)
467467
- [Time](#time)
468-
- [Timestamp](#timestamp)
468+
- [FormatTime](#formattime)
469469
- [ToKeyValueString](#tokeyvaluestring)
470470
- [TraceID](#traceid)
471471
- [TruncateTime](#truncatetime)
@@ -1962,11 +1962,11 @@ Examples:
19621962
- `Time("mercoledì set 4 2024", "%A %h %e %Y", "", "it")`
19631963
- `Time("Febrero 25 lunes, 2002, 02:03:04 p.m.", "%B %d %A, %Y, %r", "America/New_York", "es-ES")`
19641964

1965-
### Timestamp
1965+
### FormatTime
19661966

1967-
`Timestamp(time, format)`
1967+
`FormatTime(time, format)`
19681968

1969-
The `Timestamp` Converter takes a `time.Time` and converts it to a human readable string representations of the time according to the specidied format.
1969+
The `FormatTime` Converter takes a `time.Time` and converts it to a human readable string representations of the time according to the specidied format.
19701970

19711971
`time` is `time.Time`. If `time` is another type an error is returned. `format` is a string.
19721972

@@ -2015,7 +2015,7 @@ If `format` is nil, an error is returned. The parser used is the parser at [inte
20152015

20162016
Examples:
20172017

2018-
- `Timestamp(Time("02/04/2023", "%m/%d/%Y"), "%A %h %e %Y")`
2018+
- `FormatTime(Time("02/04/2023", "%m/%d/%Y"), "%A %h %e %Y")`
20192019

20202020
### ToKeyValueString
20212021

‎pkg/ottl/ottlfuncs/func_timestamp.go ‎pkg/ottl/ottlfuncs/func_formattime.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ import (
1111
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
1212
)
1313

14-
type TimestampArguments[K any] struct {
14+
type FormatTimeArguments[K any] struct {
1515
Time ottl.TimeGetter[K]
1616
Format string
1717
}
1818

19-
func NewTimestampFactory[K any]() ottl.Factory[K] {
20-
return ottl.NewFactory("Timestamp", &TimestampArguments[K]{}, createTimestampFunction[K])
19+
func NewFormatTimeFactory[K any]() ottl.Factory[K] {
20+
return ottl.NewFactory("FormatTime", &FormatTimeArguments[K]{}, createFormatTimeFunction[K])
2121
}
2222

23-
func createTimestampFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[K], error) {
24-
args, ok := oArgs.(*TimestampArguments[K])
23+
func createFormatTimeFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[K], error) {
24+
args, ok := oArgs.(*FormatTimeArguments[K])
2525

2626
if !ok {
27-
return nil, fmt.Errorf("TimestampFactory args must be of type *TimestampArguments[K]")
27+
return nil, fmt.Errorf("FormatTimeFactory args must be of type *FormatTimeArguments[K]")
2828
}
2929

30-
return Timestamp(args.Time, args.Format)
30+
return FormatTime(args.Time, args.Format)
3131
}
3232

33-
func Timestamp[K any](timeValue ottl.TimeGetter[K], format string) (ottl.ExprFunc[K], error) {
33+
func FormatTime[K any](timeValue ottl.TimeGetter[K], format string) (ottl.ExprFunc[K], error) {
3434
if format == "" {
3535
return nil, fmt.Errorf("format cannot be nil")
3636
}

‎pkg/ottl/ottlfuncs/func_timestamp_test.go ‎pkg/ottl/ottlfuncs/func_formattime_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
1414
)
1515

16-
func Test_Timestamp(t *testing.T) {
16+
func Test_FormatTime(t *testing.T) {
1717
tests := []struct {
1818
name string
1919
time ottl.TimeGetter[any]
@@ -79,7 +79,7 @@ func Test_Timestamp(t *testing.T) {
7979
expected: "July 31, 1993",
8080
},
8181
{
82-
name: "date with timestamp",
82+
name: "date with FormatTime",
8383
time: &ottl.StandardTimeGetter[any]{
8484
Getter: func(_ context.Context, _ any) (any, error) {
8585
return time.Date(2023, 3, 14, 17, 0o2, 59, 0, time.Local), nil
@@ -151,7 +151,7 @@ func Test_Timestamp(t *testing.T) {
151151
}
152152
for _, tt := range tests {
153153
t.Run(tt.name, func(t *testing.T) {
154-
exprFunc, err := Timestamp(tt.time, tt.format)
154+
exprFunc, err := FormatTime(tt.time, tt.format)
155155
if tt.errorMsg != "" {
156156
assert.Contains(t, err.Error(), tt.errorMsg)
157157
} else {

‎pkg/ottl/ottlfuncs/functions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func converters[K any]() []ottl.Factory[K] {
8989
NewStringFactory[K](),
9090
NewSubstringFactory[K](),
9191
NewTimeFactory[K](),
92-
NewTimestampFactory[K](),
92+
NewFormatTimeFactory[K](),
9393
NewTrimFactory[K](),
9494
NewToKeyValueStringFactory[K](),
9595
NewTruncateTimeFactory[K](),

0 commit comments

Comments
 (0)
Please sign in to comment.