Skip to content

Commit 2653cca

Browse files
vojtabiberleclaude
andcommitted
DMD-920 - Move formatJobTimePtr to internal/pkg/utils/timeutils
- Created new timeutils package with FormatISO8601Ptr function - Updated processor.go to use the new utility function - Moved test to timeutils package Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4d1be55 commit 2653cca

4 files changed

Lines changed: 53 additions & 35 deletions

File tree

internal/pkg/llm/twinformat/processor.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"time"
77

88
"github.com/keboola/keboola-sdk-go/v2/pkg/keboola"
9-
"github.com/relvacode/iso8601"
109

1110
"github.com/keboola/keboola-as-code/internal/pkg/filesystem"
1211
"github.com/keboola/keboola-as-code/internal/pkg/log"
1312
"github.com/keboola/keboola-as-code/internal/pkg/telemetry"
13+
"github.com/keboola/keboola-as-code/internal/pkg/utils/timeutils"
1414
)
1515

1616
// ProcessedData holds all processed data ready for generation.
@@ -425,7 +425,7 @@ func (p *Processor) processTransformations(ctx context.Context, configs []*Trans
425425
jobKey := cfg.ComponentID + ":" + cfg.ID
426426
if job, ok := jobMap[jobKey]; ok {
427427
jobExec = &JobExecution{
428-
LastRunTime: formatJobTimePtr(job.StartTime),
428+
LastRunTime: timeutils.FormatISO8601Ptr(job.StartTime),
429429
LastRunStatus: job.Status,
430430
JobReference: job.ID.String(),
431431
DurationSeconds: job.DurationSeconds,
@@ -622,14 +622,6 @@ func extractBucketName(bucketID string) string {
622622
return bucket
623623
}
624624

625-
// formatJobTimePtr formats a job time pointer for output.
626-
func formatJobTimePtr(t *iso8601.Time) string {
627-
if t == nil {
628-
return ""
629-
}
630-
return t.Time.UTC().Format(time.RFC3339)
631-
}
632-
633625
// buildTableUID builds a table UID from bucket and table name.
634626
func buildTableUID(bucket, table string) string {
635627
var b strings.Builder

internal/pkg/llm/twinformat/processor_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,6 @@ func TestExtractBucketName(t *testing.T) {
7272
}
7373
}
7474

75-
func TestFormatJobTimePtr(t *testing.T) {
76-
t.Parallel()
77-
78-
// Create a fixed time for testing
79-
fixedTime := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
80-
iso8601Time := iso8601.Time{Time: fixedTime}
81-
82-
tests := []struct {
83-
name string
84-
time *iso8601.Time
85-
expected string
86-
}{
87-
{name: "nil time", time: nil, expected: ""},
88-
{name: "valid time", time: &iso8601Time, expected: "2024-01-15T10:30:00Z"},
89-
}
90-
91-
for _, tc := range tests {
92-
t.Run(tc.name, func(t *testing.T) {
93-
t.Parallel()
94-
result := formatJobTimePtr(tc.time)
95-
assert.Equal(t, tc.expected, result)
96-
})
97-
}
98-
}
99-
10075
func TestIsJobNewer(t *testing.T) {
10176
t.Parallel()
10277

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Package timeutils provides time formatting utilities.
2+
package timeutils
3+
4+
import (
5+
"time"
6+
7+
"github.com/relvacode/iso8601"
8+
)
9+
10+
// FormatISO8601Ptr formats an iso8601.Time pointer to RFC3339 string.
11+
// Returns empty string if the pointer is nil.
12+
func FormatISO8601Ptr(t *iso8601.Time) string {
13+
if t == nil {
14+
return ""
15+
}
16+
return t.Time.UTC().Format(time.RFC3339)
17+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package timeutils
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/relvacode/iso8601"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestFormatISO8601Ptr(t *testing.T) {
12+
t.Parallel()
13+
14+
// Create a fixed time for testing
15+
fixedTime := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
16+
iso8601Time := iso8601.Time{Time: fixedTime}
17+
18+
tests := []struct {
19+
name string
20+
time *iso8601.Time
21+
expected string
22+
}{
23+
{name: "nil time", time: nil, expected: ""},
24+
{name: "valid time", time: &iso8601Time, expected: "2024-01-15T10:30:00Z"},
25+
}
26+
27+
for _, tc := range tests {
28+
t.Run(tc.name, func(t *testing.T) {
29+
t.Parallel()
30+
result := FormatISO8601Ptr(tc.time)
31+
assert.Equal(t, tc.expected, result)
32+
})
33+
}
34+
}

0 commit comments

Comments
 (0)