-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package converters | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/artie-labs/transfer/lib/typing" | ||
"github.com/artie-labs/transfer/lib/typing/ext" | ||
) | ||
|
||
type Date struct{} | ||
|
||
func (Date) ToKindDetails() typing.KindDetails { | ||
return typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateKindType) | ||
} | ||
|
||
func (Date) Convert(value any) (any, error) { | ||
valueInt64, isOk := value.(int64) | ||
if !isOk { | ||
return nil, fmt.Errorf("expected int64 got '%v' with type %T", value, value) | ||
} | ||
|
||
unix := time.UnixMilli(0).In(time.UTC) // 1970-01-01 | ||
// Represents the number of days since the epoch. | ||
return ext.NewExtendedTime(unix.AddDate(0, 0, int(valueInt64)), ext.DateKindType, ""), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package converters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDate_Convert(t *testing.T) { | ||
{ | ||
// Invalid data type | ||
_, err := Date{}.Convert("invalid") | ||
assert.ErrorContains(t, err, "expected int64 got 'invalid' with type string") | ||
} | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters